Create Laravel Add Edit In single Method
Laravel use same form for create and edit CRUD stands for Create, Read, Update, and Delete. This needs when working with the database data. With this operation, a user can perform its action, and the changes will be saved in the database. In this tutorial, I show how you can select, insert, update, and delete a record from the MySQL database with Laravel
Laravel Create Curd Add Edit In Single Route Logic
Laravel use same form for create and edit
- Create Table
- Model
- Route
- Controller
- View
- Output
- First we need to create a Route For both Add & Edit like this
- Route::any('/moduleName/update/{id?}', [FrontController::class, 'updateMethod'])->name('updateModule');
- Then we need to create a Controller For Create a method to update and insert Record
findOrNew This method will use for Handle both request id we pass id in
findOrNew(1) it will return Data for that id othewise if we don't pass Id it will Create a New Entery and return the inserted id
so useing this method we can handle both request create and update
Share:
0 Comments
Leave a reply