Zinq zinq

Blog

Posts: Articles and tutorials to help you with your projects

February 25, 2025
Upgrading to Laravel 12 - what you need to know

Today we're diving into a topic that will eventually affect all of us - upgrading our framework to the latest version. Laravel 12 is now available, so it's time to look at the migration process from version 11.

Good News - no revolution!

First, let me reassure you - moving from Laravel 11 to Laravel 12 isn't a revolutionary change. The Laravel team continues their philosophy of evolving the framework gradually, making the upgrade process relatively simple and painless.

Two Upgrade Paths

As always, we have two options to choose from:

  1. Laravel Shift - If you prefer a more automated approach, Laravel Shift remains an excellent tool that will do most of the work for you,
  2. Manual Upgrade - Personally, I recommend this option as it helps you better understand the changes and gives you complete control over the process. Additionally, it's a good opportunity to refactor certain parts of your code.

Free Compatibility Checker

Before you start, LLaravel Shift offers a free tool where you can check if your project is ready for Laravel 12. Simply copy your composer.json and paste it into their tool to see if all your packages already support Laravel 12: Can I Upgrade Laravel?

This can save you a lot of time by identifying potential compatibility issues before you begin the upgrade process.

Key Changes in Laravel 12

Before starting the upgrade process, it's worth familiarizing yourself with the official documentation: Laravel 12.x Upgrade Guide.

Most Significant Change: Carbon 3.x

The most notable change in Laravel 12 is the removal of backward compatibility for Carbon 2.x. If you use Carbon 2.x functions in your projects, you'll need to refactor your code to Carbon 3.x.

For example, if you have something like this in your code:

 
// Carbon 2.x - won't work in Laravel 12
$date = Carbon::now();
$formattedDate = $date->formatLocalized('%A %d %B %Y');

You'll need to update it to:

 
// Carbon 3.x - compatible with Laravel 12
$date = Carbon::now();
$formattedDate = $date->translatedFormat('l d F Y');

Step by Step - The Upgrade Process

Here's how you can perform the upgrade manually:

  1. Update dependencies in composer.json :
 
{
    "require": {
        "php": "^8.3",
        "laravel/framework": "^12.0"
    }
}
  1. Update packages:
 
composer update
  1. Migrate Carbon code:
  • Identify all places where you use Carbon 2.x
  • Change them according to Carbon 3.x documentation
  1. Test your application
  • Run unit tests
  • Check the functionality of key features
  • Pay special attention to date manipulation

Summary

Upgrading to Laravel 12 shouldn't be a painful process. The lack of revolutionary changes means we can enjoy new features without having to completely rebuild our applications.

As always, I recommend a gradual approach:

  1. First, update smaller projects
  2. Gain experience with the new features
  3. Then move on to updating larger, more critical applications

Good luck with your upgrade!

February 5, 2025
Keep your Laravel dependencies up to date

In the world of PHP and Laravel, keeping your dependencies up to date is crucial for security, performance, and compatibility. Fortunately, composer provides powerful tools to help you manage package updates.

Checking outdated packages - composer outdated

If you don’t want to update everything at once, you can first check which packages are outdated:

 
composer outdated

This command displays a list of outdated packages in a structured table, highlighting:

  • Patch and minor updates (e.g., 10.2.1 → 10.2.5) – marked in yellow
  • Major updates (e.g., 10.x → 11.x) – marked in red

Additionally, Composer distinguishes between:

  • Direct dependencies - packages explicitly declared in your composer.json
  • Transitive dependencies - packages required by other libraries but not listed directly in your composer.json

To see only outdated packages that you have explicitly installed, run:

 
composer outdated --direct

Security Audit - composer audit

Beyond just updating, you should also check for known security vulnerabilities:

 
composer audit

This command scans your dependencies against a database of known vulnerabilities and informs you if any packages need urgent updates due to security risks.

Updating Dependencies - composer update

The simplest way to update all dependencies/packages in Laravel project is:

 
composer update

This command updates all packages according to the constraints defined in your composer.json . For example, if your file contains:

 
"laravel/framework": "^10.0"

Composer will update Laravel to the latest 10.x version but will not upgrade to 11.x.

Updating a specific package

If you only want to update a single package in Laravel project instead of all dependencies, use:

 
composer update vendor/package-name

