简体   繁体   中英

updating the data in pivot table laravel 5

i have a many to many realtionship and a pivot table now i want to update the pivot table data with a form that users sends. here for example is assign a client to a sellman . here is my code : in route :

Route::get('admin/client/assign','ClientController@assignsellman');

controller :

public function assignsellman(Request $request){
    $user = User::all();
    $client_list = Client::all();
    $client = Client::with('sellmanlist')->firstOrFail();
    $sellman = $request->input('sellman');
    $client->sellmanlist()->attach($sellman);
    return view('admin.client.assign',compact('client_list','user'));

}

and finally here is the form of view file that i want to get 2 variables one the id of the client and the secound the id of sell man

    <form action="/admin/client/" method="post">
                <input type="hidden" name="_method" value="PUT">
                {{ csrf_field() }}
                <div class="row">
                    <div class="col-xs-4">
                        <div class="form-group">
                            <label for="client">مشتری</label>
                            <select class="select-search select2-hidden-accessible" tabindex="-1" aria-hidden="true"
                                    name="client">
                                @foreach($client_list as $client_lists)
                                    <option value="">{{$client_lists->title}}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="col-xs-4 text-center">
                        <i class="icon-arrow-left7 mr-3 icon-3x" style="font-size: 130px"></i>
                        <h4>ارجاع به</h4>
                    </div>
                    <div class="col-xs-4">
                        <div class="form-group">


                            <div class="form-group">
                                <label for="sellman">کارشناس فروش</label>
                                <select class="select-search select2-hidden-accessible" tabindex="-1"
                                        aria-hidden="true" name="sellman">
                                    @foreach($user as $users)
                                        <option value="1">{{$users->name}}</option>
                                    @endforeach
                                </select>
                            </div>

                        </div>
                    </div>

                </div>
                @if ($errors->any())
                    <div class="alert alert-danger">
                        <ul>
                            @foreach ($errors->all() as $error)
                                <li>{{ $error }}</li>
                            @endforeach
                        </ul>
                    </div>
                @endif
                <button type="submit" class="btn btn-primary">تایید</button>
            </form>

with this code i get this error

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message

thanks for help

That is because the route you've created is HTTP GET, and in your form you're using HTTP Post.

<form action="/admin/client/" method="post">

Try switching to a GET method and it should work

<form action="/admin/client/" method="get">

or switch your route to

Route::post('admin/client/assign','ClientController@assignsellman');

Please take a look at the different HTTP Verbs and apply them to your needs.

https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

编辑路线

Route::post('admin/client/','ClientController@assignsellman');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM