How to call model in blade laravel
Created at 21-Sep-2021 ,
By samar
How to call model in blade laravel
Good day, guys. In this post, we’ll look at how to solve the "How to call model in blade laravel" programming puzzle.
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-
Define static function in User model and call in laravel blade
//Static function in User model //app\Models\User.php public static function getUserNameById($id){ return User::where('id', $id)->pluck('name')->first(); } //Call method in laravel view //resources\views\<home>.blade.php {{ App\Models\User::getUserNameByID(1) }}
Output :Mr. Ian Conn
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Get comma separated email from input array
- Array to string conversion laravel Controller
- How to send ID to another page in Laravel
- Pass variable from blade to controller Laravel
- Ajax POST request in laravel
- Json encode method in laravel
- Laravel upload file with original file name
- Get ids in array from users table
- How to avoid duplicate entries in pivot table in Laravel
- Seed database using SQL file in Laravel
- Delete records with relationship in laravel
- How to get route name on visit URL in laravel
- Add class to body in laravel view
- Redirect to another view from controller in laravel
- Post table seeder laravel 10
- Store logged in user details in session and display in view in laravel
- There are no commands defined in the "route:" namespace
- Return view from route Laravel
- Create project table with model and migration
- Laravel 7 login error message not showing
- First and last item of the array using foreach iteration in laravel blade
- Delete file from amazon s3 bucket using Laravel
- How to fill a column automatically while creating records in Laravel
- Non-static method App\Http\Helper::myFunction() should not be called statically
- How to get specific columns using with method in laravel Eloquent relationship