Laravel Nova 4 - 2023 Update

Laravel Nova 4 - 2023 Update

Laravel Nova is a administrative panel for Laravel applications. Laravel Nova 4.0 was released on April 3, 2022 and includes a number of new features and improvements.

Key Takeaways

  • Laravel Nova 4.0 was recently released with major updates including a new responsive UI, collapsible relations, notifications, batch actions, and more.
  • The Nova community response has been very positive, with praise for the beautiful and intuitive interface. Nova is considered a game-changer for Laravel developers.
  • Top use cases are building admin panels and dashboards for Laravel applications. Nova offers powerful CRUD functionality out of the box.
  • Known issues are minor and being tracked on GitHub, mainly around search, metrics, and small CSS problems. No major issues reported.

Recent Updates in Nova 4.0

Some of the key updates in Nova 4.0 include:

  • New fully responsive UI with support for dark mode
  • Collapsible relations to improve performance
  • Notifications within Nova
  • Batch actions
  • New fields like Color, Avatar, MultiSelect
  • Dependent fields
  • Improved search
  • Custom sidebars and menus

Overall, Nova 4.0 provides an improved user experience while expanding the functionality and customization options.

New in Laravel Nova 4.0

The new version of Laravel Nova has been built with Inertia.js - the modern layer using a new approach to building server-driven SPA.

Dependencies have been changed.

Currently, the server-side's minimum PHP version is PHP7.3+ and Laravel Framework 8.0+.

