Answer the question
In order to leave comments, you need to log in
How to load links in laravel resource collection in one request?
I want to make it possible for the api to specify some connections in the get parameter that the client may need.
For example, when receiving posts, indicate that the authors of these posts are also needed.
Initially, this was only needed for a list of resources ala get / posts. I made a separate filtering class through which Post::query() is run and, depending on the get parameters in the Request object, selection, sorting, and external relations conditions are added to the request. In general, it works fine.
Then there was a need to receive links when receiving one, specific resource (get /posts/123).
The show method of the controller immediately receives the finished model of the desired post, if any.
class PostController extends Controller
{
public function index(Request $reqquest)
{
//...
}
public function show(Request $request, Post $post)
{
//...
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question