Search code examples
octobercmsoctobercms-backend

Check if we in backend area of October CMS


In some places of my code I need to check if it's a backend area or a public page. I wrote a simple function in my Utils class.

    static public function isInBackend()
    {
        return (strpos(Url::current(), Config::get('cms.backendUri', 'backend')) !== false);
    }

Does anyone know better ways to check that?


Solution

  • It's very easy in OctoberCMS to check whether you are in backend or not; just see below code for that:

    if(\App::runningInBackend()) {
        //write your code here
    }
    

    You can learn more from this documentation link: https://octobercms.com/docs/services/application#application-helpers