Laravel Model Get Attribute Without Mutator Example

Laravel 8 , Laravel 7 , Laravel , Laravel 6

Nicesnippets

199

29-04-2021


Hello Friends,

In this blog, I will show you how to get model attribute without mutator in laravel application. We will talk about laravel model get attribute without mutator example. This tutorial will give you how to get attribute without mutator.

We will show get attribute without mutator in laravel application. In this example I will give you simple and easy way to get attribute without mutator in laravel application.

Here i will give you full example for how to get model attribute without mutator in laravel application. So let's see the bellow example:

In this example, i have a "User" model with following fields :

  • name
  • email
  • password
  • created_at
  • updated_at

Define Method in Model


public function getOriginalValueAttribute($field)

{

return $this->attributes[$field];

}

Route::get('user', function (){

$user = \App\Models\User::find(1);

dd($user->getOriginal('name'));

});

It will help you....


Recommended Posts