I have this example
public static function boot()
{
// make the parent (Eloquent) boot method run
parent::boot();
// cause a soft delete of a product to cascade to children so they are also soft deleted
static::deleted(function($invoice)
{
try
{
DB::beginTransaction();
$invoice->detail()->delete();
$invoice->folio()->delete();
$invoice->total()->delete();
DB::commit();
}
catch(Exception $e)
{
DB::rollback();
throw new Exception("Error Processing Request", 1);
}
});
static::restored(function($invoice)
{
$invoice->detail()->restore();
$invoice->folio()->restore();
$invoice->total()->restore();
});
}
restored
is a method on SoftDeletingTrait
, so just make sure you use SoftDeletingTrait
.
Thanks!
But I think this has to be mentioned in documents. It gave me headache for some hours :))
It is: http://laravel.com/docs/4.2/eloquent#soft-deleting
And btw should you have a headache again, just use your IDE or editor's feature called find in project/ find in files etc and simply search for the method you need ;)
Yes, the docs mention the soft delete trait, but it doesn't mention that those events are defined in that trait!
Normally, you would look at http://laravel.com/docs/4.2/eloquent#model-events to find events related to your model (as a reference I mean).
The search thing is good too, but it doesn't replace the docs not mentioning this!
It seems I am counting on docs more than I should :)
I can suggest you with one software and that is "Ahsay backup" as i am using this software for my business use , So try it out. Many new softwares i have tries like acronis etc but i guess according to the speed i would 9/10 marks to this software. Use it.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community