Sub-domain “Profiles” in Laravel

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(
strrpos(config('app.url'), '://www') +7);

The middleware

The `SetOrganisationProfile` middleware
'web' => [


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