Artisan becomes more interactive

From Laravel 10 on, Artisan becomes more interactive.

For example: you ask to create a model, but you forget to pass the name:

php artisan make:model

Instead of giving an error message, Artisan will simply ask you the name of the model, as well as whether you want to create a migration, factory, etc. Very handy!

php artisan make:model
 
What should the model be named?
❯ Post
 
  Would you like any of the following? [none]
  none ......................................................................................... 0
  all .......................................................................................... 1
  factory ...................................................................................... 2
  form requests ................................................................................ 3
  migration .................................................................................... 4
  policy ....................................................................................... 5
  resource controller .......................................................................... 6
  seed ......................................................................................... 7

 

Is your application up to date?

An up-to-date application not only gives you the latest features and improvements, but also maximizes security and performance.

diff

The Laravel 10 skeleton uses native types instead of docblocks

Also from Laravel 10 on, the skeleton will use native types instead of docblocks.

The team has also added generic type annotations, which will dramatically improve auto-completion when coding as well (if your code editor supports generic annotations).

See the PR on GitHub: [10.x] PHP uses Native Type Declarations 🐘

For example, in the Laravel skeleton, the schedule() method in app/Console/Kernel.php will look like this 🤩

Tweet taylor otwel types of packages

Official packages will also use native types

Actually, you don't have to wait until Laravel 10 to enjoy native type hints in official Laravel packages. The Laravel core dev team was already integrating this throughout the year, which has certainly already paid off:

No more support for PHP 8.0

If Laravel 10 drops support for PHP 8.0 and requires at least 8.1, that means two things if you want to upgrade:

    Either switch to PHP 8.1
    Or PHP 8.2

Why are they dropping PHP 8.0 support already? PHP 8.0 has not been in Active support since Nov 26, 2022, so it only falls under Security fixes now. Since Laravel is also no longer working with LTS versions, the vision from Laravel is that they go with the technology currently in the community as best they can. Staying stuck on PHP 8.0 would therefore not fit with their new vision.

You can find the pull request on GitHub: [10.x] Drop PHP 8.0

Doctrine/dbal is no longer needed to change columns in migrations

In an effort to eliminate the need for doctrine/dbal package when using change() to modify columns, a new feature is coming to Laravel 10. This feature will allow developers to use the change() method and modify columns on MySQL, PostgreSQL, and SQL Server without the need for any additional packages. This is a significant and risky change, but we do believe it is worth the effort.

To better understand the new feature, see this example:

$table->integer('user_balance')->unsigned()->default(0);

// `user_balance` is an integer, unsigned, with a default value of '0'.

Now we assume we have a column for user_balance and we want to change its type. Since Laravel 10, we can do this easily:

$table->bigInteger('user_balance')->change(); 

// This changes `user_balance` to a bigInteger instead of an integer

The above code successfully changes the type of the column, but also drops the attributes UNSIGNED and DEFAULT. Therefore, it is important to remember to add all attributes when changing the type of a column:

$table->bigInteger('user_balance')->unsigned()->default(0)->change();

In case you have multiple database connections and have doctrine/dbal already installed, it is recommended that you call the Schema::useNativeSchemaOperationsIfPossible() method within the boot method in AppProvidersAppServiceProvider to be able to use native schema operations and to use native operations before relying on the package (SQLite, for example, does not yet support this):

use IlluminateSupportFacadesSchema;
 
class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Schema::useNativeSchemaOperationsIfPossible();
    }
}

Retrieve column types

Another notable feature of Laravel 10 is the ability to use the Schema::getColumnType method without depending on the doctrine/dbal package. Currently, we use Schema::getColumnType with doctrine/dbal to get the column type. Doctrine/dbal maps each native column type to its doctrine/dbal type equivalent, and it does not support many of the column types used by Laravel in different databases.

In Laravel 10, by contrast, the new method Schema::getColumnType returns the actual column type instead of the doctrine/dbal equivalent. This also allows you to write integration tests for the new native column change function. You can use this function to get the data type name or the entire type definition of the specified column:

Deprecations of Laravel 9

Methods that were marked as deprecated in Laravel 9 will be removed in Laravel 10. The upgrade guide that you can find back in the documentation contains a list of the deprecated methods and the potential consequences.

Here are some deprecations we found:

  • Removal of several deprecations PR #41136
  • Removing deprecated date properties PR #41136
  • Removing the handleDeprecation method PR #42590
  • Remove the assertTimesSent method PR #42592
  • Removing the ScheduleListCommand's $defaulName property Diff 419471e
  • Removing the deprecated method Route::home PR #42614
  • Removal of deprecated dispatchNow functionality PR 42591

Thinking about digitalization yourself?

At Codana you can ask all your questions and together we will work out a plan with a sustainable outlook for the future!

Laravel pennant logo

Laravel Pennant - Feature flag system

Laravel Pennant is a package published by the Laravel team along with the release of Laravel 10. Pennant allows working with feature flags without requiring community packages.

Feature flags enable you to incrementally roll out new application features with confidence, A/B test new interface designs, compliment a trunk-based development strategy, and much more.

You can install Laravel Pennant very easily with composer:

composer require laravel/pennant

To give a brief example of how feature flags work, you can deploy a functionality only to a select group of users in your production environment. This is great for A/B testing, for example.

use Laravel\Pennant\Feature;
use Illuminate\Support\Lottery;
 
Feature::define('new-coupon-order-flow', function () {
    return Lottery::odds(1, 10);
});

Verify that the user has access to the function:

if (Feature::active('new-coupon-order-flow')) {
    //
}

There is even a Blade directive:

@feature('new-coupon-order-flow')
    …
@endfeature

To learn more about Laravel Pennant, take a look at the official documentation.

Author: Noah Gillard
PHP / Laravel Developer
Noah Gillard AI generated Face

More insights

Cross-platform applicaties with React Native

Never before has developing native mobile applications been as accessible as it is today. At Codana, we do this by using the React Native, an open-source framework developed by Meta.

Author: Jinse Camps
Architect | Analyst
Jinse Camps
dev

Laracon EU 2024

A fantastic learning experience to inspire and be inspired together with a lot of other Laravel passionate people! Something we couldn't miss and very much connect with the community. What a top event! Who will we see next editions? 😮

Author: Noah Gillard
PHP / Laravel Developer
Noah Gillard AI generated Face
laracon codana persoon

An efficient tourism data management system

A TDMS or Tourist Data Management System, is simply a platform that retrieves data from various sources, processes it internally either automatically or not, and offers this data back to external platforms.

Author: Tom Van den Eynden
Web Architect | Coordinator
Tom Van den Eynden
laptop

Tourism Data Management Systems

In dit artikel verkennen we wat een TDMS is, waarom het essentieel is voor de toerisme-industrie, en hoe technologieën zoals Laravel en ElasticSearch het verschil kunnen maken. 

Author: Tom Van den Eynden
Web Architect | Coordinator
Tom Van den Eynden
tdms

The difference between data management and data processing in a digital economy

Gegevens zijn cruciaal voor bedrijven en het begrijpen van de verschillen tussen gegevensbeheer en gegevensverwerking kan verwarrend zijn. In dit artikel zullen we deze verschillen in de digitale economie nader bekijken om hun doelen en toepassingen beter te begrijpen.

Author: Tom Van den Eynden
Web Architect | Coordinator
Tom Van den Eynden
gegevensverwerking

Test Driven Development - application to a project

TDD, or in full Test Driven Development, is an approach to development where we start from writing tests.

Author: Sarah Jehin
PHP developer
Sarah Jehin
development