Я создаю сообщение, теперь я хочу получить Аутентифицированного пользователя, чтобы я мог заполнить author_id.Но когда я использую
$request->user(); or Auth::user();
Возвращает ноль.
Как передать данные из моего компонента vuejs в контроллер?
Итак, вот мой компонент Vue
Form.vue
data() {
return {
form:{
title: '',
seo_title: '',
excerpt: '',
body: '',
image: '',
meta_description: '',
meta_keywords: '',
category_id: '',
status: '',
featured: ''
}
},
methods: {
save() {
post(this.storeURL, form)
.then((res) => {
this.$router.push('Post created successfully')
})
}
}
}
PostController.php
$filename = $this->getFileName($request->image);
$request->image->move(public_path('storage/posts/'), $filename);
$article = new Post($request->all());
$article->slug = str_slug($request->title, '-');
$article->image = $filename;
$request->user()->posts()->save($article);
return response()
->json([
'saved' => true,
'id' => $article->id,
'message' => 'You have successfully posted an article!'
]);