How to call model in blade laravel

You can call the model method in the laravel blade file. You have to define the function with static property and you can call this function from laravel blade file

Answers 1
  • Define static function in User model and call in laravel blade

    //Static function in User model
    public static function getUserNameById($id){
        return User::where('id', $id)->pluck('name')->first();
    //Call method in laravel view
    {{ App\Models\User::getUserNameByID(1) }}
    Output :
    Mr. Ian Conn
  • Back to code snippet queries related laravel