Nikhil Sharma

Latest News

  1. Home
  2. Blog
Create Laravel Add Edit In single Method

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

  1. Create Table
  2. Model
  3. Route
  4. Controller
  5. View
  6. 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 

 

Author: Nikhil Sharma

Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis.

0 Comments

Leave a reply