
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
- Laravel create default admin user
- How to Run CRON Job on LIVE SERVER on Cpanel in Laravel Project
- How to get images from AWS s3 and display in Laravel blade
- Retain selected value of select box in Laravel
- How to authenticate admin users in Laravel ?
- Target class [App\Http\Controllers\Auth\Request] does not exist.
- How to get file extension from input type file in laravel
- Global scope in Laravel with example
- Laravel append URI in route
- How to fill a column automatically while creating records in Laravel
- How to generate .env file for laravel?
- Define variable and use in Laravel controller method
- Update record after find method in lavavel
- Touch parent updated_at in Laravel
- Get Array of IDs from Eloquent Collection
- How to implement toggleLike() method in Overtrue\LaravelLike laravel package
- Use of undefined constant laravel
- Use withCount() to Calculate Child Relationship Records
- Create a record if not exist in laravel
- Wheredate in laravel not working
- Laravel API response format
- Insert data with form validation using ajax in laravel
- Run artisan command to generate key in laravel
- How to get list of all views file in laravel
- Session Doesn't Work on Redirect