if you are looking for serializing laravel model for having just some properties of your model or even hide some of them in relation fetching just take a look at laravel serializing document:
in this way you can set some properties hidden or make a visible list of them.
in the other hand if you want to side loaded data instead of nested data, e.g for your relations method, also make this method relation hidden in your model and then make a response variable and load relation in it separately like below example:
assume we have a students method in our course model so first make it hidden
protected $hidden = ['students'];
then in your controller:
$course = new Course::with('students')->findOrFail; $response['course'] = $course; $response['students'] = $course->students;
so in this way you have all students of course in student index of your array.
finally maybe you can use laravel resource to set some individual formatting to toArray and then return your response with your desired array so read more about this:
vahidvs started a new conversation Best Practice For Generate Laravel Request Validation In Rest Api App
i have a restful app with laravel 5.5 and i am using laravel request class for validating requests before use theme in my controllers. so now i have many request class because there is one class for each action. for example loginRequest.php for login action and RegisterRequest.php for register and .... I am wondering if it is ok to produce requests in this way! i have five request just for AuthController and much more requests for other controllers! I can't merge them because of individual rules belongs to each one. so what is the best practice to handle this volume of requests?