how to use model function from view ? - laravel 5.4 how to use model function from view ? - laravel 5.4 laravel laravel

how to use model function from view ? - laravel 5.4


There are many ways to call a model function in the view.

Method 1:

Pass Some Modal to view in your controller like :

$model = Model::find(1);View::make('view')->withModel($model);

In modal create a some function:

  public function someFunction() {   // do something  }

In view you can call this function directly as:

{{$model->someFunction()}}

Method 2 or other way:

You can make a static function in the model like:

public static function someStaticFunction($par1, $par2) {   // do what you need}

And in your view you can model function directly as:

{{App\Model::someStaticFunction($par1,$par2)}}


The scope should be scopeTest() (camelCase).