2016-10-22 67 views
0

我目前正在处理Laravel-5.3中的图像上传。 我的“个人资料页”的路线被定义为:Laravel路径/ {用户名}形式动作

/* GET request to show the profile page */ 

Route::get('/{username}', [ 
    'uses' => '\App\Http\Controllers\[email protected]', 
    'as' => 'profile.index', 

]); 

/* POST request to update the Avatar (display pic) */ 

Route::post('/{username}', [ 
    'uses' => '\App\Http\Controllers\[email protected]', 
    'as' => 'profile.index', 
]); 

因此,个人资料网址相当多的样子example.com/john(让“约翰”是用户名)

在形式,虽然,我必须定义那个行动”。

<form enctype="multipart/form-data" action="" method="POST"> 

如何在表单动作中定义路由,以便用户重定向到各自的路由;像“example.com/john”。

我想我不能直接定义<form action="/{username}">,因为我会将其带到example.com/{username}

+0

您有2条路线具有相同的路由名称。 – Ruffles

回答

0

如果您需要为当前用户的路线,你可以这样做:

<form enctype="multipart/form-data" action="{{ url(Auth::user()->name) }}" method="POST"> 

UPD:名为路线,你可以使用route帮手

<form enctype="multipart/form-data" action="{{ route('profile.index', ['username' => 'username_here']); }}" method="POST"> 
0

如你命名的路线,你可以使用该名称通过route()帮助程序定义URL,传递一组参数作为第二个参数。

<form enctype="multipart/form-data" 
     method="POST" 
     action="{{ route('profile.index', [ 
      'username' => Auth::user()->name 
     ]) }}">