带参数的参考路线 - Laravel / Lumen

时间:2016-02-18 19:06:32

标签: php laravel laravel-5 lumen

我有一条我声明的路线;

Route::get('invite/{code}', ['middleware' => ['qwickLoggedIn'], 'uses' =>'WebController@signup_invite'])->name('signup_invite');

如您所见,路线有一个参数{code} 如何使用routeurl

来引用路线

就像下面的代码一样?

public function account_verification () {

    $referer = Request::header('referer');

    if ($referer != url('login') && $referer != url('signup') && $referer != url('invite/{code}') && $referer != url('account-verification-code')) {
        return redirect()->route('/');
    }

    $year = $this->copyright_info('2015');
    return view('pages.account-verification', ['year' => $year]);
}

我把它作为$referer != url('invite/{code}'),但这不起作用。 $referer != url('invite')也不起作用......也使用route('signup_invite');

我收到错误UrlGenerationException in UrlGenerationException.php line 17: Missing required parameters for [Route: signup_invite] [URI: invite/{code}].

任何帮助表示赞赏

1 个答案:

答案 0 :(得分:0)

看起来很混乱,但您可以使用$referrer功能解析parse_url功能&然后为组件设置条件:

$referer = Request::header('referer');

$path = parse_url($referer, PHP_URL_PATH);
$path = explode( '/', $path );

if ($referer != url('login') && $referer != url('signup') && ( parse_url($referer, PHP_URL_HOST) == parse_url( url('/'), PHP_URL_HOST ) && $path[1] == 'invite' && !empty($path[2]) ) && $referer != url('account-verification-code')) {
    return redirect()->route('/');
}