Laravel's question about the firstOrCreate method. If it is judged whether the returned model is a new one or an original one,
大家讲道理
大家讲道理 2017-05-16 16:48:21
0
1
408

laravel Questions about firstOrCreate method

If it exists, the original data will be returned,

If it does not exist, it will be created

Then how do you know whether what he returns is the original one or the new one?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
小葫芦

wasRecentlyCreatedProperties.

$user = User::firstOrCreate($userData);
if($user->wasRecentlyCreated){
    // 新用户处理
    
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!