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.


Related FAQ

Here are some more FAQ related to this Article:

  1.   Laravel set global Variable in middleware, all controller and views
  2.   Laravel Open link in new tab Example
  3.   Query Scope using Laravel 6 Eloquent Example
  4.   Soft Delete Cascade using Laravel Eloquent Example
  5.   MySQL AND Comparison Functions and Operators By Example
  6.   Laravel 5.7 custom 404 Error Page Using Exception Handlers
  7.   Laravel Soft Delete Example Tutorial From Scratch
  8.   WooCommerce Webhooks verification in PHP
  9.   Generate Secure Random Strings using Laravel
  10.   Laravel Exception Handling Example Tutorial