troelskn / laravel-fillable-relations

Provides HasFillableRelations trait to Eloquent models
63 stars 23 forks source link

Model record does not updated, on self or on relation #17

Open abhimanusharma opened 5 years ago

abhimanusharma commented 5 years ago

Hi,

My controller has,

$Data = Data::findOrFail($id);
$DataData = $request->all();
$Data = $Data->fill($DataData);

Result of dump($DataData) is below:

array:21 [▼
  "_method" => "PATCH"
  "_token" => "dfsfsfsdfsdfxfghcgxtydh"
  "name_prefix" => "Mr"
  "first_name" => "Abhi"
  "last_name" => "Test"
  "primary_email" => "pass@test.com"
  "primary_phone" => "9999999999"
  "company_name" => null
  "secondary_email" => "pass2@test.com"
  "secondary_phone" => "8888888888"
  "country" => "IN"
  "source" => "MOW"
  "destination" => "AMS"
  "departure_date" => "2019-08-29 05:09:50"
  "return_date" => null
  "booking_status" => "FOLLOW"
  "bookings" => array:1 [▼
    0 => array:8 [▼
      "passenger_first_name" => null
      "passenger_last_name" => null
      "passenger_age" => null
      "passenger_pnr" => "322433"
      "ticket_number" => null
      "airline_name" => null
      "topline" => "0"
      "cost" => "0"
    ]
  ]
  "attachments" => array:1 [▼
    0 => null
  ]
  "comment" => null
  "comment_created_by" => "1"
  "updated_by" => "1"
]

Result of dump($Data) is below:

Data {#271 ▼
  #fillable_relations: array:3 [▼
    0 => "bookings"
    1 => "comments"
    2 => "attachment"
  ]
  #fillable: array:21 [▼
    0 => "name_prefix"
    1 => "first_name"
    2 => "last_name"
    3 => "primary_email"
    4 => "primary_phone"
    5 => "company_name"
    6 => "secondary_email"
    7 => "secondary_phone"
    8 => "country"
    9 => "travel_type"
    10 => "source"
    11 => "destination"
    12 => "departure_date"
    13 => "customer_type"
    14 => "customer_type"
    15 => "return_date"
    16 => "booking_source"
    17 => "booking_status"
    18 => "booking_gds"
    19 => "supplier_id"
    20 => "created_by"
  ]
  #dates: array:4 [▼
    0 => "departure_date"
    1 => "return_date"
    2 => "created_at"
    3 => "updated_at"
  ]
  #connection: "mysql"
  #table: "Datas"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:23 [▶]
  #original: array:23 [▶]
  #changes: []
  #casts: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [▼
    0 => "*"
  ]
}

Data was updated earlier using Data::fill() but not updating any information anymore. I believe I have not changed anything in the controller, Model or View related to Data or related Models.

troelskn commented 5 years ago

Hi Abhi,

I'm not entirely sure what the issue is here?

What would you get from the following:

$docket = Docket::findOrFail($id);
dump($docket->toArray());
$docketData = $request->all();
$docket = $docket->fill($docketData);
dump($docket->toArray());
abhimanusharma commented 5 years ago

Hi @troelskn ,

I am getting this result:

array:23 [▼
  "id" => 1
  "name_prefix" => "Mr"
  "first_name" => "Abhi"
  "last_name" => "Test"
  "primary_email" => "pass@test.com"
  "primary_phone" => "9999999999"
  "company_name" => null
  "secondary_email" => "pass2@test.com"
  "secondary_phone" => "8888888888"
  "country" => "IN"
  "travel_type" => "International Flight"
  "source" => "MOW"
  "destination" => "AMS"
  "departure_date" => "2019-08-29 23:15:09"
  "customer_type" => "New Customer"
  "return_date" => null
  "booking_source" => "fb chat"
  "booking_status" => "FOLLOW"
  "booking_gds" => "Amadeus"
  "created_by" => 1
  "updated_by" => null
  "created_at" => "2019-08-24 03:18:21"
  "updated_at" => "2019-08-24 03:18:21"
]

but data is not updating into the database.

ilvalerione commented 5 years ago

You should call $docket->save() after fill() to persist data on the database.