0
votes

I have two Tables Brands and BrandTimings, I want to save brand with pickup and delivery time, and I have a form which I m submitting with all data I m getting an error, I understand error but i don't know how to assign pickup and delivery time to a variable and remove them and then using afterSave(), save them in BrandTimings with the newly created brand's id, I have tried beforeSave() and I couldn't understand how to do as October cms documentation has no example,

Column not found: 1054 Unknown column 'pickup_time' in 'field list' (SQL: insert into offline_mall_brands (name, id, pickup_time, delivery_time, slug, website, description, updated_at, created_at) values (ASDE, 1, ["0","1"], ["2","3"], zip-jet, , , 2020-06-04 10:19:17, 2020-06-04 10:19:17))" on line 664 of /home/vagrant/code/cml/vendor/laravel/framework/src/Illuminate/Database/Connection.php

Brands

id     name      location
1      Inspire   Lacer

BrandTimings

id     brand_id      pickup_time     delivery_time
1      1             08:00           15:00 
1      1             09:00           16:00
1      1             10:00           17:00
1      1             11:00           18:00  
1

1 Answers

1
votes

Oh I see what is happening. Brands doesn't have the delivery_time but BrandTimings does. One way that this would work is in your php. Now you don't mention if these models are related to each other so I won't write that way. And you don't show how you are attempting to save it now so I am going to make it up. Here is an example:

public function onSaveBrandTimings() {

    // Get inputs and you would validate them as well
    $name = Input::get('name');
    $location = Input::get('location');
    $pickup_time = Input::get('pickup_time');
    $delivery_time = Input::get('deliver_time');

    if ($validates == true) {

        // Create Brand
        $brand = New Brands;// Create brand instance but won't have id
        $brand->name = $name;
        $brand->location = $location;
        $brand->save(); // Saving the brand will fill in the ID in the instance

        // Create BrandTimings
        $brandTimings = new BrandTimings;
        $brandTimings->brand_id = $brand->id;
        $brandTimings->pickup_time = $pickup_time;
        $brandTimings->delivery_time = $delivery_time;
        $brandTimings->save();

        // Return a statment or a partial update or a redirect
        return 'Success'

    } else {

        return 'Failed'

    }
}