Cloudinary Blog

Introducing Cloudinary’s New Laravel SDK

By
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

Our $2B Valuation

By
Blackstone Growth Invests in Cloudinary

When we started our journey in 2012, we were looking to improve our lives as developers by making it easier for us to handle the arduous tasks of handling images and videos in our code. That initial line of developer code has evolved into a full suite of media experience solutions driven by a mission that gradually revealed itself over the course of the past 10 years: help companies unleash the full potential of their media to create the most engaging visual experiences.

Read more
Direct-to-Consumer E-Commerce Requires Compelling Visual Experiences

When brands like you adopt a direct–to-consumer (DTC) e-commerce approach with no involvement of retailers or marketplaces, you gain direct and timely insight into evolving shopping behaviors. Accordingly, you can accommodate shoppers’ preferences by continually adjusting your product offering and interspersing the shopping journey with moments of excitement and intrigue. Opportunities abound for you to cultivate engaging customer relationships.

Read more
Automatically Translating Videos for an International Audience

No matter your business focus—public service, B2B integration, recruitment—multimedia, in particular video, is remarkably effective in communicating with the audience. Before, making video accessible to diverse viewers involved tasks galore, such as eliciting the service of production studios to manually dub, transcribe, and add subtitles. Those operations were costly and slow, especially for globally destined content.

Read more
Cloudinary Helps Minted Manage Its Image-Generation Pipeline at Scale

Shoppers return time and again to Minted’s global online community of independent artists and designers because they know they can count on unique, statement-making products of the highest quality there. Concurrently, the visual imagery on Minted.com must do justice to the designs into which the creators have poured their hearts and souls. For Minted’s VP of Engineering David Lien, “Because we are a premium brand, we need to ensure that every single one of our product images matches the selected configuration exactly. For example, if you pick an 18x24 art print on blue canvas, we will show that exact combination on the hero images in the PDF.”

Read more
Highlights on ImageCon 2021 and a Preview of ImageCon 2022

New year, same trend! Visual media will continue to play a monumental role in driving online conversions. To keep up with visual-experience trends and best practices, Cloudinary holds an annual conference called ImageCon, a one-of-a-kind event that helps attendees create the most engaging visual experiences possible.

Read more