How to Update one form data to different tables?

Posted 8 months ago by Amalmax

I am working with Laravel 5.6 and MySQL. in My app I have some data edit form and its updated values saving with 3 different tables. called vehicles, cars and upload My edit form url as following,


number (17) is vehicle table id number, like this,

id    name         owner  
1         toyota      dane
2        BMW        peter
3        Benz         samantha
4        volvo        Alex

and car table is like this,

id     fuel    vehicle_id
1          P              1
2         D              3
3          E              2

I need update cars table data with regarding to vehicle_id , My VehicleController vehicle table data update function is like this,

public function update(Request $request, $id)
        $vehicle = Vehicle::find($id);

        $vehicle->name = $request->input('name');
        $vehicle->owner = $request->input('owner');

now I need update cars table fuel values with same form optional values input. how can I do this in the Controller?

My fuel selection input is like this,

<div class="form-group">
        <label for="exampleFormControlSelect1">Fuel</label>
        <select class="form-control" id="fuel" name="fuel">
            @foreach($vehicles->cars as $car)
            <option value="{!! $car->fuel  !!}">{!! $car->fuel  !!}</option>
        <option value="P">Petrol</option>
        <option value="D">Diesel</option>
        <option value="H">Hybrid</option>
        <option value="E">Electric</option>

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.