我在 laravel 5 中的表单路由一直指向用户
My form route in laravel 5 keep pointing at user
无论我做了什么更改,我在 laravel 中的表单模型一直指向 http://localhost:8000/user/profile/account/17
。我有两条路线,一条给管理员,另一条给用户。
即使我在管理员模式下,表单路由仍然指向用户。
{!! Form::model($user, ['method'=>'PATCH', 'action' => ['ProfileController@update',$user->user_id]]) !!}
这些是我的路线:
Route::group(['prefix' => 'admin', 'middleware' => 'auth:admin'], function()
{
$a = 'admin.';
Route::get('/', ['as' => $a . 'home', 'uses' => 'AdminController@getHome']);
Route::get('/profile', ['as' => $a . 'profile', 'uses' => 'ProfileController@index']);
Route::get('/products', ['as' => $a . 'products', 'uses' => 'ProfileController@products']);
Route::get('/payment', ['as' => $a . 'products', 'uses' => 'ProfileController@payment']);
Route::get('/profile/account/{id}', ['as' => $a . 'edit', 'uses' => 'ProfileController@edit']);
Route::patch('/profile/account/{id}', ['as' => $a . 'edit', 'uses' => 'ProfileController@update']);
});
Route::group(['prefix' => 'user', 'middleware' => 'auth:user'], function()
{
$a = 'user.';
Route::get('/', ['as' => $a . 'home', 'uses' => 'UserController@getHome']);
Route::get('/profile', ['as' => $a . 'profile', 'uses' => 'ProfileController@index']);
Route::get('/profile/account/{id}', ['as' => $a . 'edit', 'uses' => 'ProfileController@edit']);
Route::Patch('/profile/account/{id}', ['as' => $a . 'edit', 'uses' => 'ProfileController@update']);
});
管理员和用户共享同一个控制器ProfileController
。
谢谢!
使用路线而不是行动怎么样。
然后使用 if 语句在使用模型打开表单之前检查您的管理员或用户。
@if(admin)
{!! Form::model($user, ['method'=>'PATCH', 'route' => ['admin.edit', $user->id]]) !!}
@else
{!! Form::model($user, ['method'=>'PATCH', 'route' => ['user.edit', $user->id]]) !!}
不是最干净的,但解决了 url 表单应该指向的问题。使用 admin 作为占位符请公开您自己的变量。
无论我做了什么更改,我在 laravel 中的表单模型一直指向 http://localhost:8000/user/profile/account/17
。我有两条路线,一条给管理员,另一条给用户。
即使我在管理员模式下,表单路由仍然指向用户。
{!! Form::model($user, ['method'=>'PATCH', 'action' => ['ProfileController@update',$user->user_id]]) !!}
这些是我的路线:
Route::group(['prefix' => 'admin', 'middleware' => 'auth:admin'], function()
{
$a = 'admin.';
Route::get('/', ['as' => $a . 'home', 'uses' => 'AdminController@getHome']);
Route::get('/profile', ['as' => $a . 'profile', 'uses' => 'ProfileController@index']);
Route::get('/products', ['as' => $a . 'products', 'uses' => 'ProfileController@products']);
Route::get('/payment', ['as' => $a . 'products', 'uses' => 'ProfileController@payment']);
Route::get('/profile/account/{id}', ['as' => $a . 'edit', 'uses' => 'ProfileController@edit']);
Route::patch('/profile/account/{id}', ['as' => $a . 'edit', 'uses' => 'ProfileController@update']);
});
Route::group(['prefix' => 'user', 'middleware' => 'auth:user'], function()
{
$a = 'user.';
Route::get('/', ['as' => $a . 'home', 'uses' => 'UserController@getHome']);
Route::get('/profile', ['as' => $a . 'profile', 'uses' => 'ProfileController@index']);
Route::get('/profile/account/{id}', ['as' => $a . 'edit', 'uses' => 'ProfileController@edit']);
Route::Patch('/profile/account/{id}', ['as' => $a . 'edit', 'uses' => 'ProfileController@update']);
});
管理员和用户共享同一个控制器ProfileController
。
谢谢!
使用路线而不是行动怎么样。
然后使用 if 语句在使用模型打开表单之前检查您的管理员或用户。
@if(admin)
{!! Form::model($user, ['method'=>'PATCH', 'route' => ['admin.edit', $user->id]]) !!}
@else
{!! Form::model($user, ['method'=>'PATCH', 'route' => ['user.edit', $user->id]]) !!}
不是最干净的,但解决了 url 表单应该指向的问题。使用 admin 作为占位符请公开您自己的变量。