Answers for "get model in laravel"

PHP
0

laravel model get one

$flight = Flight::where('number', 'FR 900')->first();

$freshFlight = $flight->fresh();
Posted by: Guest on July-20-2021
6

laravel create or update

// 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]
);
Posted by: Guest on September-27-2020
0

Laravel model retrieve

use App\Models\Flight;

foreach (Flight::all() as $flight) {
    echo $flight->name;
}
Posted by: Guest on July-24-2021

Browse Popular Code Answers by Language