Laravel检查,如果记录新创建的

代码示例

1
0

laravel8检查,如果记录存在

        
		$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
        }

1
0

laravel检查,如果雄辩的只是创造了

$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
}

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................