“Perbarui atau buat Laravel” Kode Jawaban

Buat atau perbarui di 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

Pembaruan Laravel di mana

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

Perbarui atau buat Laravel

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

Pembaruan Laravel

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

Laravel membuat atau memperbarui

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

Perbarui atau buat Laravel

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

Jawaban yang mirip dengan “Perbarui atau buat Laravel”

Pertanyaan yang mirip dengan “Perbarui atau buat Laravel”

Lebih banyak jawaban terkait untuk “Perbarui atau buat Laravel” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya