How do I Transform specific fields in Laravel?
For example:
$user = \Auth::User();
return [
'user_id' => $user->id,
'articles' => $user->articles,
'pages' => $user->pages,
];
$user->articles
will show the entries the articles
table and $user->pages
from the pages
table.
In the User model, it would be defined something like that:
public function articles()
{
return $this->hasMany(Article::class);
}
I do not want to return all the fields from $user->articles
, just id, name, and description. What is good way to transform this collection?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2fKQwV8
via IFTTT
Aucun commentaire:
Enregistrer un commentaire