• Network Status
  • Knowledge Base
  • Homepage
  • support@blazingcdn.com
  • Network Status
  • Knowledge Base
  • Homepage
  • support@blazingcdn.com

BlazingCDN integration with Laravel 

98 views 0

Written by Grzegorz Wiosna-Zieliński
January 19, 2021

Laravel is another framework that is used to create web applications. It was made using the PHP language using the Model-View-Controller architectural pattern. To go through the process safely and smoothly, it is worth taking a few security measures. Prepare a CDN domain in BlazingCDN Static. Moreover, if you intend to use the HTTPS protocol, secure it additionally with SSL. Don’t forget to back up your resources and database. If you are using custom fonts, also run CORS.

How to integrate BlazingCDN and Laravel? Enable Laravel and define CDN in config. Then add the code in Laravela’s /config/app.php file:

<?php

return [
…
‘cdn_enabled’   => true,
‘cdn_domain’    => ‘cdn00000000.blazingcdn.net’,
‘cdn_protocol’  => ‘http’,
];

Create a CDN helper via app / helpers.php with the following content

<?php

function cdn($url = null)
{
    $url = (string) $url;
    if(empty($url))
    {
        throw new Exception(‘URL missing’);
    }

    $pattern = ‘|^http[s]{0,1}://|i’;        
    if(preg_match($pattern, $url))
    {
        throw new Exception(‘Invalid URL. ‘ .
            ‘Use: /image.jpeg instead of full URI: ‘ .
            ‘http://domain.com/image.jpeg.’
        );
    }
        

    $pattern = ‘|^/|’;        
    if(!preg_match($pattern, $url))
    {
        $url = ‘/’ . $url;
    }

    if(!Config::get(‘app.cdn_enabled’))
    {
        return $url;
    }
    else
    {
        return Config::get(‘app.cdn_protocol’) . ‘://’ . Config::get(‘app.cdn_domain’) . $url;
    }    
}   

Update the autoloader by adding the autoload key to Laravel in composer.json:

…
“autoload”: {
    “classmap”: [
      …
     ],
     …
     “files”: [
         “app/helpers.php”
     ]
},

…Finally, the helper views:

{{ cdn(‘/image.jpeg’) }}

which will output:

http://cdn00000000.blazingcdn.net/image.jpeg

See also:

How to integrate BlazingCDN and Magneto
How to integrate BlazingCDN and Joomla 
How to integrate BlazingCDN and Drupal
BlazingCDN integration with Zend 
BlazingCDN integration with XenForo
BlazingCDN integration with X-Cart
BlazingCDN integration with WordPress
BlazingCDN  integration with vBulletin
BlazingCDN integration with Typo3
BlazingCDN integration with Symfony 
BlazingCDN integration with SocialEngine 
BlazingCDN integration with Shopware
BlazingCDN integration with PrestaShop
BlazingCDN integration with Phalcon 
BlazingCDN integration with Perch
BlazingCDN integration with Opencart
BlazingCDN integration with Odoo
BlazingCDN integration with MODX CDN
BlazingCDN integration with Kirby CDN 
BlazingCDN integration with Kentico 
BlazingCDN integration with IPS
BlazingCDN integration with Grav
BlazingCDN integration with Discourse
BlazingCDN  integration with Craft
BlazingCDN integration with concrete5
BlazingCDN  integration with CodeIgniter
BlazingCDN integration with b2evolution 
BlaizngCDN integration with Ruby on Rails

Was this helpful?

Yes  No
Leave A Comment Cancel reply

Integrations

  • BlazingCDN integration with Laravel 
  • Connection to KVS
  • BlazingCDN  integration with CodeIgniter
  • BlazingCDN integration with Phalcon 
  • BlazingCDN integration with Symfony 
  • BlazingCDN integration with Zend 
View All 30  

Popular Articles

  • How to create account on BlazingCDN?
  • How do I pay for BlazingCDN service?
  • BlazingCDN integration with WordPress
  • How to add new Pull zone?
  • What is Anycast CDN?

KB Categories

  • Account Settings
  • API
  • Billing
  • CDN Static
  • Copyright & Legal
  • Get Started
  • Integrations
  • Other
  • Storage
  • Tools
  • Privacy Policy
  • Terms of Use
  • © 2022 BlazingCDN. All Rights Reserved.

Popular Search:Getting Started