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
- How to get id of next record in laravel
- Laravel 7 login error message not showing
- Undefined property: stdClass::$title
- Calculate age from date of birth in Laravel
- How to update record after save method in Laravel
- Laravel upload file with original file name
- How to restore deleted records in laravel
- External link not working in laravel blade
- Property [user] does not exist on this collection instance
- How to insert dynamic value to additional column in pivot table in laravel
- Laravel delete all rows older than 30 days
- Laravel insert query not working
- How to get column names from table in Laravel
- How to check query string exists or not in laravel blade
- How to display pivot table column value in laravel
- Non-static method App\Http\Helper::myFunction() should not be called statically
- How to set column as primary key in Laravel model
- Laravel change date format
- Method Illuminate\Database\Eloquent\Collection::appends does not exist
- Composer\Exception\NoSslException
- How to delete record in Laravel with ajax
- How to pass query string with pagination in laravel
- Get products with number of orders in Laravel
- Class 'Facade\Ignition\IgnitionServiceProvider' not found
- Pass variable from blade to controller Laravel