Sorry, this video is only available to Pro accounts.

Upgrade your account to get access to all content.

Laravel Hidden & Appended Attributes

Created on April 22nd, 2017

In this video we’ll show you how you can hide or append attributes from your JSON responses in your Laravel app.

In order to add hidden fields that you don't want to be displayed in your JSON output you can add fields to a hidden array in the Model like so:

protected $hidden = [
    'password', 'remember_token', 'email',
];

Additionally, you can add attributes to the JSON output by adding the following to your Model:

protected $appends = [
    'link'
];

public function getLinkAttribute(){
    return url('profile/' . $this->id);
}

You can learn more about Laravel Hidden and Appended attributes from the official laravel documentation here: https://laravel.com/docs/5.4/eloquent-serialization#hiding-attributes-from-json.

Comments (0)