
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
- Create a record if not exist in laravel
- How to get laravel errors folder in views directory in laravel
- Target class [admin] does not exist.
- How to validate website url in laravel using validaiton
- Credit card validation in laravel
- Use withCount() to Calculate Child Relationship Records
- First and last item of the array using foreach iteration in laravel blade
- The use statement with non-compound name 'DB' has no effect
- How to Get records between two dates in Laravel
- How to return error message from controller to view in laravel
- How to set column as primary key in Laravel model
- Get last record from table in laravel
- SQLSTATE[42000]: Syntax error or access violation: 1055
- If no route matched route::fallback in laravel
- How to create project_user pivot table in laravel
- Call to undefined function Illuminate\Encryption\openssl_cipher_iv_length()
- How to start websocket server in laravel
- How to pass query string to url in laravel
- Where to use whereNotNull eloquent in laravel
- How to display a specific word from a string in laravel
- Touch parent updated_at in Laravel
- How to get date from created_at field in laravel
- How to get file extension from input type file in laravel
- Insert data with form validation using ajax in laravel
- Laravel append URI in route