Top 10 Laravel Packages to Know in 2024
This article introduces the ten most noteworthy Laravel packages for 2024, covering authentication, markdown rendering, real‑time UI, image processing, debugging, search, Excel import/export, queue handling, localization, and automatic API generation, each with concise explanations and code examples.
Laravel is a powerful PHP framework that helps developers quickly build complex web applications. It has a large ecosystem of third‑party packages that extend its functionality. To help developers choose the right tools, we list the ten most noteworthy Laravel packages for 2024.
1. Laravel Sanctum (Authentication)
Any application needs secure user authentication, especially API‑based apps. Laravel Sanctum provides an easy way to build secure APIs.
Sanctum integrates with Laravel’s user and authorization system, allowing you to use existing models. To create an API token for a user, use the createToken() method:
<code>$user = User::find(1);
$token = $user->createToken('my-api-token');</code>2. Laravel Spatie Markdown (Text Formatting)
Spatie’s Laravel Markdown package lets you convert plain text into attractive, responsive Markdown content, supporting the full Markdown syntax, code highlighting, tables, and media embeds.
To render Markdown in a Blade template, use the markdown() directive:
<code>@markdown('# This is a title')</code>3. Livewire (Real‑time Interaction)
Livewire is a framework for Laravel that enables you to build real‑time interactive user interfaces without writing JavaScript, avoiding page reloads and complex forms.
To create a Livewire component, extend the Component class. Below is a simple counter component:
<code>// Counter component
class Counter extends Component
{
public $count = 0;
public function increment()
{
$this->count++;
}
public function render()
{
return view('counter', ['count' => $this->count]);
}
}
</code>4. Image Intervention (Image Processing)
Image Intervention is a PHP image‑processing library that can be used in Laravel applications to resize, crop, watermark, and apply other effects to images.
Example: resize an image to 100×100 pixels:
<code>$image = Image::make('path/to/image.jpg')->resize(100, 100);
$image->save('resized_image.jpg');
</code>5. Laravel Telescope (Debugging)
Laravel Telescope is a powerful debugging tool that provides detailed insights into performance, database queries, mail logs, and event handling, helping you quickly understand how your application runs.
Example: record all queries on the users table:
<code>Telescope::recordQuery('My Important Query', function () {
DB::table('users')->get();
});
</code>6. Algolia Meilisearch (Search)
Algolia Meilisearch is a high‑performance search engine that offers instant, relevant results for Laravel applications, supporting custom filters and faceting.
Example: search users by name and email:
<code>$users = Meilisearch::index('users')->search(
query: 'john doe',
filters: ['email' => '[email protected]']
);
</code>7. Laravel Maatwebsite Excel (Import/Export)
The Maatwebsite Excel package enables easy import and export of Excel files in Laravel, providing a simple API for managing spreadsheet data.
Example: export user data to an Excel file:
<code>Excel::create('users', function ($excel) {
$excel->sheet('Users', function ($sheet) {
$sheet->fromArray(User::all()->toArray());
});
})->download('xlsx');
</code>8. Spatie Queues (Background Jobs)
Spatie Queues is a robust package for handling asynchronous background jobs in Laravel, allowing long‑running tasks to be processed without blocking user requests.
Example: schedule a job to send an email:
<code>Queue::push(new SendEmailJob($user, $message));
</code>9. Spatie Laravel Translation (Localization)
Spatie Laravel Translation provides an easy way to localize Laravel applications, enabling translation of strings and resources for a global audience.
Use the @lang() directive in Blade templates to translate strings. Example:
<code><h1>@lang('Welcome')</h1>
</code>If the current locale is English, "Welcome" is displayed; if French, "Bienvenue" is shown.
10. Laravelizer (Automatic API Generation)
Laravelizer automatically generates API documentation, controllers, and configuration files, eliminating the need to write boilerplate code and speeding up API development.
Example: define a route that retrieves a user by ID:
<code>Route::get('/users/{id}', function ($id) {
return User::find($id);
});
</code>Laravelizer is a valuable asset for Laravel developers seeking fast, efficient API creation, improving maintainability and providing unified documentation.
In this article we presented the ten most valuable Laravel packages for 2024, which can help you streamline development, boost productivity, and build more complex applications.
php中文网 Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.