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.

Recent Blog Posts

Image-Editing Basics and a Tutorial for Automation With AI

You likely find yourself continually editing images for enhancement by eliminating flaws and tweaking the overall presentation, typically with software tools. Examples of basic editing are straightening, cleaning, and cropping images, as well as adjusting the contrast, exposure, and white balance. With advanced software like Cloudinary, you can automate not only editing tasks, such as quality adjustment and encoding, but also delivery.

Read more
Tips for Retaining Audience Through Engaging Videos

Measuring the level of interest your videos generate helps you produce compelling content. The measurement and optimization approach must, however, address the various aspects of each video, including the A/B test hypothesis and iterations. A high engagement rate spells effective videos; a low engagement rate calls for content improvement.

Read more
Forbes Cloud 100: When the Stars Align

In 2017, when Cloudinary first made the Forbes Cloud 100 as a ‘Rising Star,’ it was an incredibly proud moment for the company. In 2018 we graduated from Rising Star status to be acknowledged as part of the incredible Cloud 100, the top 100 SaaS companies in the world. Today marks our third consecutive year on this prestigious list.

Read more
A Cloudinary-Enhanced Student-ID App

I’m an instructional designer on Cloudinary’s Solutions and Training team. As the COVID-19 pandemic emerged in March, like other global organizations, we pivoted to set up virtual courses. As much as we looked forward to resuming in-person classes in the future, we switched gear to focus on the virtual way of learning.

Read more
Image Formats: Getting it Right

Image formats, which are standards for digital images, can be uncompressed, compressed, raster based, or vector based. You determine the DNA of your images with the formats you adopt, each of which offering different capabilities. For example, rasters generate images with pixels; vectors, with vectors or proportional formulas. PNGs can display logos without background; JPEGs always come with backgrounds. This article explains the main properties of the various image formats, including their basic concepts and pros and cons.

Read more