Create websites with TailwindCSS
Design blocks for your website
Start building the next great SAAS
Alpine & Tailwind UI Library
Plug'n Play Authentication for Laravel
Create website designs with AI
Blog platform for developers
Build a simple static website
21-day program to build a SAAS
Upgrade your account to get access to all content.
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.
306
Comments (0)