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

On-Demand Viewing of Live Video Presents New Opportunities

In early 2020, Cloudinary was planning its fourth annual ImageCon conference, a two-day event in the heart of San Francisco, where we’d congregate with curious digital-media minds to brainstorm best practices for media management. Instead, the COVID-19 pandemic forced the entirety of ImageCon 2020 online. As with all other events being planned, we had to overhaul the content to be communicated on video. Gratifyingly, we found the right partner—the event platform Bizzabo—to turn that into a reality.

Read more
Why the Future of E-commerce Is Live

In a previous post, I discussed how “going live” is gaining popularity across industries and verticals. What began as a way for gamers to jam together has evolved into a medium for broader entertainment and business purposes. To continue the conversation, this post unpacks the current trends of shoppable live streams to shine a light on how brands are leveraging “lives” to connect with shoppers in new ways.

Read more
An Overview of Live-Streaming Video Trends

“Let’s go live.” For decades, that’s what newscasters say as they cut to real-time footage of a colleague reporting in the field. The live-video feed adds visual interest and perspective to a story beyond what can be communicated by someone sitting behind the news desk. In the same way, live-streaming video nowadays adds context to other consumer environments. From gaming and events to shopping and social media, “going live” enhances everyday experiences, and it’s something anyone can do with relative ease.

Read more
Readying Live Streams for Video on Demand

When planning a live broadcast or stream, companies often overlook the redistribution phase, but live-stream videos are useful well beyond their initial streaming. Why? Because not everyone watches the first run. For a wider audience, it makes sense to repost live content on your website under an “events” tab, on YouTube, and other social sites for video on demand (VOD). However, preparing footage for reposting can be a lot of work.

Read more