Laravel Eloquent

Reference

Soft Deletes adds the column deleted_at to your table. It can be added by updating the migration config.

Example config for User table below:

  1. <?php
  2.  
  3. use Illuminate\Database\Migrations\Migration;
  4. use Illuminate\Database\Schema\Blueprint;
  5. use Illuminate\Support\Facades\Schema;
  6.  
  7. class CreateUsersTable extends Migration
  8. {
  9. /**
  10.   * Run the migrations.
  11.   *
  12.   * @return void
  13.   */
  14. public function up()
  15. {
  16. Schema::create('users', function (Blueprint $table) {
  17. $table->id();
  18. $table->string('name');
  19. $table->string('username')->unique();
  20. //$table->timestamp('email_verified_at')->nullable();
  21. $table->string('password');
  22. $table->rememberToken();
  23. $table->timestamps();
  24. $table->softDeletes();
  25. });
  26. }
  27.  
  28. /**
  29.   * Reverse the migrations.
  30.   *
  31.   * @return void
  32.   */
  33. public function down()
  34. {
  35. Schema::dropIfExists('users');
  36. }
  37. }
$user = App\User::where('username', 'bob')->first();
$user->delete();
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies