Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel firstorcreate usage

// Retrieve flight by name, or create it if it doesn't exist...
$flight = AppFlight::firstOrCreate(['name' => 'Flight 10']);

// Retrieve flight by name, or create it with the name, delayed, and arrival_time attributes...
$flight = AppFlight::firstOrCreate(
    ['name' => 'Flight 10'],
    ['delayed' => 1, 'arrival_time' => '11:30']
);
Comment

eloquent firstOrCreate

firstOrCreate() will automatically create a new entry in the database if there is not match found. Otherwise it will give you the matched item.
firstOrNew() will give you a new model instance to work with if not match was found, but will only be saved to the database when you explicitly do so (calling save() on the model). Otherwise it will give you the matched item.
Comment

PREVIOUS NEXT
Code Example
Php :: laravel get last get request 
Php :: remove symbolsand spaces php 
Php :: laravel migration change default value 
Php :: convert string to array laravel 
Php :: php keep only letters and numbers 
Php :: laravel validate unique column 
Php :: Artisan::call for all catch clear in laravel 
Php :: replace all numbers in string php 
Php :: get category post in wordpress 
Php :: while loop php 
Php :: laravel env asset_url 
Php :: curl exec not working php 
Php :: php if string contains 
Php :: wp wordpress logout 
Php :: show display error php 
Php :: display image in laravel 
Php :: php cors multiple headers 
Php :: laravel migration remove unique 
Php :: browser detection php 
Php :: how send parameter with command in laravel 
Php :: larevel version artisan 
Php :: php file for image load 
Php :: laravel route slug 
Php :: php import python script 
Php :: php convert mb to bytes 
Php :: laravel remove duplicates from array 
Php :: how to change javascript value to php value 
Php :: laravel routing controller get and post method 
Php :: where not null in laravel 
Php :: laravel echo query 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =