Cloudinary Blog

Introducing Cloudinary’s New Laravel SDK

Introducing Cloudinary’s New Laravel SDK

Known far and wide as the “PHP framework for web artisans,” Laravel is a robust, expressive, and productive developer tool. In particular, it's clean, smooth, and fluent API interface greatly simplifies the process of embedding features in web apps.

Since its release in June 2011 by Taylor Otwell, a .NET developer turned PHP programmer, Laravel has garnered massive growth in usage, accolades, and largely positive critique from developers. As of now, Laravel has earned over 60,000 stars on GitHub with a total download of over 98 million. That’s a big deal!

laravel stats

Below are GitHub’s download statistics of five popular web frameworks tailored for trendy server-side programming languages:

No matter that those are vanity metrics, they undeniably illustrate the efficacy and reliability of Laravel’s superior developer experience.

This article shows the benefits and capabilities of the Laravel PHP framework and the way to upload to and transform files with Cloudinary with its new Laravel SDK. Here are the topics:

What Benefits Does Laravel Offer?

As do many other web frameworks, Laravel follows the Model-View-Controller pattern but also provides a Facade pattern, which accords access to several core capabilities. All that translates to an intuitive and fast start for you as developers. You’ll find yourself automatically memorizing the classes to import for various tasks.

Example: The facades below are interfaces for all major features, such as authentication, mail, notifications, caching, and file upload.

Facade Classes
App Illuminate\Support\Facades\App::class,
Arr Illuminate\Support\Arr::class,
Artisan Illuminate\Support\Facades\Artisan::class,
Auth Illuminate\Support\Facades\Auth::class,
Blade Illuminate\Support\Facades\Blade::class,
Broadcast Illuminate\Support\Facades\Broadcast::class,
Bus Illuminate\Support\Facades\Bus::class,
Cache Illuminate\Support\Facades\Cache::class,
Config Illuminate\Support\Facades\Config::class,
Cookie Illuminate\Support\Facades\Cookie::class,
Crypt Illuminate\Support\Facades\Crypt::class,
DB Illuminate\Support\Facades\DB::class,
Eloquent Illuminate\Database\Eloquent\Model::class,
Event Illuminate\Support\Facades\Event::class,

Here are more details.

Laravel makes available through abstraction the many similar building blocks required by web apps, freeing up developers to focus on business logic. Impressively, almost everything in Laravel is preconfigured out of the box.

Built-In Authentication and Authorization

Laravel offers authentication and authorization capabilities. To configure authentication for your app while installing Laravel, type:

Copy to clipboard
laravel new app --auth

That command line readies all the scaffolding you need for authentication to work. You can then customize it as desired by following the procedures in the documentation.

Caching

You must have tackled caching logic and strategies, headaches both, multiple times. The twists and turns involved in bursting caches and setting up the right storage are constant challenges.

Laravel comes with a caching capability along with drivers and integrations for Redis, Memcached, database, files, etc. Simply opt in and out of the drivers you would like to use from the environment file. Additionally, you can leverage the Cache facade and helper function for caching apps in your code base.

Blade Templating Engine

Blade, an unobtrusive templating engine, is available in Laravel. To fully take advantage of that engine, ensure that your view files end with the .blade.php extension.

You can write plain PHP code along with the default Blade syntax and components. Plus, caching is guaranteed with Blade, ensuring fast views for Laravel apps. Here’s an example of a Blade view:

Copy to clipboard
<body>
        <div class="flex-center position-ref full-height">
            @if (Route::has('login'))
                <div class="top-right links">
                    @auth
                        <a href="{{ url('/home') }}">Home</a>
                    @else
                        <a href="{{ route('login') }}">Login</a>

                        @if (Route::has('register'))
                            <a href="{{ route('register') }}">Register</a>
                        @endif
                    @endauth
                </div>
            @endif

            <div class="content">
                <div class="title m-b-md">
                    Laravel
                </div>
            </div>
        </div>
    </body>

Jobs and Queues

Building jobs and queues are a chore for novice developers. Even experienced programmers find those tasks laborious, let alone that the tasks might not work as expected. However, jobs can fail and, when they do, you must know when, how, and why, and ensure that they automatically retry.

The effective integration of jobs and queues in Laravel follows the convention over configuration paradigm. Just be sure to set up your workers and crontab files on the hosting platform. If you can’t do that, Laravel’s premier Forge hosting platform does it for you by default.

Forge, which currently hosts and manages over 330,000 web apps, is proven to be trustworthy and effective.

Eloquent Object-Relational Mapping (ORM)

Over 80 percent of web apps interact with a database, which requires SQL code for adding, updating, fetching, and deleting data from there. As web apps grow in size and complexity, so does the difficulty of writing and maintaining queries—exponentially. That means you must learn the multitude of SQL functions and query operations, which is hardly something to relish.

No need to do that with Laravel, however, which liberates you to work on tasks like business logic. Laravel’s built-in Eloquent ORM abstracts SQL away with reusable classes, functions, and relationship mechanisms—all the tools you need for performing intricate queries in your app.

Well-Established and Cohesive Developer Community

To me, Laravel’s developer community is the best out there, always helpful and supportive of other members. Below are the learning resources and packages Laravel’s developer community has built over the years.

  • Laracasts, a website that teaches you everything about Laravel.
  • Laravel IO, a community portal for problem solving and knowledge sharing among Laravel enthusiasts.
  • Laravel Daily, a website in which myriad tips and tricks are shared.
  • Packages and tools for integrating remarkable features outside the Laravel core into web apps. Popular examples are Graham Campbell, Spatie, Beyondcode, Jeffrey Way, and Taylor Otwell.

What Can You Do With Laravel?

You can build all web apps with Laravel: from one-page sites to content management systems (CMS) to forums, to e-commerce stores. Go to made with Laravel for a host of examples of apps and websites developed with Laravel.

The article Twenty-Five Popular Applications Built With Laravel is another informative reference.

How Do You Upload and Transform Files With Laravel on Cloudinary?

Laravel’s file system leverages the useful PHP Flysystem on GitHub along with an Amazon S3 and a local file-driver storage. Many Laravel developers have built drivers for external storage services.

With the newly released Laravel SDK from Cloudinary, you can efficiently upload, manipulate, optimize, and deliver files. For example, to upload and transform media files, code like this:

Copy to clipboard
 // Store the image on Cloudinary and return the secure URL
  request->file('image')->storeOnCloudinary()->getSecurePath();

Upload Files

Copy to clipboard
// Store the uploaded file in the "alarmanda" directory on Cloudinary
 $request->file('image')->store('alarmanda', 'cloudinary');

Upload Files to a Specific Directory

Copy to clipboard
cloudinary()->upload(
                $request->file('image')->getRealPath(), [
                'transformation' => [
                    'gravity' => 'auto',
                    'width' => 300,
                    'height' => 300,
                    'crop' => 'crop'
                ]
        ])->getSecurePath();

Upload and Transform a File Simultaneously

You can perform numerous other tasks with Cloudinary’s Laravel SDK: retrieving and displaying media in your app, attaching media to existing models, interacting with files on the console. Furthermore, the SDK contains helpful Blade UI components, ready for deployment.

Want to Learn More About Laravel?

Recent Blog Posts

Global Study Strengthens Case for Brands to Support UGC

However, along with the benefits of user-generated content (UGC), comes myriad technical challenges. Content must be moderated to avoid compromising your brand. You need to provide a user-friendly process to efficiently manage content uploads. You need to transform images and videos to ensure brand consistency and web performance. You also need to ensure they look presentable across all devices and browser environments. To help brands address these issues and more, we recently ran a three-part blog series on UGC.

Read more
Cloudinary Supports JPEG XL

Since its founding, Cloudinary's mission has been to help companies unleash the full potential of their media to create the most engaging visual experiences. In keeping with that quest, we support new codecs for images and videos as soon as possible.

Read more
WingTai Asia Fashions Efficient Media Management Workflow

WingTai Asia, a subsidiary of Wing Tai Holdings Limited, is an investment holding company that focuses on property investment and development, lifestyle retail, and hospitality management in key Asian markets. The company is a licensed distributor or sole license distributor for many brands, including Adidas, Cath Kidson, TopShop and UNIQLO, and operates brick and mortar shops to sell these goods throughout Singapore and Malaysia.

Read more