VOOZH about

URL: https://www.geeksforgeeks.org/php/laravel-delete-records/

⇱ Laravel | Delete Records - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Laravel | Delete Records

Last Updated : 27 Apr, 2020
To delete records we can use DB facade with the delete method. To do so follow the below steps one by one:
  • Step 1: Create Controller UserController by executing this command.
    php artisan make:controller UserController
    👁 Image
  • Step 2: We can delete records in two ways. First Method: The first is to delete direct using database command. Write following Code in App/Http/Controllers/UserController.php Second Method: The second way is to delete using the Laravel delete Function and User Model (Easy one).
  • Step 3: Implementation or Driver Code and create web routes for implementation of the above code in routes/web.php
  • Step 4: Create a View File from where we display our users in resources/views directory name user.blade.php. Write following HTML code.
  • Step 5: Start the server by executing php artisan:serve command and go to http://localhost:8000/user and the output will be: 👁 Image
  • Output: Click on the delete button to get the record deleted. After deleting two records output is: 👁 Image
Comment
Article Tags: