Комментарии:
I planned to do like this before 😉
Ответитьanother useful way is you can set it in your model like:
public function getCreatedTimeAttribute()
{
return Carbon::parse($this->created_at)->diffForHumans();
}
protected $appends = ['created_time'];
protected $casts = [
'created_at' => 'datetime:F d Y, h:i A',
];
I like this one a lot
ОтветитьAPI Resources within another API Resource is extremely useful and one of the bigger reasons to use these resources in the first place.
For example if you want to return an Author resource and also return a list of Books they have associated with their record, you just attach books to the author resource and call the appropriate method to give back an array of those Book resources using the list of books as a source.
i have been using this re-use of resource 4 years ago on one of our projects, pretty helpful
ОтветитьThanks for the tip.
Ответитьpretty useful for "standard" objects, like User for instance!
ОтветитьThanks a lot for sharing.
ОтветитьThis is really nice one.
It is usually tiring formating in every resource
I did this exact thing some 6 months ago with an api I was asked to refactor. I has a lot of structures that use same data in same way, so I assigned an api resource for each of them, then interconnected them.
ОтветитьAnd again DI is murdered and another bloated package is loaded for something simple.
Ответитьinteresting
ОтветитьI have learned alot from Alex he is great.
Ответить