dimanche 14 octobre 2018

How to Update one form data to different tables in Laravel?

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,

http://localhost:8000/myads/1/edit

number (1) 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');

        $vehicle->save();
}

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>
            @endforeach 
        <option value="P">Petrol</option>
        <option value="D">Diesel</option>
        <option value="H">Hybrid</option>
        <option value="E">Electric</option>

        </select>
        </div> 

How can do it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire