我正在尝试将以下下拉列表路由到控制器的特定部分,当我进入链接时http://127.0.0.1:8000/assignees/custom?datacenter=RDC03始终找不到页面,
这是我的路线:
Route::resource('cards','CardController');
Route::resource('customers','CustomerController');
Route::resource('assignees','AssigneeController');
Route::get('autocomplete', 'AssigneeController@autocomplete')->name('autocomplete');
Route::get('searchcard', 'AssigneeController@searchcard')->name('searchcard');
Route::get('returncard/{id}', 'AssigneeController@returncard')->name('returncard');
Route::get('custom', 'AssigneeController@custom')->name('custom');
这是index.blade.php中的视图:
<form action="{{ route('custom') }}">
<div class="form-group" id="dropdown">
<label>Data Center:</label>
<select name="datacenter" id="datacenter" class="form-group">
<option value="RDC46">RDC46</option>
<option value="RDC03">RDC03</option>
<option value="RDC05">RDC05</option>
<option value="DDC21">DDC21</option>
</select>
<button type="submit" class="btn btn-info">Submit</button>
</div>
</form>
这是我的控制器:
public function custom(Request $request)
{
// You will have access to the datacenter using $request->datacenter
$assignees = assignee::findorfail($request->datacenter)->paginate(10);
return view('assignees.custom',compact('assignees'))
->with('i', (request()->input('page', 1) - 1) * 5);
}
这是custom.blade.php的路径:
resources/views/assignees/custom.blade.php
这是我当前的路线:列表:
Domain | Method | URI | Name | Action | Middleware |
+--------+-----------+---------------------------+-------------------+------------------------------------------------------------------------+--------------+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | assignees | assignees.index | App\Http\Controllers\AssigneeController@index | web |
| | POST | assignees | assignees.store | App\Http\Controllers\AssigneeController@store | web |
| | GET|HEAD | assignees/create | assignees.create | App\Http\Controllers\AssigneeController@create | web |
| | DELETE | assignees/{assignee} | assignees.destroy | App\Http\Controllers\AssigneeController@destroy | web |
| | PUT|PATCH | assignees/{assignee} | assignees.update | App\Http\Controllers\AssigneeController@update | web |
| | GET|HEAD | assignees/{assignee} | assignees.show | App\Http\Controllers\AssigneeController@show | web |
| | GET|HEAD | assignees/{assignee}/edit | assignees.edit | App\Http\Controllers\AssigneeController@edit | web |
| | GET|HEAD | autocomplete | autocomplete | App\Http\Controllers\AssigneeController@autocomplete | web |
| | POST | cards | cards.store | App\Http\Controllers\CardController@store | web |
| | GET|HEAD | cards | cards.index | App\Http\Controllers\CardController@index | web |
| | GET|HEAD | cards/create | cards.create | App\Http\Controllers\CardController@create | web |
| | GET|HEAD | cards/{card} | cards.show | App\Http\Controllers\CardController@show | web |
| | PUT|PATCH | cards/{card} | cards.update | App\Http\Controllers\CardController@update | web |
| | DELETE | cards/{card} | cards.destroy | App\Http\Controllers\CardController@destroy | web |
| | GET|HEAD | cards/{card}/edit | cards.edit | App\Http\Controllers\CardController@edit | web |
| | GET|HEAD | custom | assignee.custom | App\Http\Controllers\AssigneeController@custom | web |
| | POST | customers | customers.store | App\Http\Controllers\CustomerController@store | web |
| | GET|HEAD | customers | customers.index | App\Http\Controllers\CustomerController@index | web |
| | GET|HEAD | customers/create | customers.create | App\Http\Controllers\CustomerController@create | web |
| | PUT|PATCH | customers/{customer} | customers.update | App\Http\Controllers\CustomerController@update | web |
| | DELETE | customers/{customer} | customers.destroy | App\Http\Controllers\CustomerController@destroy | web |
| | GET|HEAD | customers/{customer} | customers.show | App\Http\Controllers\CustomerController@show | web |
| | GET|HEAD | customers/{customer}/edit | customers.edit | App\Http\Controllers\CustomerController@edit | web |
| | GET|HEAD | home | home | App\Http\Controllers\HomeController@index | web,auth |
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController@showLoginForm | web,guest |
| | POST | login | | App\Http\Controllers\Auth\LoginController@login | web,guest |
| | POST | logout | logout | App\Http\Controllers\Auth\LoginController@logout | web |
| | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail | web,guest |
| | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest |
| | POST | password/reset | password.update | App\Http\Controllers\Auth\ResetPasswordController@reset | web,guest |
| | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController@showResetForm | web,guest |
| | GET|HEAD | register | register | App\Http\Controllers\Auth\RegisterController@showRegistrationForm | web,guest |
| | POST | register | | App\Http\Controllers\Auth\RegisterController@register | web,guest |
| | GET|HEAD | returncard/{id} | returncard | App\Http\Controllers\AssigneeController@returncard | web |
| | GET|HEAD | searchcard | searchcard | App\Http\Controllers\AssigneeController@searchcard | web
答案 0 :(得分:0)
您应该尝试以下操作:
public function custom(Request $request)
{
// You will have access to the datacenter using $request->datacenter
$assignees = assignee::findorfail($request->datacenter)->paginate(10);
return view('assignees.custom',compact('assignees'));
}
只需删除with()
并尝试
更新后的答案
<form action="{{ route('assignee.custom') }}">
<div class="form-group" id="dropdown">
<label>Data Center:</label>
<select name="datacenter" id="datacenter" class="form-group">
<option value="RDC46">RDC46</option>
<option value="RDC03">RDC03</option>
<option value="RDC05">RDC05</option>
<option value="DDC21">DDC21</option>
</select>
<button type="submit" class="btn btn-info">Submit</button>
</div>
</form>
答案 1 :(得分:0)
您可以尝试这样的事情吗?
Route::get('/custom', 'AssigneeController@custom')->name('assignee.custom');
Route::resource('cards','CardController');
Route::resource('customers','CustomerController');
Route::resource('assignees','AssigneeController');
Route::get('autocomplete', 'AssigneeController@autocomplete')->name('autocomplete');
Route::get('searchcard', 'AssigneeController@searchcard')->name('searchcard');
Route::get('returncard/{id}', 'AssigneeController@returncard')->name('returncard');
和
<form action="{{ route('assignee.custom') }}">
如果这是由于Route::resource('assignees','AssigneeController');
生成了一条路由assignees/{assignee}
而没有任何正则表达式的原因,那么您的受让人/自定义路由就会被该路由捕获