• This topic has 2 replies, 2 voices, and was last updated 1 year ago by dan.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #516

    The updateorCreate method updates an existing model and create it if it does not exist

    In the Laravel documentation:

    In the example below, if a flight exists with a departure location of Oakland and a destination location of San Diego, its price and discounted columns will be updated. If no such flight exists, a new flight will be created which has the attributes resulting from merging the first argument array with the second argument array:

    $flight = Flight::updateOrCreate(
    [‘departure’ => ‘Oakland’, ‘destination’ => ‘San Diego’],
    [‘price’ => 99, ‘discounted’ => 1]

    My problem is that the column ‘discounted’ is not update


    The updateOrCreate method uses mass assignment and therefore you should make sure that the property ‘discounted’ is included in the protected fillable field in your Flight model

    In Flight.php:

    protected fillable = [‘discounted’];


    It works. Thank you

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.