我目前正在处理Laravel-5.3中的图像上传。我的“个人资料页面”路由定义如下:
/* GET request to show the profile page */
Route::get('/{username}', [
'uses' => '\App\Http\Controllers\ProfileController@getProfile',
'as' => 'profile.index',
]);
/* POST request to update the Avatar (display pic) */
Route::post('/{username}', [
'uses' => '\App\Http\Controllers\ProfileController@updateAvatar',
'as' => 'profile.index',
]);因此,配置文件URL看起来很像example.com/john (让"john“作为用户名)
在表单中,我必须定义"action“。
<form enctype="multipart/form-data" action="" method="POST">如何在表单操作中定义路由,以便将用户重定向到他们各自的路由;类似于“example.com/john”。
我想我不能直接定义<form action="/{username}">,因为我将被带到example.com/{username}。
发布于 2016-10-22 16:24:58
如果你需要当前用户的路由,你可以这样做:
<form enctype="multipart/form-data" action="{{ url(Auth::user()->name) }}" method="POST">更新:对于命名路由,您可以使用route帮助器
<form enctype="multipart/form-data" action="{{ route('profile.index', ['username' => 'username_here']); }}" method="POST">发布于 2016-10-22 16:42:50
在命名路由时,可以使用该名称通过帮助器定义URL,并将参数数组作为第二个参数进行传递。
<form enctype="multipart/form-data"
method="POST"
action="{{ route('profile.index', [
'username' => Auth::user()->name
]) }}">https://stackoverflow.com/questions/40189915
复制相似问题