Laravel Redirect To Another URL / Web Page - HTTP Laravel Redirects

Laravel 6 Delete and soft delete Examples

Today, We want to share with you Laravel 6 Delete and soft delete Examples.In this post we will show you wordpress plugin require another plugin, hear for Laravel 6 Validation Unique With Soft Delete Example we will give you demo and example for implement.In this post, we will learn about How To Make Unique Validations Work With Soft Delete In Laravel6 with an example.

Laravel 6 Delete and soft delete Examples

There are the Following The simple About Laravel 6 Edit, delete and soft deletes Full Information With Example and source code.

  Eloquent ORM Soft Delete in Laravel 6

As I will cover this Post with live Working example to develop How To Add SoftDelete With Unique Validation In Laravel 6, so the Eloquent ORM Soft Delete & Permanent Delete in Laravel 6 is used for this example is following below.

Laravel Soft Deleting

use the Illuminate\Database\Eloquent\SoftDeletes

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Product extends Model
{
    use SoftDeletes;
}

Schema::table('products', function (Blueprint $table) {
    $table->softDeletes();
});

if ($product->trashed()) {
    //
}

Laravel 6 Querying Soft Deleted Models

Including Soft Deleted Models

$products = App\Product::withTrashed()
                ->where('cat_id', 1)
                ->get();

$product->history()->withTrashed()->get();

Laravel 6 Retrieving Only Soft Deleted Models

$products = App\Product::onlyTrashed()
                ->where('category_id', 1)
                ->get();

Restoring Soft Deleted Models in Laravel 6

$product->restore();

App\Product::withTrashed()
        ->where('category_id', 1)
        ->restore();

Laravel 6 Permanently Deleting Models

// Force deleting a single model instance...
$product->forceDelete();

// Force deleting all related models...
$product->history()->forceDelete();

Web Programming Tutorials Example with Demo

Read :

  PHP Laravel Soft Delete Migration cascade

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 6 Delete and soft delete (Practical examples).
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Reply

avatar
  Subscribe  
Notify of