
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
- How to validate form input data in laravel
- How to decrypt laravel password
- Send OTP using textlocal api in laravel
- How to print form data in laravel
- Create model with migration and seeder
- How to get specific columns using Laravel eloquent methods
- How to display 1 day ago in comments in laravel view
- Laravel file size validation not working
- Laravel save object to database
- How to get specific columns using with method in laravel Eloquent relationship
- How to remove P tag from CkEditor in Laravel?
- Best Practices for Error Handling in Production Server Code (example code)
- Return redirect laravel not working
- How to include header file in laravel
- Laravel URL validation not working
- Shorter syntax for whereHas with call back function in laravel
- How to get path from current URL in Laravel
- How to run a specific seeder class in laravel
- How to prevent host header attack in Laravel
- Calculate age from date of birth in Laravel
- Create project factory and seed data in laravel
- If condition in foreach loop in laravel
- The openssl extension is required for SSL/TLS protection but is not available
- Remove public from url in laravel project
- How to get only time from created_at in laravel