Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 2, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 2, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 2, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 2, 2025

      The Alters: Release date, mechanics, and everything else you need to know

      June 2, 2025

      I’ve fallen hard for Starsand Island, a promising anime-style life sim bringing Ghibli vibes to Xbox and PC later this year

      June 2, 2025

      This new official Xbox 4TB storage card costs almost as much as the Xbox SeriesXitself

      June 2, 2025

      I may have found the ultimate monitor for conferencing and productivity, but it has a few weaknesses

      June 2, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      May report 2025

      June 2, 2025
      Recent

      May report 2025

      June 2, 2025

      Write more reliable JavaScript with optional chaining

      June 2, 2025

      Deploying a Scalable Next.js App on Vercel – A Step-by-Step Guide

      June 2, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      The Alters: Release date, mechanics, and everything else you need to know

      June 2, 2025
      Recent

      The Alters: Release date, mechanics, and everything else you need to know

      June 2, 2025

      I’ve fallen hard for Starsand Island, a promising anime-style life sim bringing Ghibli vibes to Xbox and PC later this year

      June 2, 2025

      This new official Xbox 4TB storage card costs almost as much as the Xbox SeriesXitself

      June 2, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»How to delete the data from Database using Laravel 11

    How to delete the data from Database using Laravel 11

    February 12, 2025

    In this tutorial, we will learn How to delete the data from the database using Laravel 11. To delete data in Laravel 11, follow these steps:

    Files created for this tutorial

    fetch.blade.php (resources/views/fetch.blade.php)

    deleteController.php (app/Http/Controllers/deleteController.php)

    web.php (routes/web.php)

    The User Data looks like before the delete.

    Laravel-Data-delete

    Step 1:  Create the Fetch View

    Already created in the previous tutorial

    @if(session('success'))
                <div class="alert alert-success">{{ session('success') }}</div>
            @endif
    
            @if(session('error'))
            <div class="alert alert-danger">{{ session('error') }}</div>
            @endif
                <table class="table table-striped table-hover table-bordered">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>First Name</th>
                            <th>Last Name</th>
                            <th>Email id</th>
                            <th>Mobile No</th>
                            <th>Address</th>
                            <th>City</th>
                            <th>State</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach ($data as $id => $user )
                        <tr>
                            <td>1</td>
                            <td>{{ $user->firstName }}</td>
                            <td>{{ $user->lastName }}</td>
                            <td>{{ $user->emailId }}</td>
                            <td>{{ $user->mobileNumber }}</td>
                            <td>{{ $user->address }}</td>
                            <td>{{ $user->city }}</td>
                            <td>{{ $user->state }}</td>
                            <td>    <a class="btn btn-primary btn-sm" href="{{ route('update', $user->id) }}">Edit</a></td>
                        </tr>
                        @endforeach
                          
                    </tbody>
                </table>

    Step 2: Create a controller for data deleting.

    php artisan make:controller deleteController

    Add logic to delete data in the controller (app/Http/Controllers/deleteController.php)

    <?php
    namespace AppHttpControllers;
    use IlluminateSupportFacadesDB;
    use IlluminateHttpRequest;
    
    class deleteController extends Controller
    {
        public function deleteUser(string $id){
            $user=DB::table('tblusers')
            ->where('id', $id)
            ->delete();
            if($user){
                return redirect()->route('fetch')->with('success', 'Data deleted.');
            } else{
                return redirect()->route('fetch')->with('Something went wrong . Please Try again.');
            }
        }
    }

    How to run the Script

    1. Download the project zip file

    2. Extract the file and copy insert-app  folder

    3. Paste inside root directory (for xampp xampp/htdocs, for wamp wamp/www, for lamp var/www/Html)

    4.Open PHPMyAdmin (http://localhost/phpmyadmin)

    5. Create a database with the name  userdb

    6. Import userdb.sql file(given inside the zip package in SQL file folder)

    7. Run these command

    PS C :> cd xampp/htdocs/insert-app

    PS C:xampphtdocsinsert-app> php artisan serve

    8. After that open the browser and run the script

    http://127.0.0.1:8000/fetch

    Download Full source code(Delete Data Using Laravel11)
    Size: 27.5 MB
    Version: V 1.0
    Download Now!

    The post How to delete the data from Database using Laravel 11 appeared first on PHPGurukul.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleNew Windows 11 reference hints Start Menu Recommendations might be optional
    Next Article How to Start a Fiction Blog and Rank in 28 Days on Google: The Ultimate SEO Guide

    Related Posts

    Artificial Intelligence

    Markus Buehler receives 2025 Washington Award

    June 2, 2025
    Artificial Intelligence

    LWiAI Podcast #201 – GPT 4.5, Sonnet 3.7, Grok 3, Phi 4

    June 2, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    I’m reinstalling Starfield to play this crazy new Watchtower ‘Creations’ mod from some of Fallout’s best modders — the latest update just added an amazing feature, too

    News & Updates

    Best Practices for Web Permissions

    Development

    1win: Experience Top-Tier Sports Betting & Casino Thrills Online

    Learning Resources

    Redis DoS Vulnerability: Attackers Can Exhaust Server Memory or Cause Crashes

    Security

    Highlights

    CVE-2025-2776 – SysAid XXE Vulnerability

    May 7, 2025

    CVE ID : CVE-2025-2776

    Published : May 7, 2025, 3:15 p.m. | 4 hours, 29 minutes ago

    Description : SysAid On-Prem versions
    Severity: 9.3 | CRITICAL

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    Ghost Ransomware Group Exploiting Unpatched Software, FBI and CISA Warn

    February 20, 2025

    CVE-2025-29686 – OA System Cross-Site Scripting (XSS)

    May 14, 2025

    CVE-2025-47582 – QuantumCloud WPBot Pro WordPress Chatbot Object Injection Vulnerability

    May 19, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.