$tenant = Tenant::whereSlug($subdomain)->first() ?: abort(404);

can be changed to:

$tenant = Tenant::whereSlug($subdomain)->firstOrFail();

Same effect.

Also, the use of whereSlug is a magic function, making it x3 times slower (check some benchmarks) than native function call. So let’s address this by using the following:

$tenant = Tenant::where('slug', $subdomain)->firstOrFail();

    Èrik Campobadal Forés

    Written by

    ICT systems engineer. Future master in web design and development. Open source contributor & open source packages creator / maintainer.