Radical Design Course by Jack McDade

From the creator of Statamic

Learn how to make your websites standout and be remembered.

Taking your approach on designing things actually makes it fun, more natural, and overall easier.

— Dominik, Developer

Site Repository

To work with the with Site Repository, use the following Facade:

use Statamic\Facades\Site;

Methods

Methods Description
all() Get all Sites
get($handle) Get Site by handle
findByUrl($url) Get site by a given URL
current() Returns the current site, determined by the current page URL.
setCurrent($handle) Sets the current site.
selected() Returns the site currently selected in the Control Panel
setSelected($handle) Sets the selected site.
default() Returns the "default site", which will be the first site in the sites config
authorized() Returns a collection of Site objects, where the user is authorized to view the site (see Multisite Permissions).
multiEnabled Returns a boolean indicating if multi-site is enabled.
hasMultiple() Returns a boolean indicating if multiple sites are configured.
setSites($sites) Accepts an array. Allows you to override the configured sites.

Resolving the current site

When you're using the Site::current() method, sometimes the current page URL will lead to the wrong site being returned (like when using Livewire). In this case, you can use the resolveCurrentUrlUsing to check against a different URL:

// app/Providers/AppServiceProvider.php
 
use Statamic\Facades\Site;
 
Site::resolveCurrentUrlUsing(fn () => Livewire::originalUrl());
HR: Section
Learn More!

There is more to learn more in these related articles:

Docs

HR: Section
Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →