Answers for "laravel check if record newly created"

PHP
1

laravel check if eloquent just created

$item = Item::firstOrCreate(['title' => 'Example Item']);

if ($item->wasRecentlyCreated === true) {
    // item wasn't found and have been created in the database
} else {
    // item was found and returned from the database
}
Posted by: Guest on October-10-2020
1

laravel 8 check if record exists

$subscription_count = DB::table('subscriptions')->where('pid_user',$pid_user)->count();

        //check if any subscription plan exists
        if($subscription_count == 0)
        { 
          //record does not exist 
        }else{
          //record exists
        }
Posted by: Guest on January-04-2022

Code answers related to "laravel check if record newly created"

Browse Popular Code Answers by Language