Laravel Serialization: Hiding Attributes From JSON

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = ['password'];
}
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    /**
     * The attributes that should be visible in arrays.
     *
     * @var array
     */
    protected $visible = ['first_name', 'last_name'];
}

Temporarily Modifying Attribute Visibility

Return $user->makeVisible('attribute')->toArray();
Return $user->makeHidden('attribute')->toArray();

Laravel Serialization: Hiding Attributes From JSON — Structure map

Clickable & Draggable!

Laravel Serialization: Hiding Attributes From JSON — Related pages: