
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
- Laravel get single row by id
- Get the post details if it has at least one comment in comments table
- How to get IP address in laravel
- Conditional validation in laravel
- How to get date from created_at field in laravel
- Class 'Facade\Ignition\IgnitionServiceProvider' not found
- How to check query string exists or not in laravel blade
- How to send ID to another page in Laravel
- Method Illuminate\Database\Eloquent\Collection::appends does not exist
- Retrieve count of nested relationship data in Laravel
- How to use more than one query scope in Laravel
- Non-static method App\Http\Helper::myFunction() should not be called statically
- The use statement with non-compound name 'Auth' has no effect
- How to implement toggleLike() method in Overtrue\LaravelLike laravel package
- Call to a member function getRelationExistenceQuery() on array in Laravel
- How to pass query string with pagination in laravel
- Array to string conversion laravel blade
- How to pass data to multiple partial view files in laravel
- How to get specific columns using with method in laravel Eloquent relationship
- Shorter syntax for whereHas with call back function in laravel
- Return redirect laravel not working
- Target class [admin] does not exist.
- How to pass link from controller to view in laravel on ajax call
- How to add foreign key in laravel using migration
- Touch parent updated_at in Laravel