PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

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)

loading comments