Sub-domain “Profiles” in Laravel

https://motorpress.co.za/
https://vw.motorpress.co.za/
https://audi.motorpress.co.za/
https://toyota.motorpress.co.za/

The database

A simple `CreateOrganisationsTable` migration

Generating slugs automatically

The `SlugService` class
(new SlugService())->uniqueSlug($organisation, 'title', 'slug');
static::creating(function (Organisation $organisation) {
$organisation->slug = $organisation->slug ?:
(new SlugService())->uniqueSlug($organisation);
});

Dealing with the request

php ./artisan make:middleware SetCompanyProfile
return substr(
config('app.url'),
strrpos(config('app.url'), '://www') +7);

The middleware

The `SetOrganisationProfile` middleware
'web' => [
\App\Http\Middleware\SetOrganisationProfile::class
],

Facades

The `Profile` facade
public function register()
{
$this->app->bind('profile', function ($app) {
return new ProfileService();
});
}
use App\Support\Facades\Profile;...$profile = Profile::getProfileOrganisation();

Where to from here

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store