lundi 5 décembre 2016

How to temporarily hide model relations attributes with Laravel 5

I have read how to temporarily hide model attributes. I would like to temporarily hide a model relation attribute.

For instance

{
    "slug": "google-chrome",
    "name": "Google Chrome",
    "description": {
         "text": null,
         "created_at": "2016-12-05 12:16:38",
         "updated_at": "2016-12-05 12:16:38"
}

What is the syntax for hiding the description.created_at only in this query? In my SoftwareController I have

public function show(Request $request, $slug)
{
    $models = Software::query();

    $model =
        $models
        ->where('slug', $slug)
        ->firstOrFail()
        ->makeHidden([
            'description.created_at',
        ]);

    return $model;
}

This syntax does not seem to work? Is it possible?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2gZOtBp
via IFTTT

Aucun commentaire:

Enregistrer un commentaire