Post::onlyTrashed()->where('id', $post_id)->restore();
Soft Delete : $user->delete();
Force Delete : $user->forceDelete();
Restore Soft Deleted Item : $user->restore();
Schema::table('flights', function (Blueprint $table) {
$table->softDeletes();
});
$table->softDeletes();
//i will softDelete for contact
<------------1 In Contact Modal---------->
namespace AppModels;
use IlluminateDatabaseEloquentFactoriesHasFactory;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentSoftDeletes;
class Contact extends Model
{
use HasFactory;
use SoftDeletes;
}
<---------2 create file for add delete_at column in contact table------------>
php artisan make:migration add_deleted_at_to_contacts_table
database > migration >567890874_add_deleted_at_to_contacts_table.php
<----------3 declare
$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();
/**
* Get the name of the "deleted by" column.
*
* @return string
*/
public function getDeletedByColumn()
{
return defined('static::DELETED_BY') ? static::DELETED_BY : 'deleted_by';
}
protected function runSoftDelete(){
$columns = [
$this->getDeletedAtColumn() => $this->fromDateTime($time),
$this->getDeletedByColumn() => Auth::id(),
];
}