How to update record after save method in Laravel
How to update record after save method in Laravel
We’ll attempt to use programming in this lesson to solve the "How to update record after save method in Laravel" puzzle.
You can update the record which you recently saved in your database using save method in Laravel. You can get the id of recently saved record and after that you can use update method with where condition to update the record.-
Update record after save method in Laravel
// Import project model in controller class $product = new Product; $product->name = $request->name; $product->save(); Product::where('id', $product->id)->update(['inventory_id'=>1]);
Using this code snippet you can update the recently added record. You can use the id of recently created record after the save method and after that you can call update method on this record using where condition in laravel.
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
- Json encode method in laravel
- Call to a member function pluck() on array
- How to display order by null last in laravel
- Display success message in laravel
- Database transactions in laravel
- Method Illuminate\Database\Eloquent\Collection::lists does not exist
- RuntimeException You must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
- How to create laravel project using composer
- Laravel change date format
- SQLSTATE[42000]: Syntax error or access violation: 1055
- Validation for multiple forms on same page in laravel
- OrderBy on Eloquent relationships method in Laravel
- Method chaining in Laravel
- How to add class to tr in table using foreach in laravel
- How to display pivot table column value in laravel
- Class 'Facade\Ignition\IgnitionServiceProvider' not found
- How to restore deleted records in laravel
- How to get specific columns using with method in laravel Eloquent relationship
- Target class [App\Http\Controllers\Auth\Request] does not exist.
- Redirect to another view from controller in laravel
- Get latest record by created at in Laravel
- How to pass data to multiple partial view files in laravel
- How to set column as primary key in Laravel model
- If condition in foreach loop in laravel
- Return redirect laravel not working