Bonjour,

Voila je rencontre un petit problème avec mon code.
Je souhaite avoir un prefixe dynamique pour toute mes routes.
En gros je souhaite avoir 2 fronts et un back.
J'utiliserai les memes vues quasiment
Ca doit donner ca:

localhost/admin
localhost/front1
localhost/front2 

Ce que je fais

Décrivez ici votre code ou ce que vous cherchez à faire

app\Providers\RouteServiceProvider.php

public function boot() 
{ 
    parent::boot(); 
    Route::bind('brand', function ($value) { 
        return Brand::where('slug', $value)->first() ?? abort(404); 
    }); 
} 

app\Providers\RouteServiceProvider.php

public function boot() 
{ 
    parent::boot(); 
    Route::bind('brand', function ($value) { 
        return Brand::where('slug', $value)->first() ?? abort(404); 
    }); 
} 
routes/web.php

use Illuminate\Support\Facades\Auth;
use \App\Brand;

Route::get('/' , 'HomeController@index')->name('main');

/*Back*/
Route::group([
    'prefix' => 'admin'
], function () {
    Route::get('/' , 'AdminController@index')->name('admin.home');
    AuthRoutes();
});

/*Front*/
Route::group([
    'prefix' => '{brand}'
], function () {
    Route::get('/' , 'BrandsLandingController@index')->name('main_landing');
    AuthRoutes();
});

function AuthRoutes()
{
    Route::get('login', 'Auth\LoginController@showLoginForm')->name('login');
    Route::post('login', 'Auth\LoginController@login');
    Route::post('logout', 'Auth\LoginController@logout')->name('logout');
    Route::get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
    Route::post('register', 'Auth\RegisterController@register');
    Route::get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');
    Route::post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');
    Route::get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm')->name('password.reset');
    Route::post('password/reset', 'Auth\ResetPasswordController@reset')->name('password.update');
    Route::get('email/verify', 'Auth\VerificationController@show')->name('verification.notice');
    Route::get('email/verify/{id}', 'Auth\VerificationController@verify')->name('verification.verify');
    Route::get('email/resend', 'Auth\VerificationController@resend')->name('verification.resend');
}

AdminController.php

    public function index()
    {
        return view('layouts.app');
    }

BrandsLandingController.php
    public function index()
    {
        return view('layouts.app');
    }

Liste de routes: 
|        | GET|HEAD | /                              | main                  | App\Http\Controllers\HomeController@index                              | web                                                  |
|        | GET|HEAD | admin                          | admin.home            | App\Http\Controllers\AdminController@index                             | web                                                  |
|        | GET|HEAD | admin/email/resend             | verification.resend   | App\Http\Controllers\Auth\VerificationController@resend                | web,auth,throttle:6,1                                |
|        | GET|HEAD | admin/email/verify             | verification.notice   | App\Http\Controllers\Auth\VerificationController@show                  | web,auth                                             |
|        | GET|HEAD | admin/email/verify/{id}        | verification.verify   | App\Http\Controllers\Auth\VerificationController@verify                | web,auth,signed,throttle:6,1                         |
|        | GET|HEAD | admin/login                    | login                 | App\Http\Controllers\Auth\LoginController@showLoginForm                | web,guest                                            |
|        | POST     | admin/login                    |                       | App\Http\Controllers\Auth\LoginController@login                        | web,guest                                            |
|        | POST     | admin/logout                   | logout                | App\Http\Controllers\Auth\LoginController@logout                       | web                                                  |
|        | POST     | admin/password/email           | password.email        | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail  | web,guest                                            |
|        | POST     | admin/password/reset           | password.update       | App\Http\Controllers\Auth\ResetPasswordController@reset                | web,guest                                            |
|        | GET|HEAD | admin/password/reset           | password.request      | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest                                            |
|        | GET|HEAD | admin/password/reset/{token}   | password.reset        | App\Http\Controllers\Auth\ResetPasswordController@showResetForm        | web,guest                                            |
|        | POST     | admin/register                 |                       | App\Http\Controllers\Auth\RegisterController@register                  | web,guest                                            |
|        | GET|HEAD | admin/register                 | register              | App\Http\Controllers\Auth\RegisterController@showRegistrationForm      | web,guest                                            |
|        | GET|HEAD | api/user                       |                       | Closure                                                                | api,auth:api                                         |
|        | GET|HEAD | {brand}                        | main_landing          | App\Http\Controllers\BrandsLandingController@index                     | web                                                  |
|        | GET|HEAD | {brand}/email/resend           | verification.resend   | App\Http\Controllers\Auth\VerificationController@resend                | web,auth,throttle:6,1                                |
|        | GET|HEAD | {brand}/email/verify           | verification.notice   | App\Http\Controllers\Auth\VerificationController@show                  | web,auth                                             |
|        | GET|HEAD | {brand}/email/verify/{id}      | verification.verify   | App\Http\Controllers\Auth\VerificationController@verify                | web,auth,signed,throttle:6,1                         |
|        | POST     | {brand}/login                  |                       | App\Http\Controllers\Auth\LoginController@login                        | web,guest                                            |
|        | GET|HEAD | {brand}/login                  | login                 | App\Http\Controllers\Auth\LoginController@showLoginForm                | web,guest                                            |
|        | POST     | {brand}/logout                 | logout                | App\Http\Controllers\Auth\LoginController@logout                       | web                                                  |
|        | POST     | {brand}/password/email         | password.email        | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail  | web,guest                                            |
|        | GET|HEAD | {brand}/password/reset         | password.request      | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest                                            |
|        | POST     | {brand}/password/reset         | password.update       | App\Http\Controllers\Auth\ResetPasswordController@reset                | web,guest                                            |
|        | GET|HEAD | {brand}/password/reset/{token} | password.reset        | App\Http\Controllers\Auth\ResetPasswordController@showResetForm        | web,guest                                            |
|        | POST     | {brand}/register               |                       | App\Http\Controllers\Auth\RegisterController@register                  | web,guest                                            |
|        | GET|HEAD | {brand}/register               | register              | App\Http\Controllers\Auth\RegisterController@showRegistrationForm      | web,guest                                            |

Ce que je veux

  • Ne plus avoir d'erreurs :)

  • Pouvoir differencier mes routes :

    <a href="{{ route($prefix->slug . 'login') }}">Login </a>

    $prefix etant l'objet contenant les donnees selon le prefixe que j'ai en URL

Ce que j'obtiens

  • Lorsque je vais sur la page localhost/front1/login , j'ai cette erreur :
Missing required parameters for [Route: login] [URI: {brand}/login]. (View: F:\StockageUnit2\Developpement\projets\billetterie\resources\views\auth\login.blade
  • Sur mes templates, comment je peux faire la difference entre chaque route ?

Merci d'avance

2 réponses


Tu as trouvé la solution ? Je suis très interessé par ce sujet !

Bonjour,

c'est typiquement le boulot d'un middleware.