You mean make it optional?
Jun 16, 2015
9
Level 2
Remove subdomain parameter in Controllers?
Hi, I'm doing subdomain routing, and I wanna know if there is a way to avoid adding the first parameter, where the subdomain is stored?
public function find($path){
return $path;
}
# Output: 'subdomain name'
public function find($account, $path){
return $path;
}
#Output: correct path.
Route::group(['domain' => '{account}.mywebsite.com', 'middleware' => 'subdomain'], function () {
});
It's annoying to implement it for each existing Controller.
namespace App\Http\Middleware;
class SubdomainMiddleware
{
public function handle($request, Closure $next)
{
$subdomain = $request->route()->account;
if(! in_array($subdomain, config('app.websites'))) {
return abort(404);
}
// I'm doing some things for the subdomain over here
return $next($request);
}
}
Level 56
You can "forget" a route parameter ;)
class FooMiddleware
{
public function handle($request, Closure $next)
{
// ...
$request->route()->forgetParameter('account');
// ...
}
}
http://laravel.com/api/5.0/Illuminate/Routing/Route.html#method_forgetParameter
5 likes
Please or to participate in this conversation.