No Comments

Exploring the Latest Advancements: Laravel 10.37 Released

Reading Time: 8 minutes

In the always-changing world of making websites, Laravel is a PHP frame that keeps going and still brings new things. It’s special in making the internet stronger. Laravel 10.37 is no exception, offering a plethora of new features, advancements, and improvements to enable developers to build reliable and effective web applications. In this article, we’ll look closely at the main features of Laravel 10.37. We will also look at the big changes and improvements that make it a really good update.

1. Improved Performance:

The goal of Laravel 10.37’s speed optimisation is to make web applications developed with the framework function quicker and more effectively. Performance has increased overall and response times have decreased thanks to the Laravel team’s fine-tuning of several framework components. Applications with heavy traffic and resource-intensive tasks can especially benefit from this.

In the new Laravel 10.37 release, there are several improvements that can contribute to improved performance. Here are a few examples:

a) Background Queue Processing: Slow tasks can be delegated to a background queue with Laravel, which keeps your web requests responsive. The ‘dispatch’ method can be used to send jobs to the queue. This allows you to run as many queue workers as needed to handle your workload. For example:

$podcast = Podcast::create(/* ... */);
ProcessPodcast::dispatch($podcast)->onQueue('podcasts');

b) Improved Filesystem Abstraction: A strong filesystem abstraction layer offered by Laravel gives users a consistent API to deal with both local and cloud-based filesystems. This makes handling files in your application easier. Laravel’s beautiful and simple syntax lets you work with files no matter where they are stored. For example:

$path = $request->file('avatar')->store('s3');
$content = Storage::get('photo.jpg');
Storage::put('photo.jpg', $content);

c) Laravel Horizon: Laravel Horizon offers a stunning dashboard and code-driven settings for your Laravel-powered Redis queues if you require greater visibility and control over your queues. It provides improved queue management and monitoring features. You can learn more about Laravel Horizon from the official documentation.

2. Enhanced Blade Components:

Improved Blade components give the Blade templating engine a boost in Laravel 10.37. More modular and reusable components can now be made by developers, which simplifies the process of creating and maintaining intricate user interfaces. Cleaner and more maintainable projects are encouraged by the improved Blade components, which facilitate code management and organisation.

In the new Laravel 10.37 release, there are several enhancements to Blade components that can improve your development experience.

a) New Blade Directive: A new Blade directive named ‘@once’ is introduced in Laravel 10.37. Even if a section of code is included more than once, you can only render it once with this directive. This makes sure that even if the directive is called multiple times, the script tag appears in the produced HTML only once. For example:

@once
<script src="https://example.com/js/library.js"></script>
@endonce

b) Improved Component Slots: By enabling you to supply more data to named slots, Laravel 10.37 improves the use of component slots. When you need to alter the information within a slot, this can be helpful. For example:

<x-alert>
<x-slot name="title">
{{ $alertTitle }}
</x-slot>
{{ $alertMessage }}
</x-alert>

In this example, the '$alertTitle' and '$alertMessage' variables are passed to the named slots 'title' and default slot, respectively, within the 'x-alert' component.

3. Innovative Database Features:

Laravel is good at doing things with databases and version 10.37 added new cool features to make databases easier to work with. Better database speed and size come from improved search optimization and more complex database tools that make everything work better. The update also makes Eloquent, Laravel’s fancy ORM tool, even better and easier to use by the people who create these programs.

In the new Laravel 10.37 release, there are several innovative database features that can enhance your development experience. Here are a few points to consider:

a) Migrations: You can provide and distribute the database schema definition for your application using Laravel’s migration capability. Your database’s migrations serve as version control, which simplifies the management and synchronisation of changes across your team members. For example:

public function up(): void {
Schema::create('flights', function (Blueprint $table) {
$table->uuid()->primary();
$table->foreignUuid('airline_id')->constrained();
$table->string('name');
$table->timestamps();
});
}

This example demonstrates the creation of a 'flights' table with various columns and relationships.

b) Validation Rules: Laravel provides over 90 powerful built-in validation rules that can be applied to your database inputs. These rules help ensure data integrity and consistency. For example:

public function update(Request $request) {
$validated = $request->validate([
'email' => 'required|email|unique:users',
'password' => Password::required()->min(8)->uncompromised(),
]);
$request->user()->update($validated);
}

In this example, the update method validates the email and password fields before updating the user record.

4. Security Enhancements:

Laravel thinks safety is very important. The 10.37 version makes web apps safer by adding new protection features against possible dangers. The setup now has stronger ways of dealing with logging in, allowing access, and protection against typical safety weaknesses. Laravel still promises to give developers a safe place to make apps without worry.

In the new Laravel 10.37 release, several security enhancements have been introduced to help developers build more secure applications. Here are a few points to consider:

a) Filesystem Security Enhancement: Laravel provides a robust filesystem abstraction layer that allows you to interact with local and cloud-based filesystems. The latest release includes security enhancements in the filesystem component, ensuring secure file handling and storage.

b) Background Job Queue Security: Laravel allows you to offload slow jobs to a background queue, improving the responsiveness of your web requests. In the new release, there are security enhancements related to background job queue processing. You can run multiple queue workers to handle your workload securely.

5. New Tools for Testing:

