vendredi 21 juillet 2017

Laravel Route::group passing incorrect variables

I am having a very weird issue, I have setup a route group for wildcard subdomains and it is now passing the subdomain variable through to my controllers instead of the correct variable;

Route::group(['domain' => '{subdomain}.website.co.uk', 'middleware' => 'custom'], function() {  
    Route::group(['middleware' => 'auth'], function(){
        Route::get('/customer/view/{customerID}', 'CustomerController@viewCustomer');
    });
});

I then try and load /customer/view/20 and the data that is displayed is the subdomain and not 20

public function viewCustomer($customerID){
    dd($customerID);
}

I cannot see why the {subdomain} from the route group is being passed to all of my controller functions instead of in this case {customerID}

The 'custom' middleware is the below, just in case this is causing it;

namespace App\Http\Middleware;

use Closure;
use App\Whitelabel;

class Custom
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if($request->route('account') != 'my'){
            if(\Cookie::get('sub_domain') == NULL || \Cookie::get('sub_domain') != $request->route('account')) {

                $whitelabel = Whitelabel::where('subdomain', '=', $request->route('account'))->first();

                if($whitelabel){   
                    \Cookie::queue('sub_domain', $request->route('account'), 43200);
                    \Cookie::queue('reseller_name', $whitelabel->reseller_name, 43200);
                    \Cookie::queue('reseller_logo', $whitelabel->logo_url, 43200);
                    \Cookie::queue('reseller_colour', $whitelabel->custom_colour, 43200);
                    \Cookie::queue('top_bar_colour', $whitelabel->top_bar_colour, 43200);
                }else{
                    \Cookie::queue(\Cookie::forget('sub_domain'));
                    \Cookie::queue(\Cookie::forget('reseller_name'));
                    \Cookie::queue(\Cookie::forget('reseller_logo'));
                    \Cookie::queue(\Cookie::forget('reseller_colour'));
                    \Cookie::queue(\Cookie::forget('top_bar_colour'));
                    return \Redirect::to('http://ift.tt/2tn9Kbh'.$request->path());
                } 

            }
        }else{
            \Cookie::queue(\Cookie::forget('sub_domain'));
            \Cookie::queue(\Cookie::forget('reseller_name'));
            \Cookie::queue(\Cookie::forget('reseller_logo'));
            \Cookie::queue(\Cookie::forget('reseller_colour'));
            \Cookie::queue(\Cookie::forget('top_bar_colour'));
        }

        return $next($request);
    }
}

This is just used to set the white-label color scheme and logo.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire