First, enable soft deletes in your model. I’ll use the users
table as an example.
use Illuminate\Database\Eloquent\SoftDeletes; class User extends Model { use SoftDeletes; protected $dates = ['deleted_at']; }
Then, create a new migration to modify the existing table.
/php artisan make:migration add_soft_deletes_to_user_table --table="users"
Open up the newly created migration file and add the softDeletes
method.
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class AddSoftDeletesToUserTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::table('users', function(Blueprint $table) { $table->softDeletes(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::table('users', function(Blueprint $table) { $table->dropSoftDeletes(); }); } }
Now, run your migration.
php artisan migrate
You should now see the deleted_at
timestamp column in your database.
my terminal is work but my database is not add deleted at row.
thanks (y)
thanks man!
very good tectnique for learnning
This is a good point we tend to forget.
Thank you for sharing the information.
Billal BEGUERADJ
Nice tutorial 🙂
Best tutorial, that I seen !
Thanks !