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.
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
You're probably trying to do mass assignment. Just add name
field to $fillable
.
It has nothing to do with soft deletes.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community