
How to pass variable from controller to model in Laravel
Created at 11-Oct-2021 ,
By samar
How to pass variable from controller to model in Laravel
In this session, we’ll try our hand at solving the "How to pass variable from controller to model in Laravel" puzzle by using the computer language.
You can pass variable from controller to model in Laravel by defining a method in model and calling the model method from controller with argument.-
Pass parameter values from controller to admin model in laravel
//app\Http\Controllers\AdminController.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Admin; class AdminController extends Controller { /** * Handle an authentication attempt for admin. * * @return Response */ public function userAuthentication(Request $request) { $admin = new Admin(); $admin->checkUserAuthentication($request); } } //app\Models\Admin.php <?php namespace App; use Illuminate\Database\Eloquent\Model; class Admin extends Model { public function checkUserAuthentication($request) { // Do something with $request $request->input('username'); } }
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
- There are no commands defined in the "route:" namespace
- Laravel 7 login error message not showing
- How to create laravel project using composer
- Send OTP using textlocal api in laravel
- Php artisan make model, factory, migration and controller in single command
- How to get specific columns using with method in laravel Eloquent relationship
- How to upload multiple images after preview in laravel using cropper js
- Show old value while editing the form in Laravel
- Class 'App\Providers\Auth' not found
- Shorter syntax for whereHas with call back function in laravel
- SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'posts_user_id_foreign'; check that column/key exists
- Delete file from amazon s3 bucket using Laravel
- If no route matched route::fallback in laravel
- How to create new user without form submission in laravel
- Convert input array to comma-separated string in laravel controller
- Route group with URI prefix using middleware and route name prefixes
- Call to a member function getRelationExistenceQuery() on array in Laravel
- Argument 1 passed to App\Http\Controllers\Auth\LoginController::authenticated() must be an instance of App\Http\Controllers\Auth\Request
- Json encode method in laravel
- RuntimeException You must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
- Create record with unique slug in laravel
- How to customize pagination view in laravel
- Laravel 9 route group with controller
- Call to undefined relationship [user] on model [App\Models\Post]
- Display first n record from collection in laravel view