“Laravel updateRcreate” Código de respuesta

Laravel updateRcreate

// If there's a flight from Oakland to San Diego, set the price to $99.
// If no matching model exists, create one.
$flight = App\Flight::updateOrCreate(
    ['departure' => 'Oakland', 'destination' => 'San Diego'],
    ['price' => 99, 'discounted' => 1]
);
Alberto Peripolli

updateRcreate

$user = User::updateOrCreate(
    ['email' =>  request('email')],
    ['name' => request('name')]
);

// Do other things with the User

Shiny Swiftlet

Laravel crea o actualiza

// If there's a flight from Oakland to San Diego, set the price to $99.
// If no matching model exists, create one.
$flight = App\Models\Flight::updateOrCreate(
    ['departure' => 'Oakland', 'destination' => 'San Diego'],
    ['price' => 99, 'discounted' => 1]
);
Embarrassed Eel

crear un nuevo registro a través del modelo en Laravel

$userData = array('username' => 'Me', 'email' => '[email protected]');
User::create($userData);
Romesh Fernando

elocuente primario

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.
Quaint Quetzal

Respuestas similares a “Laravel updateRcreate”

Preguntas similares a “Laravel updateRcreate”

Más respuestas relacionadas con “Laravel updateRcreate” en PHP

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código