mercredi 29 mars 2017

Generating URL specific routes in a multi-URL Laravel application

I have multiple URLs going to a single Laravel application:

  • www.mydomain.com
  • panel.mydomain.com

Within this I have several routes configured:

<?php
Route::group(['middleware' => ['web']], function () {
    Route::get('/page', 'App\MyApp\Page\Controllers\PageController@index')->name('home');
});

Route::group(['middleware' => ['web'], 'domain' => 'panel.mydomain.com'], function() {
    Route::get('/page', 'App\MyApp\Page\Controllers\ControlPanelPageController@index')->name('controlpanel.dashboard');

});

So anyone going on panel.mydomain.com gets a ControlPanelPageController index method, everyone else gets the PageController method.

However I'm having difficulty generating a link from a named route.

For example:

<?php
namespace App\MyApp\Page\Controllers;
use App\Http\Controllers\Controller;

class ControlPanelPageController extends Controller 
{
    public function index()
    {
        echo route('home');
        // output: /page
        echo url( route('home') );
        // output: http://ift.tt/2nx65pb

        // required output: http://ift.tt/1G4ROBG
    }


}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire