https://dev.to/norbybaru #overview Overview https://laravel.com/docs/master/eloquent is an object-relational mapper (ORM) that makes it enjoyable to interact with your database. A Model in this case will be a representation of a database row as well as entity relationship.

However in case the record was not found, new record will be created and persisted to the database using given data.

use App\Models\Flight; // Update flight where departure and destination with price and discounted // or create new record with departure, destination, price and discounted $flight = Flight::updateOrCreate(['departure' => 'Oakland', 'destination' => 'San Diego'], ['price' => 99, 'discounted' => 1]); Enter fullscreen mode

Flight::upsert([ ['departure' => 'Oakland', 'destination' => 'San Diego', 'price' => 99], ['departure' => 'Chicago', 'destination' => 'New York', 'price' => 150]], ['departure', 'destination'], ['price']); Enter fullscreen mode
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners