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
- Get duplicate records in laravel
- How to prevent host header attack in Laravel
- How to validate URL with https using regex in laravel
- Include External CSS and JS file in Laravel
- How to pass data to route in laravel?
- Setup laravel project with docker
- How to display validation error in laravel
- How to display a specific word from a string in laravel
- Class "App\Http\Controllers\Auth\Verified" not found
- How to customize or Change validation error messages
- How to pass external link in laravel blade to anchor tag
- How to check record exist or not in relationship table
- How to get specific columns using Laravel eloquent methods
- How to pass data to multiple partial view files in laravel
- The use statement with non-compound name 'DB' has no effect
- Insert current date time in a column using Laravel
- Multiple Level eager loading in Laravel
- Get last record from table in laravel
- How to pass two variables in HREF in laravel
- Laravel 9 route group with controller
- Use of undefined constant laravel
- How to create event and listener in laravel ?
- Get current URL on visit URL in Laravel
- Ignore Records where a field has NULL value in Laravel
- Create record with unique slug in laravel