Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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();
    	});
    }
0

restored is a method on SoftDeletingTrait, so just make sure you use SoftDeletingTrait.

0

Thanks!

But I think this has to be mentioned in documents. It gave me headache for some hours :))

Last updated 9 years ago.
0

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 ;)

Last updated 9 years ago.
0

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 :)

0

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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.