Laravel maatwebsite export excel - I have is with the timestamps created_at and updated_at

Posted in CategoryLaravel
  • N
    Neeltje Chanterie 1 year ago

    Finally I found something that works.
    I'm new to laravel so this helps alot!
    But the only problem I have is with the timestamps ... because you don't insert the created_at timestamp I get an error and can't see my view ...
    Any help/solution?

    Link: https://itsolutionstuff.com/post/laravel-5-import-export-to-excel-and-csv-using-maatwebsite-exampleexample.html

  • H
    Hardik Savani 1 year ago

    you can insert data this way : 

    Item::create($insert); 
    // instead of 
    DB::table('items')->insert($insert);

    try this timestamps will work

  • N
    Neeltje Chanterie 1 year ago

    Thank you So much Hardik

    Now it works for the timestamps and creates a record, but the values of $insert are not inserting ...

  • H
    Hein Htet 1 year ago

    Thanks friend it`s really help-full me

  • H
    Hardik Savani 1 year ago

    did you write field name on $fillable in app/Item.php Model like :

    public $fillable = ['title','description'];
  • N
    Neeltje Chanterie 1 year ago

    Yes I did, but my timestamps are protected ...

  • H
    Hardik Savani 1 year ago

    Can you comment $dates variable and check again for just testing, that way we can check it is working or not ?

  • N
    Neeltje Chanterie 1 year ago

    Same results as before,
    If I add DB::table('products')->insert($insert); it only inserts the info of the product
    and if I add Product::create($insert); it inserts only the timestamps.

  • H
    Hardik Savani 1 year ago

    Hmm, It's strange, Can you try with protected into public fillable variable in Model ?

    Like : 

    public $fillable = ['title','description'];
  • N
    Neeltje Chanterie 1 year ago

    Also doesn't work ...
    I will just add a column for created_at in my sheet for now ...

Please login or register to leave a response.

* You May Also Like Bellow Issue to check *