我正在使用Laravel 5.2并尝试在下拉列表选择中提交表单。即使我能做到。但它始终重定向到store
函数,该函数已注册为resource
路由。
我的routes.php文件的路由定义如下:
Route::group(['middleware' => ['web']], function () {
Route::group(['middleware' => 'auth'], function () {
Route::get('dashboard', function () {
return view('dashboard.dashboard');
});
Route::get('getcurrency', 'QuoteController@getCurrency'); <!--------This is where i have problem--------->
Route::resource('quotes','QuoteController');
});
});
我也尝试过命名路线。但它总是带我走向store function
这是我的下拉列表的样子:
<form method="post" action={{ action('QuoteController@getCurrency') }}>
<div class="form-group">
<label class="control-label col-md-1">Name</label>
<div class="col-md-5">
<select class="form-control select2me selectCurrency" name="user_id" onchange="this.form.submit()">
@foreach($users as $user)
<option value="{{$user->id}}">{{ $user->name }}
@if(!empty($user->companyname))
({{$user->companyname }})
@else
({{$user->email}})
@endif
</option>
@endforeach
</select>
</div>
</div>
</form>
我无法理解为什么它总是强制将值发送到store
函数,当我甚至试图提及route
,method
,url
和action
。非系统为我工作。
laravel是否已预定义将SUBMIT BUTTON仅限于特定功能?
以下是我的表格时我的网址:
http://localhost/laravel/public/quotes
有谁知道为什么会这样?我该如何解决?
谢谢!
答案 0 :(得分:0)
如果您使用路线资源,您的帖子将自动以商店方式进行更多https://laravel.com/docs/5.2/controllers#restful-resource-controllers
如果您想更改方法,请更改操作,例如
<form method="post" action='quotes'>
然后需要在资源路径
之前为此URL写一个路由Route::group(['middleware' => ['web']], function () {
Route::group(['middleware' => 'auth'], function () {
Route::get('dashboard', function () {
return view('dashboard.dashboard');
});
Route::get('getcurrency', 'QuoteController@getCurrency'); <!--------This is where i have problem--------->
Route::post('quotes','QuoteController@customMethod');
Route::resource('quotes','QuoteController');
});
});
答案 1 :(得分:0)
Route.php
Route::group(['middleware' => ['web']], function () {
Route::group(['middleware' => 'auth'], function () {
Route::get('dashboard', function () {
return view('dashboard.dashboard');
});
Route::post('getcurrency', 'QuoteController@getCurrency'); // make it post instead of get
Route::resource('quotes','QuoteController');
});
});
刀片文件
<form method="post" action={{ url('getcurrency') }}>
<input type="hidden" name="_token" value={{ csrf_token() }}/>
<div class="form-group">
<label class="control-label col-md-1">Name</label>
<div class="col-md-5">
<select class="form-control select2me selectCurrency" name="user_id" onchange="this.form.submit()">
@foreach($users as $user)
<option value="{{$user->id}}">{{ $user->name }}
@if(!empty($user->companyname))
({{$user->companyname }})
@else
({{$user->email}})
@endif
</option>
@endforeach
</select>
</div>
</div>
</form>