我有一个非常奇怪的问题,我已经为通配符子域设置了一个路由组,它现在将子域变量传递给我的控制器而不是正确的变量;
Route::group(['domain' => '{subdomain}.website.co.uk', 'middleware' => 'custom'], function() {
Route::group(['middleware' => 'auth'], function(){
Route::get('/customer/view/{customerID}', 'CustomerController@viewCustomer');
});
});
然后我尝试加载/ customer / view / 20,显示的数据是子域而不是20
public function viewCustomer($customerID){
dd($customerID);
}
我看不出为什么来自路由组的{subdomain}被传递给我的所有控制器函数而不是在这种情况下{customerID}
'定制'中间件如下所示,以防万一造成它;
namespace App\Http\Middleware;
use Closure;
use App\Whitelabel;
class Custom
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if($request->route('account') != 'my'){
if(\Cookie::get('sub_domain') == NULL || \Cookie::get('sub_domain') != $request->route('account')) {
$whitelabel = Whitelabel::where('subdomain', '=', $request->route('account'))->first();
if($whitelabel){
\Cookie::queue('sub_domain', $request->route('account'), 43200);
\Cookie::queue('reseller_name', $whitelabel->reseller_name, 43200);
\Cookie::queue('reseller_logo', $whitelabel->logo_url, 43200);
\Cookie::queue('reseller_colour', $whitelabel->custom_colour, 43200);
\Cookie::queue('top_bar_colour', $whitelabel->top_bar_colour, 43200);
}else{
\Cookie::queue(\Cookie::forget('sub_domain'));
\Cookie::queue(\Cookie::forget('reseller_name'));
\Cookie::queue(\Cookie::forget('reseller_logo'));
\Cookie::queue(\Cookie::forget('reseller_colour'));
\Cookie::queue(\Cookie::forget('top_bar_colour'));
return \Redirect::to('http://my.website.co.uk/'.$request->path());
}
}
}else{
\Cookie::queue(\Cookie::forget('sub_domain'));
\Cookie::queue(\Cookie::forget('reseller_name'));
\Cookie::queue(\Cookie::forget('reseller_logo'));
\Cookie::queue(\Cookie::forget('reseller_colour'));
\Cookie::queue(\Cookie::forget('top_bar_colour'));
}
return $next($request);
}
}
这仅用于设置白标颜色方案和徽标。
答案 0 :(得分:2)
您在路线中定义了两个参数:subdomain
和customerID
。这意味着controller方法中的第一个参数将包含subdomain
值,而第二个参数将包含customerID
值。
因此,相应地改变方法:
public function viewCustomer($subdomain, $customerID) {
...
}