For example, to update only Laravel’s HTTP client:

 
composer update laravel/framework

If you want to update a package along with its dependencies, use the --with-dependencies flag:

 
composer update vendor/package-name --with-dependencies

You can also allow major version upgrades by modifying composer.json and then running:

 
composer require vendor/package-name:^NEW_VERSION

For example, upgrading guzzlehttp/guzzle to version 8:

 
composer require guzzlehttp/guzzle:^8.0

Final thoughts

Regularly updating your dependencies helps keep your Laravel project secure and up to date. Even if you can’t upgrade to the latest Laravel version immediately, monitoring outdated and vulnerable dependencies should be a routine practice.

January 31, 2025
How to use Blade section directive in Livewire Volt

When creating full page components in Livewire, you typically return view that extends given layout and injects content in specific section:

 
return view('livewire.welcome')
    ->extends('layouts.landing')
    ->section('content');

But how to inject your content into specific section using Volt? Official Livewire Volt documentation does not include instruction how to use Blade section directive in Volt.

Blade section directive usage in Livewire Volt

If you want to inject specific content in given section in Laravel Blade using Volt you need to use @section directive directly in your Livewire Volt component:

 
<?php

use Illuminate\Http\Request;
use function Livewire\Volt\{layout};

layout('layouts.application');

?>


<div>
    @section('content')
        <!-- Your content goes here -->
    @endsection
</div>

It is important to wrap your Volt component content with <div>...</div> . Then you can use @section directive.

Multiple Blade section directives in Livewire Volt

This also works if you have many @yield directives in your layout:

 
<?php

use Illuminate\Http\Request;
use function Livewire\Volt\{layout};

layout('layouts.application');

?>


<div>
    @section('header', 'Dashboard')

    @section('content')
        <!-- Your content goes here -->
    @endsection
</div>

This also works with other Laravel Blade directives, like:

  • @push
  • @pushOnce

Could not find Livewire component in DOM tree

When using a full-page Volt component combined with Laravel Blade’s @section directive, you might not be able to use $wire in your Alpine.js or JavaScript. This happens because Livewire cannot locate the current component when your HTML is injected into the view using the @section directive.

I have reported this issue on Volt's GitHub related to this.

Workaround

As a workaround, you can create a separate Blade view that contains your Volt component.

Volt component resources/views/livewire/email.blade.php

 
<?php

use function Livewire\Volt\{layout, state};

layout('layouts.bare');
state('email', '[email protected]');

?>

<div>
    @section('body')
    <p x-data="{
        email: $wire.$get('email')
    }">Your email is: <span x-text="email"></span></p>
    @endsection
</div>

Routing routes/web.php

 
Route::view('email', 'email');

View resources/views/email.blade.php

 
@extends('layouts.bare')

@section('body')
    <livewire:email />
@endsection

With this approach, you can successfully use $wire while using Laravel Blade’s @section directive and Livewire Volt! 🚀

January 28, 2025
Install Tailwind 4 in a Laravel 11 project

When you set up a fresh Laravel 11 project, you may notice it comes with Tailwind CSS 3.x by default. For those looking to upgrade to the latest Tailwind CSS 4, we’ve prepared this guide. These instructions also work for existing projects. If you encounter any issues, feel free to reach out via email: [email protected].

Steps to Install Tailwind 4 in Laravel 11

  1. Ensure Node Modules are installed

After installing a fresh Laravel project, you need to install the required node modules. Run:

 
npm install
  1. Initialize a Git repository

Your Laravel project must have a Git repository initialized. For a new Laravel project, you can simply run:

 
git init
  1. Run the Tailwind upgrade command

Once you have the node_modules directory in your project, run the following command:

 
npx @tailwindcss/upgrade@next
  • This command will:
    • link your tailwind.config.js file to the appropriate stylesheets
    • migrate your JavaScript configuration, templates, stylesheets, and PostCSS configuration
  • if your working directory has uncommitted changes, you may need to add the --force flag to the command:
 
npx @tailwindcss/upgrade@next --force
  1. You’re Done! 🎉

These instructions were prepared and tested using the latest, clean Laravel 11 project.

Useful Links

Enjoy building with Tailwind CSS 4 in your Laravel 11 project! 🚀

Newsletter

Join other developers and never miss out on new tips, tutorials and Zinq updates!