Support the ongoing development of Laravel.io →
Database

Hello Laravel Community,

I am a beginner in Laravel. I have learned the soft delete concept using [](laravel.com) and using this tutorial: [](https://www.scratchcode.io/how-to-use-the-laravel-soft-delete/)

Product Migration Table

`<?php

use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration;

class CreateProductTable extends Migration { public function up() { Schema::create('products', function (Blueprint $table) { $table->bigIncrements('id'); $table->string('name'); $table->text('description'); $table->softDeletes(); $table->timestamps(); }); }

public function down()
{
    Schema::dropIfExists('products');
}

} ?> `


Product Model

`<?php

namespace App;

use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; //add this line

class Product extends Model { use SoftDeletes; //add this line

public $fillable = [ 'description' ];
protected $dates = [ 'deleted_at' ];

} ?>`

Don't know what is changed in my code. The name field is stopped populating in the database. Help me, guys! Thanks in advance.

Also, I would like to fetch the soft-deleted data for my Trash tab.

Last updated 2 years ago.
0
moderator

Hello Mayank,

You don't need to add the deleted_at to the dates array, the trait will handle that for you.

I'm not sure what your problem is, I see your model and migration but no code how you use it.

If you use a create/update using a mass assignment you need to add the name field to your $fillable array. Else it will not filled. Maybe is that part of your question.

Did you find the documentation about soft deletes? https://laravel.com/docs/8.x/eloquent#soft-deleting

0

You're probably trying to do mass assignment. Just add name field to $fillable.

It has nothing to do with soft deletes.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Mayank scratchcodeio Joined 29 Dec 2020

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.