Implementation of SoftDeletes is as follows:
A Model is created where we specify use SoftDeletes;
Also, in the migration file for this model:
$table->softDeletes();
Then we simply use it in the Controller (something like this example):
$var = ModelName::withTrashed()->find($id);
$var->restore();
The restore() method is located in Illuminate\Database\Eloquent\SoftDeletes
.
The method is accessible when accessing the Laravel trash, i.e.,
$var = ModelName::withTrashed()->find($id);
$var->restore();
Laravel trash has such methods:
withTrashed();
onlyTrashed();
But when typing (IntelliSense does not suggest that there is a method):
$var->
There is no suggestion for restore()
, but for a method likeforceDelete()
, which signifies permanent deletion in the database, it is present.
Regarding protected properties (which are specified in the model):
$fillable: Array of attributes that are allowed to be mass assignable.
$guarded: Array of attributes that cannot be mass assigned.
$table: Name of the table associated with the model.
It would be nice to see the following => for example, when typing protected, IntelliSense suggests which protected properties of the model are reserved in Laravel. And the full set of properties is available in the documentation (https://laravel.com/docs/10.x/eloquent).