Answers for "laravel check if eloquent just created"

PHP
0

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

Code answers related to "laravel check if eloquent just created"

Browse Popular Code Answers by Language