jeudi 1 mars 2018

Laravel :error when updating the database after editing data

I have two tables table "technician" and table "user" with a connection one to one and I have a form through which I edit the technician information. When I save the changes I get an error and the update doesn't work.Here is my form my code and a screenshot of the error Thank you in advance.

route.php

Route::get('/technicien/{id}/edit', 'TechnicienController@edit');
Route::patch('/technicien/{id}', 'TechnicienController@update')-
>name('technicien.update');

edit.php

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
<div class="container">
    <div class="row">
        <div class="col-md-10">
            <h1>Modifier Technicien</h1>
        <form action="" method="update">
        
        


             <div class="form-group">
            <label for="nom">Nom</label>
            <input id="nom" type="text" class="form-control" name="user[nom]" value="" >
        </div>
        <div class="form-group">
            <label for="prenom">Prenom</label>
            <input id="prenom" type="text" class="form-control" name="user[prenom]" value="" >
        </div>
        <div class="form-group">
            <label for="prenom">Email</label>
            <input id="prenom" type="text" class="form-control" name="user[email]" value="" >
        </div>

        <div class="form-group">
            <label for="">moyenne Avis</label>
            <input type="text"  name="moyenne_avis" class="form-control" value ="" >
        </div>
        <div class="form-group">
            <label for="">Etat Technicien</label>
            <input type="text"  name="actif" class="form-control" value ="" >
        </div>

        <div class="form-group">
            <input type="submit" value="enregistrer" class="form-control btn btn-primary">
        </div>
            </div>




        </form>
    </div>
</div>
@endsection

controller1.php

public function edit($id)
{
    $technicien=technicien::find($id);
    $user = $technicien->user;
    return view('technicien.edit',['moyenne_avis'=>$technicien],
    ['actif'=>$technicien],['user_id'=>$technicien])->with('user',$user);
}

controller2.php

public function update(Request $request, $id)
{
    // do some request validation

    $technicien=technicien::find($id);
    $technicien->update($request->all());
    $technicien->user->update($request->get('user'));
    return redirect('technicien');
}

enter image description here



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire