Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting an error with sub domain routing in Laravel 4
    text
    copied!<p>Thanks for taking the time to read my post.</p> <p>I am currently trying to setup my Laravel 4 setup to work as a multi-tenant environment. I had checked the Laravel forums and i have followed a post that was made there by Wyred here is the link to the post <a href="http://forums.laravel.io/viewtopic.php?id=9315" rel="nofollow">http://forums.laravel.io/viewtopic.php?id=9315</a> . </p> <p>After following this post i have created the sub domain and it is sending the sub domain along to the routes correctly. When i log in i am sure i am authenticating against the tenant database because it allows me to log in with a username that is only created in the tenant database, but once it logs in ( I am using Zizaco's Confide for AUTH ) and redirects me to my controllers index i get an error that says </p> <p>Error:</p> <pre><code>Symfony \ Component \ Routing \ Exception \ MissingMandatoryParametersException Some mandatory parameters are missing ("subdomain") to generate a URL for route {subdomain}.recordsynergy.com get patient/index/{v1}/{v2}/{v3}/{v4}/{v5}". </code></pre> <p>I have looked to see what the issue is, but have not been able to find it. Inside the UrlGenerator.php i have dd() the values that throw this exception, but it shows the values of the subdomain. Now when i do a dd() before my getLogin Auth page it shows the subdomain as an array like this array('subdomain' => 'actual subdomain here'). When i do it in the controller for the index page it just shows str3(actual subdomain), but without an array. So i am not sure what the issue is. Hopefully with the code i paste someone would be able to help. Thanks! </p> <pre><code> Error: Symfony \ Component \ Routing \ Exception \ MissingMandatoryParametersException Some mandatory parameters are missing ("subdomain") to generate a URL for route "{subdomain}.recordsynergy.com get patient/index/{v1}/{v2}/{v3}/{v4}/{v5}". Symfony\Component\Routing\Exception\MissingMandatoryParametersException …/­vendor/­symfony/­routing/­Symfony/­Component/­Routing/­Generator/­UrlGenerator.php155 open: /var/www/recordsynergy/vendor/symfony/routing/Symfony/Component/Routing/Generator/UrlGenerator.php ~~~~~ Routes.php ~~~~~~ &lt;?php /* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the Closure to execute when that URI is requested. | Route::get('/', function() { return View::make('hello'); }); */ $subdomain = ''; $domain_parts = explode('.', Request::server('HTTP_HOST')); if (count($domain_parts) == 3) { $subdomain = $domain_parts[0]; if ($subdomain == 'www') { $subdomain = ''; } } if (empty($subdomain)) { //create routes meant for webapp.com or www. webapp.com Route::get('/','UserController@getLogin'); } else { //create routes meant for tenant.webapp.com Route::group(array('domain' =&gt; '{subdomain}.'.Config::get('app.domain'), 'before' =&gt; 'db.setup'), function() { //login, logout Route::get('/','UserController@getLogin'); ; }); //routes that require login //REMEMBER that the db.setup filter must be run first in order to change the database to the tenant's so that your sessions will be read from the correct database Route::group(array('domain' =&gt; '{subdomain}.'.Config::get('app.domain'), 'before' =&gt; 'db.setup|auth'), function() { Route::controller('patient','PatientController'); }); } Route::group(array('before' =&gt; 'force_ssl'), function() { Route::get('/','UserController@getLogin'); //Defining Controllers Route::controller('patient','PatientController'); Route::controller('user', 'UserController'); Route::controller('note', 'DailyNoteController'); Route::controller('eval', 'EvalController'); Route::controller('billing', 'BillingController'); Route::controller('insurance', 'InsuranceController'); //End Defining Controllers Route::get('/forgot', 'UserController@getForgot'); Route::get('/cpt', 'PatientController@getCpt'); //Route::get('user/confirm/{code}', 'UserController@getReset'); //Route::get('user/reset/{token}', 'UserController@getReset'); }); Route::when('patient*','auth'); Route::get('/icd9', 'PatientController@getJSON'); // Confide RESTful route //Route::controller( 'user', 'UserController');// Confide RESTful route ~~~~~~~~~~~~~ END Routes.php ~~~~~~~~~~~~~ ~~~~~~~~~~~~~~ Filters ~~~~~~~~~~~~~~~~ &lt;?php /* |-------------------------------------------------------------------------- | Application &amp; Route Filters | | Below you will find the "before" and "after" events for the application | which may be used to do any work before or after a request into your | application. Here you may also register your custom route filters. | */ App::before(function($request) { // }); App::after(function($request, $response) { // }); Route::filter('force_ssl', function() { if(!Request::secure()) { return Redirect::secure(Request::getRequestUri()); } }); Route::filter('db.setup', function($route, $request) { $host = $request-&gt;getHost(); $parts = explode('.', $host); $subdomain = $parts[0]; $tenant = Tenant::whereSubdomain($subdomain)-&gt;first(); $domain = Config::get('app.domain'); //unable to find tenant in database, redirect to myapp.com if ($tenant == null) return Redirect::to('http://'.Config::get('app.domain')); //set the default database connection to the tenant database Config::set('database.connections.mysql_tenant.database', 'RS_'.strtoupper($subdomain)); DB::setDefaultConnection('mysql_tenant'); }); /* |-------------------------------------------------------------------------- | Authentication Filters |-------------------------------------------------------------------------- | | The following filters are used to verify that the user of the current | session is logged into this application. The "basic" filter easily | integrates HTTP Basic authentication for quick, simple checking. | */ Route::filter('auth', function() { if (Auth::guest()) return Redirect::guest('/user/login'); }); Route::filter('auth.basic', function() { return Auth::basic(); }); /* |-------------------------------------------------------------------------- | Guest Filter |-------------------------------------------------------------------------- | | The "guest" filter is the counterpart of the authentication filters as | it simply checks that the current user is not logged in. A redirect | response will be issued if they are, which you may freely change. | */ Route::filter('guest', function() { if (Auth::check()) return Redirect::to('/'); }); /* |-------------------------------------------------------------------------- | CSRF Protection Filter |-------------------------------------------------------------------------- | | The CSRF filter is responsible for protecting your application against | cross-site request forgery attacks. If this special token in a user | session does not match the one given in this request, we'll bail. | */ Route::filter('csrf', function() { if (Session::token() != Input::get('_token')) { throw new Illuminate\Session\TokenMismatchException; } }); ~~~~~~~~~~~ END FILTERS ~~~~~~~~~~~~~ ~~~~~~~~~~User Controller Login Function ~~~~~~~~~~~~~ public function getLogin($subdomain) { $data['subdomain'] = $subdomain; if( Confide::user() ) { // If user is logged, redirect to internal // page, change it to '/admin', '/dashboard' or something return Redirect::action('PatientController@getIndex', $data); } else { return View::make(Config::get('confide::login_form'), $data); } } ~~~~~~~~~~~~~ End User Login Func ~~~~~~~~~~~~~~ ~~~~~~~~~~~~~ Patient Controller Get Index Function ~~~~~~~~~~~~~~ public function getIndex($subdomain) { $data['subdomain'] = $subdomain; return View::make('patients.index',$data) -&gt;with('patients', Patient::where('cc_id',Auth::user()-&gt;cc_id)-&gt;orderBy('last')-&gt;get()); } ~~~~~~~~~ End Patient Controller Get Index ~~~~~~~~~~~~~~ ~~~~~~~~~~~ Patient.Index View ~~~~~~~~~~~~~~~~~ @extends('layouts.default') @section('content') &lt;title&gt;Dashboard&lt;/title&gt; &lt;h1&gt;Patient Dashboard &lt;/h1&gt; &lt;table class="table table-striped"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Name&lt;/th&gt; &lt;/tr&gt; &lt;tbody&gt; @foreach($patients as $patient) &lt;tr&gt; &lt;?php if($patient-&gt;middle){ $name = $patient-&gt;last.", ". $patient-&gt;first." ".$patient-&gt;middle."."; }else{ $name = $patient-&gt;last.", ". $patient-&gt;first; }?&gt; &lt;td&gt;{{ HTML::linkAction('PatientController@getInfo',$name, array($patient-&gt;patients_id)) }} &lt;/td&gt; &lt;td&gt; &lt;ul class="unstyled inline" style="display:inline"&gt; &lt;li class="dropdown"&gt;&lt;a href="#" class="dropdown-toggle" data-toggle="dropdown"&gt;&lt;b class="icon-plus"&gt;&lt;/b&gt;&lt;/a&gt; &lt;ul class="dropdown-menu"&gt; &lt;li&gt;&lt;a href="{{ Action('EvalController@getNewEval', [$patient-&gt;patients_id]) }}"&gt;&lt;i class="icon-plus-sign"&gt;&lt;/i&gt; New Eval&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="{{ Action('DailyNoteController@getNewNote', [$patient-&gt;patients_id]) }}"&gt;&lt;i class="icon-plus-sign"&gt;&lt;/i&gt; New Note&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;a href="{{ Action('PatientController@getEdit', [$patient-&gt;patients_id]) }}" class="icon-edit"&gt;&lt;/a&gt; &lt;a href="{{ Action('PatientController@getDelete', [$patient-&gt;patients_id]) }}" class="icon-remove" onclick='return confirm("CONFIRM: Delete Patient?")'&gt;&lt;/a&gt; &lt;/td&gt; &lt;/tr&gt; @endforeach &lt;/tbody&gt; &lt;/table&gt; </code></pre> <p>@stop</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload