Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel delete records of child relations

 <?php

        class User extends Eloquent
        {
            // this will enable soft delete on model.
            use SoftDeletingTrait;
            protected $dates = ['deleted_at'];

            public function photos()
            {
                return $this->has_many('Photo');
            }

            // override existing delete method.
            // invoke when we call $user->delete(), softdelete.
            public function delete()
            {
                // delete all associated photos
                $this->photos()->delete();

                // delete the user
                return parent::delete();
            }

            // override existing forceDelete method.
            // invoke when we call $user->forceDelete(), force delete
            public function forceDelete()
            {
                // use of withTrashed() to delete all records
                $this->photos()->withTrashed()->forceDelete();

                // delete the user
                return parent::forceDelete();
            }
    }
Comment

PREVIOUS NEXT
Code Example
Php :: Redirect image attachment pages in Wordpress 
Php :: woocommerce check if cart is not empty 
Php :: get word between two characters php 
Php :: php.validate.executablepath wamp 
Php :: php get last index end in foreach 
Php :: validate time in laravel 
Php :: smarty if 
Php :: Composer detected issues in your platform: Your Composer dependencies require a PHP version "= 8.0.2". 
Php :: woocommerce change sale text 
Php :: php get first last loop 
Php :: webstorm vs phpstorm 
Php :: laravel collection each 
Php :: difference betwen include and indlude once 
Php :: minuscule string php 
Php :: fore install debian 10 php 7.3 
Php :: dir name php 
Php :: how to declar a variable in php 
Php :: make controller laravel 8 with resource 
Php :: set php path in ubuntu 
Php :: woocommerce change "Billing Details" text 
Php :: upload file laravel 
Php :: in loop how add string by comma in php 
Php :: php get unique values by key from array 
Php :: php array join 
Php :: Artisan::call for all catch clear in laravel 
Php :: current date time in php 
Php :: php number positive 
Php :: php capital string 
Php :: artisan mograte particular tabel 
Php :: error repoerting in php 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =