What's new What's New Laravel 10"A Deep Dive" into the most recent updates and features

Jan 27, 2023
Laravel 10

With the way it has already simplified PHP development for beginners and experienced developers, some might argue that it has spoiled users into believing it is PHP is the most simple programming language out there.

At the very most, we're sure we know that Laravel 10 has a lot to provide. What we'll discover in this article as we take you on the journey of Laravel's new features, fixes as well as newly deprecated methods as well as packages.

Laravel Release Schedule

The Laravel core team used to publish two major versions each year each six months.

But, the cycle of release had been altered after Taylor Otwell, the creator of Laravel, announced that only a single major version will now be made available each year. The members of the core team to commit more effort and time on a particular edition of the Framework. It also allowed them to release new features that are powerful without making any breaking adjustments.

  • Laravel 10 7 February 2023
  • Laravel 11 7 February 2024

Furthermore, in accordance with the support policy, bug fixes are available for 18 months as well as security updates last for two years on every Laravel versions.

Here are the anticipated bugs fixes and security updates schedule:

  • Laravel 9 will continue to be updated with bug fixes until 8 August 2023. Then, security fixes through February 6, 2024.
  • Laravel 10 will get bug fixes up to August 6, 2024. It will also receive security updates until February 4, 2025.
  • Laravel 11 is expected to receive bug fixes up through August 4, 2025 and security fixes until February 2, 2026.

Are You Ready to Upgrade to Laravel 10?

It is important to keep in mind that we do not always have to update our applications' Laravel version. It's not necessary to upgrade it to the latest version at the time an updated version becomes available.

Laravel is an open-source framework, which implies that every when we create a newly created Laravel instance on our computer We own the framework's codebase. That means, even if the framework version our app is using has been discontinued, the app will still function; we just need maintain it by ourselves.

As a result, it is widely suggested that stability of applications be given priority over framework upgrades.

In short, you should think about upgrading to Laravel 10 whenyou:

  • The application is stable with its current version and functioning without problems.
  • The latest version may add an option that your application requires or fixes any issue that the application is having.
  • The program will be rigorously tested before the upgrade changes will be pushed to production.

Laravel 10 hot updates from Laravel

Laravel 10 Logo
An image of the Laravel 10 Logo.


 As you already know, Laravel 10 has not yet been released. However, we will update this post to include the most current information on the upcoming release. We recommend saving this page , and returning to periodically.

New Features and Updates are available in Laravel 10

There's no doubt that the most thrilling aspect of every new version is the introduction of new options. Without further delay, let's start by having some look at the new improvements and new features that are available in Laravel 10.

1. PHP 8.1 The Heart of Laravel 10

2. Assistance for PHP 8.2

PHP 8.2 was launched on December 8 2022. It was released just two months prior to Laravel 10's release date. But, this shouldn't prevent anyone from using PHP 8.2 functions, since there is no need to do anything else, Laravel 10 will be ready for PHP 8.2.

In fact, the entire Laravel ecosystem, which includes Forge, Vapor, and Envoyer can be used with PHP 8.2 And you could even run PHP 8.2 in conjunction with Laravel 9. Wow! !

3. Laravel Starter Kits Upgrade

4. Predis Version Upgrade

Even though Laravel documentation states the Predis package as the package for interacting with Redis, you may make use of this officially licensed PHP extension. This extension is an API for connecting to Redis servers.

5. Native Type Declarations

Laravel used to utilize DocBlocks within the skeleton code of its to show what a piece of code performs and the kinds of parameters or responses to anticipate. With the advent of native declarations of type in Laravel 10 the way this is done is going to change.

The easiest way to convey this change is with a simple illustration. Instead of having a function that looks like this:

code >/**
 Find out if the user is able to create models. *
 * @param \ namespacedUserModel  $user
 * @return \Illuminate\Auth\Access\Response|bool
 */
 public function create( user  $user)
 
 //
 

...it will look similar to this:

/**
 * Find out whether users can build models. */
Public function create(user |user|$user): user} $user) * bool //

This change is purely for the benefit of developers, since IDEs can determine the structure of the expected parameter as well as the reaction. This improves quality of type, even when it's not feasible via PHP native types. This will allow code editors better work with auto-complete capabilities.

6. Each of the Validation Rules Invokable by Default

If you wanted to create an invokable rule for validation within Laravel 9, you would need to add --invokable flag after the artist command. This is no longer necessary as all Laravel 10 rules are invokable by default. Therefore, you can run the following command to create an invokable new rule for Laravel 10:

php artisan make:rule CustomRule

7. Native Column Modification Support

To have a better comprehension of this new feature, see the example below:

$table->integer('user_balance')->unsigned()->default(0)->comment('balance'); // `user_balance` is an integer, unsigned, defaults to '0', and column comment is 'balance'

Now, we're assuming that there is a column called users_balance and want to change its type. Starting from Laravel 10, we are able to perform this procedure:

$table->bigInteger('user_balance')->change(); // This will change `user_balance` to bigInteger instead of just integer

The code above will effectively change the type of the column but it also drop the UNSIGNED, DEFAULT and comment attributes. So, it's crucial to keep in mind all of the attributes when you're changing the type of a column:

$table->bigInteger('user_balance')->unsigned()->default(0)->comment('balance')->change();
use IlluminateSupportFacadesSchema;
 
 class AppServiceProvider extends ServiceProvider
 
 public function boot()
 
 Schema::useNativeSchemaOperationsIfPossible();
 
 

8. Column Type Native Retrieval

Another noteworthy feature of Laravel 10 is the ability to use the Schema::getColumnType method without having to rely on the doctrine/dbal package. We currently use Schema::getColumnType with doctrine/dbal to obtain the column type. doctrine/dbal converts every native column type to its doctrine or dbal type counterpart, but it doesn't support all of the column types used by Laravel in various databases.

In Laravel 10 on the other hand, the new Schema::getColumnType method will return the actual column type rather than its doctrine/dbal equivalent. It also enables you to create integration tests using the new native column modifying feature. You may use this feature to obtain either the data type name or even the complete nature definition for the column

Schema::getColumnType('products', 'price'); // decimal

9. Speedier Hashing Algorithm

xxHash is a Hash algorithm that's extremely quick. It features great output dispersion and output randomness in addition to its the ability to minimize collisions. Since PHP 8.1 provides support for the xxh128 algorithm and Laravel 10 runs on PHP 8.1 with an efficient hash algorithm in Laravel 10 is ideal.

It's important to note that Taylor mentioned when he reviewed the change that certain third-party packages may rely on the file names being exactly the same format as the SHA-1 is hash. That is the algorithm Laravel used to use for hashing. Therefore, If you're planning an upgrade in Laravel 10, it would be wise to verify this in any third-party packages used in your app.

10. whereExists() Method Support for Eloquent Builder

Presently, using whereExists() requires configuring the nested query using the closure. With Laravel 10, it is now possible to include an Eloquent Builder as an interconnected query. It allows for the use of custom builder methods, model scopes, and many more.

As an example, we usually perform this when we need to make use of whereExists():

Order::whereExists(function ($query) 
 $query->from('products')->whereColumn('products.order_id', 'orders.id');
 );

Through Laravel 10, we are able to accomplish this:

Order::whereExists(
 Product::whereColumn('products.order_id', 'orders.id')
 );

11. Eager Loading Optimization

Currently when eager loading relations which don't contain any keys that need to be loaded Laravel will still execute the same query as the one above. to select* from `table_name` where 0 = 1. But, the latest Laravel 10 update checks to determine if there are keys available to be loaded, and if not, provides an empty collection which eliminates the requirement for the unnecessary database queries.

The Deprecated Methods and Packages of Laravel 10

Laravel 10, Says Farewell PHP 8.0

Deprecated Methods of Removal

The Laravel core team is eliminating methods that are no longer supported within Laravel 9 from Laravel 9 and the Laravel 10 branch. The team is expected to update the documentation's upgrade guide to reflect all the deprecated methods and packages when Laravel 10 is released.

If you're planning to move your current application to Laravel 10, any code that utilizes a method no longer in use must be written with a fresh approach in order to get the same results.

Here is a list of the various deprecations and deletions we found while looking at Laravel 9 with Master Branch:

  • The Route::home method (deprecated in Laravel 9)
  • The deprecated functions and methods that are based on dispatchNow. This is to encourage developers to make use of dispatchSync, which is the sole method that is supported to dispatch immediately.
  • GetBaseQuery is a variant of the getBaseQuery due to the fact that it is a equivalent toBase equivalent
  • The MaintenanceModeException class which was not used anymore
  • The MocksApplicationServices trait
  • The fake mail's Failures of the mail method
  • The deprecated date property, it's recommended to use $casts instead.
  • It is the assertTimesSent() method
  • The support was withdrawn for Predis 1 and doctrine/dbal 2
  • The deprecations are all related to doctrine/dbal since Laravel discontinuing support for Version 2.

How Do I Install Laravel 10

Laravel 10 is already available today for users to go for a ride and test its capabilities. The "-dev" flag on the Laravel installer will install master branches from the laravel/laravel repository. All what you will have to do is to run the following command from your terminal

laravel new example--app --dev

Or, if you prefer using Composer:

composer create-project --prefer-dist laravel/laravel example--app dev-master

To better understand how to use the Composer command, here is brief explanation of it:

  • laravel/laravel: The package for the Laravel installation
  • Example--App: The new directory for your new project (can be altered)
  • dev-master the next version of Laravel (in this instance, Laravel 10)

After installing Laravel 10, you can confirm the version by navigating into the newly created directory application-example and run the artisan command.

$ php artisan --version
 Laravel Framework 10.x-dev

How To Upgrade a Project to Laravel 10

Are you considering upgrading your current version to Laravel 10? The Laravel team is working hard in the area of documentation, ensuring an easy and seamless upgrade guide while covering every potential breaking feature. Check out the Laravel 10's guide to upgrade for more details about the upgrade process is available now.

It is also important to keep an eye on the Laravel Shift once Laravel 10 is released. It offers a simple and automated approach to upgrading your Laravel version.

In addition to Laravel documentation, and Laravel shift, will release an extensive upgrade manual with examples from real life. Don't forget to bookmark this page and revisit it when Laravel 10 is released.

How To Deploy Laravel 10 Projects

  • PHP >= 8.1
  • BCMath PHP Extension
  • Ctype PHP Extension
  • CURL PHP Extension
  • DOM PHP Extension
  • Fileinfo PHP Extension
  • JSON PHP Extension
  • Mbstring PHP Extension
  • OpenSSL PHP Extension
  • PCRE PHP Extension
  • PDO PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension

Installing Laravel 10 on : Step-by Step guide

There are many advantages to hosting your apps and installing them on , for example, not having to bother with the configuration of deployment.

1. Laravel 10 Application

It is possible to include an .htaccess file in the root directory of your application which contains the following:


 RewriteEngine On
 RewriteRule ^(. *)$ public/$1 [L]
 

In the case of Laravel This redirects every request to public/index.php. However, if needed you can modify this option while adding the app ( Set up your processes step) or following deployment via your application's processes page. You can use:

  •    heroku-php-apache2 /public  
  •    php artisan serve --host 0.0.0.0 --port 8080  

2.Login to My

3. Authorizing on GitHub

My dashboard
Screenshots of my dashboard.


 Next, click on the   Follow along by using GitHub   button. If you're not already signed into GitHub, you'll be shown an option to sign into GitHub. After that, you can enable the GitHub application to connect to the account you have created with GitHub. GitHub account by selecting   Authorize  .

Finally, GitHub will redirect your browser to My so that you can keep setting up the app.

Connecting My with GitHub
Screenshot of connecting My on GitHub to GitHub.


 After you're connected to GitHub After connecting, you'll be shown the   Apply for an Add-on  popup/modal, which has a dropdown menu to select the GitHub repository. Click on the   GitHub repository  Select the field   Edit permissions on GitHub  in the dropdown.

Adding an application to My
Screenshot for adding an application My. My.


 This will open a new tab in your browser to the GitHub website where you are able to choose which data will be accessible. Instead of making access available to all repositories, consider picking only the repository you'd like to use. Choose the one you prefer.   Only certain repositories   Choose the repository you wish to install.

Installing My on GitHub
An example of how to install My On GitHub. GitHub.


 After that, you can click   Install   And you're good to go!

After you have returned to My and click the GitHub repository field, the authorized repository will be displayed. Additionally, you may tick Automated deployment after commit option to allow My's feature to auto-deploy your application as soon as you make any changes in your GitHub repository.

Selecting repository branch for My
Screenshot of Selecting Repository Branch for My.

4. Add Application Basic Details

Adding application basic details
Screenshot to add application basics specifics.

5. Include Variables in the environment

If you don't have an app key stored in the .env file already then you can create one by using an on-line Laravel key generator. In the next step, add the app key into the Key 1 field. Then, insert the generated app key into the Value 1. field.

Last but not least, you must select Running time during build and available during the build process.

Adding env variables to My application
Screenshot showing how to add env variables into My Application.

5. Create Build Environment Configuration

The most amazing thing about this is that there is no need to do anything! You may proceed by clicking on the Continue button, and voila! It's done with the built environment setup. If you'd like to increase the resources for building to ensure faster building You can select the preferred choice from the Build resources section.

The build paths field is optionalYou can just leave it blank. My will be using your root directory.

My application build environment
Configuring the application's build environment.

6. Create the processes and the Payment Method

