Introduction to Laravel Nova – Build Admin Panels Fast

Picture of Antonio C.

Antonio C.

Laravel Nova intro Image
Share:
Key Takeaways:

  • Laravel Nova provides a powerful toolkit for quickly building custom admin panels tailored to your app’s unique needs.
  • With its robust resource system and deep customization options, Nova allows you to focus on crafting the admin experience while handling CRUD fundamentals automatically.
  • Nova’s growing ecosystem of community packages and addons allows you to extend Nova’s capabilities for more advanced or large-scale applications.

Building full-featured admin panels can be time-consuming in most scenarios. Take that Laravel Property Listing App for example which we talked about recently. If you start to build an admin panel from scratch it will take a lot of precious work hours to get it done. So if you don’t want to do that one way is Laravel Nova. Laravel Nova aims to change that by providing an intuitive admin interface builder right out of the box. With Nova, developers can quickly build custom admin panels tailored to their application’s unique needs.

For those familiar with Laravel’s conveniences for rapid application development, Nova offers similar productivity gains for your app’s admin UI. Skipping the tedious work of coding admin features from scratch, Nova allows you to represent your app’s data as Nova resources. With a focus on usability and aesthetics, Nova can have your admin UI up in running in no time.

What is Laravel Nova?

Laravel Nova is an administration panel builder for Laravel applications. With Nova, developers can quickly construct complete admin interfaces tailored to their app’s data and use cases.

Under the hood, Nova provides a fluent API for representing your application’s entities as Nova “resources”. These resources give you an automatic admin UI for managing your app’s data. Nova handles the standard create, read, update, and delete (CRUD) operations out of the box.

Nova focuses on high usability and aesthetics, allowing you to build admin panels that are both functional and pleasing. The Nova dashboard offers customizable metrics and quick actions for managing your app. With robust customization options, Nova fits right in with your Laravel app’s frontend.

Laravel Nova example

Key Features of Laravel Nova

Some of the key features and capabilities provided by Laravel Nova include:

  • Automatic CRUD interfaces – Nova builds complete create, read, update, and delete interfaces for managing your app’s data
  • Custom resources – Define admin interfaces for your models and data as Nova resources
  • Dashboard – Organize resources and display metrics and analytics
  • Custom tools – Build new visual tools for managing data in the Nova UI
  • Authentication – Integration with Laravel auth and configurable authorization
  • Filters & Lenses – Allow searching, filtering and scoping resources in the admin
  • Custom Styling – Theme Nova with custom CSS and branding to match your app
  • Extensibility – Add custom Vue components and integrate other Laravel tools

Also Read: How To Build An Ecommerce Store In Laravel

Installation and Setup

Installing Laravel Nova is straightforward using Composer. Require the laravel/nova package:

composer require laravel/nova

After installing, run Nova’s install command to publish its assets and config:

php artisan nova:install

With assets published, you can migrate the Nova database tables:

php artisan migrate

In your App\Providers\NovaServiceProvider, Nova needs to be booted with your user model and admin permissions. For example:

public function boot()

{

Nova::serving(function () {

Nova::userModel(User::class);

Nova::auth(function ($request) {

return Auth::check();

});

});

}

This defines the User model and checks the Laravel auth guard to authorize Nova access.

Creating Your First Nova Resource

Nova resources represent the admin interface for a model or data entity. Generate your first resource with:

php artisan nova:resource Post

This creates a Post resource class. To display fields, add them in the fields method:

public function fields(Request $request)

{

return [

ID::make()->sortable(),

Text::make('Title')->rules('required'),

Text::make('Content')->hideFromIndex()

];

}

This defines columns for the post ID, title, and content. The content field is hidden from the index view.

Visit /nova to see your new Post resource! From here you can create, update, view and delete posts.

Customizing Nova Resources

Nova provides many options for customizing the display and behavior of resources in your admin panel. Some examples include:

Custom Layouts

You can customize the index, detail, create and edit layouts for a resource using separate methods:

public function fields(Request $request) { }

public function indexQuery(NovaRequest $request, QueryBuilder $query) { }

public function detailLayout() { }

public function createLayout() { }

public function updateLayout() { }

Custom Rows

Use the row() method to group fields together in a resource’s layout:

Row::make([

Text::make('First Name'),

Text::make('Last Name'),

]);

Global Search

Allow resource records to be searched via Nova’s global search using the searchable() method:

public static $search = [

'id', 'name', 'content'

];

public static function searchable() {

return static::$search;

}

There are many other customization options – review Nova’s resource documentation to learn more.

Also Read: The Best Laravel eCommerce CMS Solutions For 2024

Filters and Lenses

Nova filters allow scoping down resource results. Enable filterable fields with ->filterable():

Text::make('Name')->filterable();

Custom filters can be defined using Laravel’s query builder:

public function filters(Request $request)

{

return [

new Filters\MyCustomFilter

];

}

Lenses provide another way to modify index views and apply predefined filters. Register a lens using:

Lens::make(‘Published’, ‘isPublished’)

Lenses Laravel nova

Security and Access Control

Laravel Nova provides multiple ways to control access and permissions for your admin panel.

Gates

Gates allow restricting access to resources and actions using Laravel policies:

Gate::define('viewPosts', function ($user) {

return $user->isAdmin;

});

public function authorizedToView(Request $request) {

return $request->user()->can('viewPosts');

}

Roles and Permissions

Role-based permissions can be implemented using packages like Spatie’s Laravel Permission.

Policies

You can further customize authorization using Nova’s resource policies. Generate one with:

php artisan nova:policy Post

This creates a PostPolicy for granular control over Post resource access.

Also Read: How to Build REST APIs with Laravel Framework

Nova Packages and Extensions

Nova has a growing ecosystem of community packages and addons:

  • Nova Extension Trend – Adds charts and analytics
  • Nova File Manager – Filesystem browser for uploads
  • Nova Calendar – Full calendar view for events
  • Cashier – Subscription and billing management
  • Nova Mail Coach – Email marketing integration

Browse Nova add-ons on the Nova Website or Nova Packages.

https://hybridwebagency.com/wp-content/uploads/2024/01/Laravel-Nova-intro-Image.webp

Tips for Optimizing Nova

Here are some tips for improving performance in Nova:

  • Use eager loading to reduce queries
  • Add caching where possible
  • Use pagination for long index views
  • Lazy load resource panels
  • Enable Nova query caching
  • Limit exposed relationships to reduce complexity

Also Read:  How To Build A Property Listing App Using Laravel

Ending Note

Laravel Nova provides a robust toolkit for rapidly building custom admin panels tailored to your application’s unique needs. With its intuitive resource system and deep customization options, Nova lets you focus on crafting the admin experience while handling the CRUD fundamentals automatically.

For those seeking an experienced team to build their Laravel admin panel using Nova, our developers at Hybrid Web Agency are experts in Laravel and Nova. We offer flexible engagement models, allowing us to either own end-to-end Laravel development or augment your team with specialized Nova developers. Our proven processes and expertise in Laravel projects enable us to deliver high-quality solutions tailored to your needs on time and on budget.

Reach out to our Laravel team today to discuss your project and admin panel requirements. We’re excited to help you build something incredible!

Table of Contents

Related Blogs

Ready To Start Your Project

OR