How to make a template respons'a?

Learning Laravel
Make API for your web project

Once there was campisano bike with such a structure of the response:
{success: true,
globe_error: 'OK'
errors: [],
data: []}


How to make same pattern of response in Laravel? Or even is it possible?

I used to have just the Output class with static methods '::addError', '::setData'
Then it all was run through json_encode and I enjoy life
And here I already googled but couldn't find one
June 8th 19 at 17:28
1 answer
June 8th 19 at 17:30
Solution
I try to create a trait with your methods, forming the desired format of the response, and implement this trait in the base controller. After that you can successfully all of the controllers to return a reply something like this:
return $this->success($message);
Zadolbali each controller to place the traits, it's easier to do the same in your Controller or ApiController - Gerda57 commented on June 8th 19 at 17:33
Ahem. Read my answer carefully... - Gerhard commented on June 8th 19 at 17:36
sorry. Slept 6 hours, went to 8 am blunt ;) - Gerda57 commented on June 8th 19 at 17:39
You like a response! )) - Gerhard commented on June 8th 19 at 17:42

Find more questions by tags Laravel