How to call a variable in models in laravel?

Member

by larissa , in category: PHP Frameworks , 10 months ago

How to call a variable in models in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by haylee.mertz , 10 months ago

@larissa 

In Laravel, you can access a variable in a model by using the $this keyword.


For example, if you have a variable named $name in your model, you can access it like this:

1
$this->name;


You can also use the magic __get() method to access the variable directly like this:

1
$name = $this->name;


Make sure that the variable you are trying to access is defined in the model class.

Related Threads:

How to properly call models in codeigniter?
How to get a all eloquent models in laravel?
How to access a column value in models in laravel?
How to pass multiple models to laravel view?
How to make a api call in laravel?
How to call ajax in jquery in laravel?