<? php
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentSoftDeletes;
class customModel extends Model{
use SoftDeletes;
// your other code goes here
}
Soft Delete : $user->delete();
Force Delete : $user->forceDelete();
Restore Soft Deleted Item : $user->restore();
$table->softDeletes();
$model = Contents::find( $id );
$model->delete();
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentSoftDeletes;
class Post extends Model {
use SoftDeletes;
protected $table = 'posts';
// ...
}
Namespace: use IlluminateDatabaseEloquentSoftDeletes; ->in modal
Invoking : use SoftDeletes; -> in modal
php artisan make:migration add_deleted_at_to_contacts_table
Creating a softdelete column : $table->softDeletes(); -> add_deleted_at_to_contacts_table.php
Other Important function
withTashed()->delete or nonDelete(for restore method and forcDelete method)
onlyTrashed()->delete(for view)
restore()
forceDelete()
$flights = Flight::where('active', 1)
->orderBy('name')
->take(10)
->get();