Several packages have also been updated:

  • doctrine/dbal

  • laravel/ui

  • symfony/*

  • cakephp/chronos

On the client-side, flatpickr and moment.js libraries have been removed

You must follow the official website instructions when you decide to update your Laravel Nova from version 3+ to 4.

Laravel Nova 4.0 is the latest version of the administrative panel for Laravel applications and builds upon the improvements made in the previous 3.x versions.

One of the major updates in Nova 4.0 is implementing a fully redesigned and responsive interface built on top of the Tailwind CSS 2 framework, Vue 3 JavaScript library, and Inertia.js for building single-page applications. This new design also includes support for dark mode.

In addition to the updated design, Nova 4.0 introduces many new features and improvements to make it easier to manage and customize your Laravel application.

Some of these features include the ability to collapse related resources, customize the branding of the Nova interface, receive notifications within the panel, define custom callback actions, create custom fields with dependencies and filters, define custom menus, create new metrics, perform batch actions, and improve search functionality.

These are just a few examples of the many new features and improvements available in Laravel Nova 4.0.

Personal experience with Laravel Nova

As someone who has been using Laravel Nova for several years, I can confidently recommend it as a powerful and feature-rich administrative panel for Laravel applications. Nova provides a user-friendly interface for managing and organizing the various components of a Laravel application, including resources, actions, filters, lenses, and custom fields. The interface is easy to navigate and customize, and the wide range of available features makes it a versatile tool for various use cases.

One of the standout features of Nova is its ability to easily create custom fields and actions, which allows you to tailor the panel to your specific needs and workflow. The support for custom filters and lenses is also a useful tool for organizing and presenting data in a meaningful way to your team or clients.

Overall, I have found Laravel Nova to be an invaluable asset in my work with Laravel applications, and I would recommend it to anyone looking for a robust administrative panel.

Examples of Custom Dashboards in Laravel Nova

Laravel Nova provides a lot of flexibility when it comes to creating custom dashboards. Here are some examples of the types of dashboards you can create:

1. User Statistics Dashboard

You can create a custom dashboard that displays important statistics about your users. For example, you could display the number of registered users, active users, and inactive users. You could also include charts that show user growth over time.

2. Revenue Dashboard

If your application generates revenue, you can create a custom dashboard that displays important revenue metrics. For example, you could display total revenue for the month, week, or day. You could also include charts that show revenue growth over time.

3. Content Management Dashboard

If your application has a lot of content, you can create a custom dashboard that helps you manage it more effectively. For example, you could display the number of articles published each day, week or month. You could also include filters to help you find specific types of content more easily.

These are just a few examples of the many types of custom dashboards you can create with Laravel Nova. With its flexible interface and powerful features, there's no limit to what you can achieve with this tool!

Customizing Resource Fields in Laravel Nova

One of the key features of Laravel Nova is its ability to customize the fields displayed for each resource. This allows you to tailor the information displayed on the backend to your specific needs.

To customize resource fields in Laravel Nova, you can use the fields method within your resource class. This method defines an array of fields that should be displayed for each instance of the resource.

For example, let's say you have a Post resource and you want to display only the title, author, and publish date. You could define these fields as follows:

use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\DateTime;

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        Text::make('Title'),

        BelongsTo::make('Author', 'author', User::class),

        DateTime::make('Publish Date'),
    ];
}

In this example, we're using four different field types: ID, Text, BelongsTo, and DateTime. The ID field is used as a unique identifier for each post, while the other fields display the post's title, author (as a relationship with a User model), and publish date.

By customizing resource fields in this way, you can ensure that your backend displays only the most relevant information for each resource. This helps to streamline your workflow and make it easier to manage your application's data.

Filters and Sorting Options in Laravel Nova

Laravel Nova makes it easy to filter and sort your application's data using its built-in tools.

Filters

Filters are a powerful feature of Laravel Nova that allow you to quickly find specific records. You can create filters for any field in your resource, such as text fields or date pickers.

For example, let's say you have a Product resource with a name field. You could create a filter that allows you to search for products by name:

use Laravel\Nova\Filters\Filter;
use Illuminate\Http\Request;

class NameFilter extends Filter
{
    public function apply(Request $request, $query, $value)
    {
        return $query->where('name', 'like', '%'.$value.'%');
    }

    public function options(Request $request)
    {
        return [];
    }
}

In this example, we're creating a filter called NameFilter that searches for products where the name field contains the specified value.

Sorting Options

Sorting options allow you to sort your data based on specific criteria. For example, you might want to sort your products by price or by popularity.

To create sorting options in Laravel Nova, you can use the sortFields method within your resource class. This method defines an array of fields that should be used for sorting.

For example, let's say you want to sort your Product resource by price and popularity. You could define these fields as follows:

use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Currency;

public function fields(Request $request)
{
    return [
        ID::make()->sortable(),

        Text::make('Name'),

        Currency::make('Price')->sortable(),

        Text::make('Popularity')->sortable(),
    ];
}

In this example, we're using three different field types: ID, Text, and Currency. The Currency field is used to display the product's price, and is marked as sortable so that it can be used for sorting. We've also added a Popularity field that displays the product's popularity rating, which is also marked as sortable.

By using filters and sorting options in Laravel Nova, you can quickly find and manage your application's data with ease.

Creating a Custom Tool for Laravel Nova

Laravel Nova provides the ability to create custom tools that can be added to the dashboard. These tools allow you to extend the functionality of Nova and perform additional tasks that are specific to your application.

To create a custom tool in Laravel Nova, follow these steps:

  1. Create a new class that extends the Laravel\Nova\Tool class.

  2. Define a render method within your new class, which returns the HTML content for your tool.

  3. Register your new tool with Laravel Nova by adding it to the tools method within your NovaServiceProvider.

Here's an example of how you might create a simple tool that displays the current weather conditions:

use Illuminate\Support\Facades\Http;
use Laravel\Nova\Tool;

class WeatherTool extends Tool
{
    public function render()
    {
        $response = Http::get('https://api.openweathermap.org/data/2.5/weather?q=New%20York&appid=YOUR_API_KEY');

        $weather = $response['weather'][0]['description'];

        return view('weather-tool', compact('weather'));
    }
}

In this example, we're using the OpenWeatherMap API to retrieve the current weather conditions for New York City. We then pass this information to a Blade template called weather-tool, which displays the weather conditions on our dashboard.

Once you've created your custom tool, you can add it to your dashboard by registering it with Laravel Nova:

use App\Tools\WeatherTool;
use Laravel\Nova\NovaApplicationServiceProvider;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    // ...

    public function tools()
    {
        return [
            new WeatherTool(),
        ];
    }
}

By following these steps, you can easily create custom tools that extend the functionality of Laravel Nova and make it even more powerful.

Useful Links:

Related articles

Ruslan Osipov
Written by author: Ruslan Osipov