puffy
643
11
Laravel

How can i set Auth::routes() with a dynamic subdomain

Posted 2 years ago by puffy

I use Laravel 5.4 and i try to develop an app with dynamic subdomain as users.

routes/web.php

Route::pattern('domain', 'www.localhost.dev|localhost.dev');
Route::group(['domain' => '{domain}'], function()
{
    Route::get('/', function()
    {
          return view('welcome');
    });
});

Route::group(['domain' => '{company}.localhost.dev', 'middleware' => 'CheckCompany'], function()
{ 
    Auth::routes();
    Route::get('/', function($company)
    {
          return view('welcome', compact('company'));
    });
    Route::get('/home', '[email protected]');
  
});

middleware/CheckCompany.php

namespace App\Http\Middleware;
use App\Company;
use Closure;
use Session;

class CheckCompany
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $CompanyUsername = $request->route('company');
        $organisation = Company::where('username', '=', $CompanyUsername)->first();
        if($organisation)
        {
            Session::put('company', $organisation);
            return $next($request);
        } else {
            return response()->view('errors.nouser', compact('CompanyUsername'));
        }
        
    }
}

I need to use /authroutes only if checkcompany is passed. i recive next error on existinguser.localhost.dev/login is accessed

ErrorException in UrlGenerationException.php line 17:
Missing required parameters for [Route: login] [URI: login]. (View: /Users/Web/laravel/devapp/resources/views/auth/login.blade.php)

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.