Laravel 10.37 adds new tools and better ways to test applications. The test set is now bigger to help complete checks of many parts, making sure apps are dependable and steady. Developers can use these improvements in testing to create better and complete test cases. This leads to better quality software.

Here are some key tools and features available for testing in Laravel:

a) PHPUnit: PHPUnit is the standard testing framework used by Laravel. A popular testing framework for PHP applications, PHPUnit offers a robust collection of assertion techniques and testing tools. You may create features, integration, and unit tests for your Laravel apps with PHPUnit. For example, here’s a simple PHPUnit test case in Laravel:

use Tests\TestCase;

class ExampleTest extends TestCase
{
public function testBasicTest()
{
$response = $this->get('/');

$response->assertStatus(200);
}
}

b) Test Helpers and Assertions: Writing tests is made simpler by the variety of testing assertions and aids that Laravel offers. These utilities offer functions for asserting response status codes, asserting JSON responses, and submitting HTTP queries, among other things. These tools facilitate the testing process and improve the readability of your tests.

For example, you can use the 'assertJson' method to assert that a response contains specific JSON data:

$response = $this->get('/api/users');

$response->assertStatus(200)
->assertJson([
'data' => [
['name' => 'John Doe'],
['name' => 'Jane Smith'],
]
]);

6. API Improvements:

In today’s world where API making is important, Laravel 10.37 has added big changes that improve the framework’s ability to work well with APIs. The new update brings in tools that make it easier to make APIs and use them too. This helps developers create smooth and fast communication between different parts of their apps.

Here are some key points regarding API development in Laravel:

a) API Resource Classes: You may turn your models and model collections into JSON responses using Laravel’s API resource classes. These resource classes offer a practical means of tailoring the return data and structure to your API specifications. Your API endpoints’ returned data can be formatted and filtered by defining resource classes.

For example, you can create an API resource class to format the response for a user resource:

use Illuminate\Http\Resources\Json\JsonResource;

class UserResource extends JsonResource
{
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'email' => $this->email,
// Other attributes...
];
}
}

b) API Authentication: Laravel provides various authentication mechanisms for securing your API endpoints. You can use Laravel’s built-in authentication features like API tokens, OAuth, or JWT (JSON Web Tokens) to authenticate API requests and protect sensitive data. These authentication mechanisms help ensure that only authorized users can access your API resources.

7. Documentation Updates:

Laravel is known for offering lots of helpful and clear information for anyone who makes computer programs. Its release 10.37 is just like others. The paperwork has been changed to tell correctly about the new and better things that are now available. This allows people who make programs to quickly get what they need to use Laravel’s abilities best.

Here is a bit more info about the new features introduced:

Storing batches in DynamoDB

The idea of using DynamoDB to store batch meta information rather than a relational database was suggested by Sebastien Armand. You may use the following settings in your ‘queue.php’ config file to set up your application to use DynamoDB:

'batching' => [

   'driver' => env('QUEUE_FAILED_DRIVER', 'dynamodb'),

   'key' => env('AWS_ACCESS_KEY_ID'),

   'secret' => env('AWS_SECRET_ACCESS_KEY'),

   'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),

   'table' => 'job_batches',

],

See the documentation for complete setup details, and Pull Request #49169 for implementation details.

Assert multiple error messages

Tim MacDonald contributed the ability to assert a list of errors on a field using the ‘assertInvalid()’ method:

// Before, separate assertion calls are required

$response->assertInvalid(['email' => 'The email field must be a string.']);

$response->assertInvalid(['email' => 'The email field must be at least 5 characters.']);

// As of Laravel 10.37 you can now do:

$response->assertInvalid([

   'email' => [

       'The email field must be a string.',

       'The email field must be at least 5 characters.',

   ],

]);

Add ‘engine()’ method to Blueprint

James Brooks contributed an ‘engine()’ method when defining migration schemas:

// Previously

Schema::table('foo', function (Blueprint $table) {

   $table->engine = 'InnoDB';

   // ...

});

// Using the new engine() method

Schema::table('foo', function (Blueprint $table) {

   $table->engine('InnoDB');

   // ...

});

Get the indexes and foreign keys of a table

To retrieve the indexes and foreign keys of a given table schema, Hafez Divandari contributed the ‘getIndexes()’ and ‘getForeignKeys’ functions.

Schema::getIndexes();

Schema::getForeignKeys();

The ‘getForeignKeys()’ method returns an array for each foreign key with ‘name’, ‘columns’, ‘foreign_schema’, ‘foreign_table’, ‘foreign_columns’, ‘on_update’, and ‘on_delete’. The ‘getIndexes()’ method returns an array with several keys, such as ‘name’, ‘columns’, ‘type’, ‘unique’, and ‘primary’.

Conclusion

Another significant development in the history of this popular PHP framework is Laravel 10.37. Laravel keeps enabling developers to create complex and dependable online apps with new testing tools, enhanced Blade components, inventive database features, security fixes, and updated documentation. Developers can anticipate even more exciting features and advancements in upcoming releases as the Laravel ecosystem continues to grow.

In the vibrant ecosystem of Laravel development, Zunction stands as an online platform committed to providing an unparalleled experience for Laravel developers. Central to our mission is the steadfast adoption of the latest technologies, and with the release of Laravel 10.37, we reinforce our dedication to keeping our community at the forefront of innovation.

Subscribe to our telegram channel for Laravel tips every Monday!

You might also like