orignal attribute name laravel code example

Example 1: get original name without mutant model laravel

Inside your model file:

1. In laravel older versions (5.x and older):
// that skips mutators
$this->getOriginal('name');

2. In laravel latest versions (6.x and above):
// that skips mutators
$model->getRawOriginal('name');

Alternative methods for getting value with mutator:
1. $this->attributes['name']
2. $this->getAttributes()['name']`

Example 2: laravel property

// Create a new user in the database...
$user = User::create(array('name' => 'John'));

// Retrieve the user by the attributes, or create it if it doesn't exist...
$user = User::firstOrCreate(array('name' => 'John'));

// Retrieve the user by the attributes, or instantiate a new instance...ddd
$user = User::firstOrNew(array('name' => 'John'));

Example 3: laravel property

// Create a new user in the database...dddd
$user = User::create(array('name' => 'John'));

// Retrieve the user by the attributes, or create it if it doesn't exist...
$user = User::firstOrCreate(array('name' => 'John'));

// Retrieve the user by the attributes, or instantiate a new instance...
$user = User::firstOrNew(array('name' => 'John'));

Tags:

Php Example