Answer the question
In order to leave comments, you need to log in
How to access laravel model methods in vue?
I'm using vue on Laravel and I'm having this problem.
I extract through axious let's say model data
public function getPosts()
{
$posts = Post::all();
return response()->json([
'posts' => $posts
]);
}
public function thumb()
{
return 'images/thumb/'.$this->img;
}
{{ note.thumb() }}
Answer the question
In order to leave comments, you need to log in
Laravel Resource
Need to be done Write
in this file
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
// Метод из модели
'thumb' => $this->thumb(),
];
}
public function getPosts()
{
$posts = Post::all();
return PostResource::collection($posts);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question