In the Resources section, complete each field by filling in the following details:

  • The name of your process This is the name that you see on the screen of your application's processes.
  • Process type: Choose carefully, since this can't be altered once you've set it. You can, however, alter and modify further processes, for example background jobs, via your app's Processes page following deployment.
  • Starting command This is the "Start" instruction for your program (not required).
  • Size of the pod: The pod capacity you're expecting to need to run your business.
  • Instance count: The number of instances for your process (max 50).

Note that you can simply click Continue and not fill in the Command to Start field since the system automatically detects the required command in the initial deployment.

My application setup process
Screenshot to set up the application's process.


 The final step is to look over the monthly cost of use estimated for your app Then, confirm the payment method you have chosen. Once you're done, hit the   Verify payment method   button.

Confirming payment details for My
Screenshot for confirming payment details.


  And you're done! The program will perform all the work behind the scenes to support your application.

Loading application's deployment process
Screenshot to load application's deployment process.


 Once you've installed the app, you'll be able to access the entire deployment details as well as your temporary app URL that you may later replace with your personal Domain.

Successful deployment for the application
The application has been successfully deployed Laravel10 application on My.


 It's great that your Laravel 10 application now in production  But what if you need to make a change in production? If we need to modify the anchor tag's   Href   attribute? Because we activated the   Automatic Deployment of Commit  The feature My will detect any changes made to the branches that are deployed and update the live app accordingly.

7. Connect Laravel 10 to MySQL Database

Now that we've deployed our Laravel 10 application, we can effortlessly construct an online database, and then connect it to our application. All you have to do is select Applications from the navigation menu to the left. Then, click add a service and choose Database.

Adding new database to My
Screenshot of adding a new databases to My.


 After you have filled in all fields, click    Create database  . This creates a fresh database, ready to be used for internal and external connections. In our scenario the database requires external connections to connect to this Laravel 10 project that we deployed.

In order to do that, all you need to do is to select Add application in the Internal connections section. Then, select the application. You can check the Include environment variables in the application checkbox and My will populate all the .env variables your application requires.

Connecting database to Laravel 10 app
Screenshot showing how to connect the database with Laravel 10 application.


 Just like that you can see that the Laravel 10 application is deployed and connected to databases.

How Can I Contribute To Laravel 10

Although Laravel is maintained by a core group, it's being developed and improved by more than 3000 volunteers.

Do you want to be one of those contributors and contribute to the direction of Laravel's future? If yes it is possible to help the users from all over the globe by adding a new option, fixing a glitch, or even rewriting an unclear section of documentation.

For you to be a contributor to Laravel 10, here is how to contribute:

  1. Head to Laravel's GitHub repository and browse through the pull requests that have [10.xThe pull requests are tagged with [10.x as the subject. This will provide you a clear picture of the complete pull request to Laravel 10. If one of them refers to the contribution you were hoping to contribute, consider if you can improve on it.
  2. If your contribution idea has not yet been addressed by anyone else, you may create a PR by yourself.
  3. Not everything is worth adding to the codebase of the framework. Thus, you should only implement improvements that will be easy to maintain over time and help the vast majority of the Laravel community.
  4. Ensure adhering to the guidelines for contributions to Laravel to have a greater chance to have your work integrated with the framework.

Another reason why you should love Laravel 10 is that it lets you win money for the work you put into it through bug hunts! We'll look at those next.

Laravel 10 Bug Hunt Contest

Laravel 10 bug hunt contest
Laravel 10 bug hunt contest.


 Laravel 10 has announced an fantastic contest, whereby any contributor can stand a chance of winning $1000.

This will be the first contest that is of this kind within Laravel history. The idea behind it was to inspire members of the community to identify the bugs hidden within Laravel 10.

The rules are straightforward:

  • Only PRs submitted to the laravel/framework repository's 10.x branch are qualified.
  • Only "genuine" bugs fixes will be considered. The addition of new features, refactoring as well as typo-fixes, are not taken into consideration.
  • Every bug fix needs to be accompanied by tests.
  • The accepted bug fixes will be labeled on GitHub, and a random winner will be announced at conclusion of the contest.

The contest will finish at the time that the initial stable version of Laravel 10 is released. Any pull requests that would still be pending by that time or submitted after the initial release of Laravel 10 will be ineligible.

Summary

But that's not the only thing to note in this piece! There will be more changes prior to the date of release. However, for now, Laravel 10 appears to be extremely promising, and we're eager to explore all of the gifts it brings for all of the PHP world.

  • Easy setup and management in My Dashboard. My dashboard
  • Support is available 24/7.
  • The most efficient Google Cloud Platform hardware and network, powered by Kubernetes to ensure maximum capacity
  • Enterprise-level Cloudflare integration that improves speed as well as security
  • Reaching a global audience with more than 35 data centers as well as more than 275 PoPs in the world.