PHP Laravel Soft Delete Migration cascade

Today, We want to share with you Simple PHP Laravel Soft Delete Records.
In this post we will show you laravel soft delete Tutorial, hear for laravel soft delete relationship we will give you demo and example for implement.
In this post, we will learn about laravel soft delete cascade with an example.

PHP Laravel Soft Delete Records

How to use soft delete in Laravel 5?

How work simple soft delete, with soft deleted records laravel add deleted_at simple database column on the table that be setting will be null value created and when we here action delted to remove then it will place simple value put current date and time timestamp, and then Laravel Model generally all the fetch that row have only simple set here deleted_at = null.

Migration Example:

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProductsTable extends Migration
{

    public function up()
    {
        Schema::create('products', function(Blueprint $table) {
            $table->increments('id');
            $table->string('title');
            $table->text('information');
            $table->softDeletes();
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::drop("products");
    }
}

Good, And then We can simple here database find deleted_at column in our Database products table and We have simple also Laravel model need look such as bellow:

Products Model

namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Product extends Model
{
    use SoftDeletes;
    public $fillable = ['title','information'];
    protected $dates = ['deleted_at'];
}

And then, We may use here simple Product model in Laravel as generally such We use before, We get all rows such this way.

$data = Product::get();
$data = Product::find(1)->delete();
Laravel CRUD
PHP Laravel Soft Delete Migration
PHP Laravel Soft Delete Migration

Read :

Summary

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

I hope you get an idea about Soft Delete example for Laravel.
I would like to have feedback on my Pakainfo.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 Comment