“Zaktualizuj lub utwórz Laravel” Kod odpowiedzi

Utwórz lub aktualizuj w Laaravel

//if there is id => 1 for user role , update this and if there is not 
//id => 1 create it and insert some data for it
 $data = $request->all();
   UserRule::updateOrCreate(
            ['id' => 1],
            $data
        );
Mohamad

aktualizacja laravel gdzie

User::where('id', $user_id)
    ->update([
           'name' => $name
    ]);
Snippets

Zaktualizuj lub utwórz Laravel

$user = User::updateOrCreate(['name' => request()->name], [ 
    'foo' => request()->foo
]);
Fragile Fish

aktualizacja laravel

Flight::where('active', 1)
      ->where('destination', 'San Diego')
      ->update(['delayed' => 1]);
Cooperative Crab

Laravel Utwórz lub aktualizuj

// 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

Zaktualizuj lub utwórz Laravel

$user = User::updateOrCreate(
    ['email' =>  request('email')],
    ['name' => request('name')]
);
 
// Do other things with the User
ibtesam khan

Odpowiedzi podobne do “Zaktualizuj lub utwórz Laravel”

Pytania podobne do “Zaktualizuj lub utwórz Laravel”

Więcej pokrewnych odpowiedzi na “Zaktualizuj lub utwórz Laravel” w PHP

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu