2016-10-22 64 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 
     ]) }}">