Pass value from controller to model in laravel
Created at 09-Aug-2021 ,
By samar
Pass value from controller to model in laravel
In this tutorial, we will try to find the solution to "Pass value from controller to model in laravel" through programming.
You can pass values or parameters from controller to model in laravel by creating a model instance and calling the model method by using $object->methodName($parameters).-
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 the post details if it has at least one comment in comments table
- Non-static method App\Http\Helper::myFunction() should not be called statically
- Check if Relationship Method Exists in Laravel
- Declaration of App\Models\Post::sluggable() must be compatible with Cviebrock\EloquentSluggable\Sluggable
- Send id with route Laravel
- Method Illuminate\Http\Request::validated does not exist
- How to create controller in laravel
- Insert dummy data in users table Laravel
- How to validate form input data in laravel
- How to include header file in laravel
- Class 'Facade\Ignition\IgnitionServiceProvider' not found
- If condition in foreach loop in laravel
- How to get specific columns using with method in laravel Eloquent relationship
- How to get all posts which contains comments in laravel
- How to pass external link in laravel blade to anchor tag
- Conditional validation in laravel
- How to display HTML tags In Laravel blade
- Call to undefined relationship [user] on model [App\Models\Post]
- Call to a member function pluck() on null
- How to start websocket server in laravel
- Rename Pivot Table in Laravel
- How to check email is valid or not in Laravel
- If no route matched route::fallback in laravel
- Print query in laravel
- How to show data by ID in laravel?