DEV Community

kogena6100@aiworldx.com
kogena6100@aiworldx.com

Posted on

Laravel CRUD(Create Read Update and Delete) Notes

Requirement for CRUD

  1. A controller
  2. A Model connected to a relevant table on database
  3. Views file for (creating form , for table to show students)
  4. Routes

1. First Step
Create a view for your create student form

  1. Route for the view you created in step 1
Route::get('create_student', function(){
   return view("create_student");
});
Enter fullscreen mode Exit fullscreen mode

3.Create a form in the create_student

The below form is submited on the route whose name is saveStudent and the route method is Post

<h1>This is a form for student</h1>

<form action="{{ route('saveStudent') }}" method="POST">
    @csrf
    <input type="text" name="student_name" placeholder="Enter your name">
    <br><br>
    <input type="email" name="student_email" placeholder="Enter your email">
    <br><br>
    <input type="password" name="student_password" placeholder="Enter your password">
    <br><br>
    <button type="submit">Submit</button>
</form>
Enter fullscreen mode Exit fullscreen mode

4. Create the route for submitting form
The route method should post and its name should be saveStudent

Route::post('save_student', [StudentController::class, "saveMethod"])->name('saveStudent');
Enter fullscreen mode Exit fullscreen mode

Top comments (0)