Background
Laravel Nova is one of the most powerful web development toolkits if you’re a Website or PHP/Laravel developer. For a rock bottom once off price of $99 you can save years in development time by simply purchasing this software. At Vander Host, most of our back-end systems are created using Laravel and Nova. As such, we need a quick way to bootstrap new applications and this article is just what we need to get into the hyperlane.
Updated 7 November 2021 to include boilerplate installation and composer require commands:
Installation
laravel new project-name --jet cd project-name
mc -e .env
, add database, fix email sending to be Helo compatible
MAIL_HOST=localhost MAIL_USERNAME="Voice-Commander" MAIL_FROM_ADDRESS="[email protected]"
We install Nova via composer since we have a license and this method allows auto updating.
composer config repositories.nova '{"type": "composer", "url": "https://nova.laravel.com"}' --file composer.json
Then update composer.json
"require": {
"php": "^7.2.5",
"fideloper/proxy": "^4.2",
"laravel/framework": "^7.0",
"laravel/nova": "~3.0"
},
composer update --prefer-dist
php artisan nova:install
php artisan migrate
Then the fun continues!
composer require gregoriohc/laravel-nova-theme-responsive
php artisan vendor:publish --provider="Gregoriohc\LaravelNovaThemeResponsive\ThemeServiceProvider"
composer require chris-ware/nova-breadcrumbs
In tools:
\ChrisWare\NovaBreadcrumbs\NovaBreadcrumbs::make(),
In resource:
use Breadcrumbs;
While in resource replace indexQuery
:
/** * Default ordering for custom index query. * * @var array */ public static $sort = ['id' => 'desc']; /** * Custom index query that allows easy sorting of individual * resources by simply adding a public static $sort option */ public static function indexQuery(NovaRequest$request, $query) { if (empty($request->get('orderBy'))) { $query->getQuery()->orders = []; return $query->orderBy(key(static::$sort), reset(static::$sort)); } return $query; }
You’ll need this later in individual resources:
public static $sort = ['id' => 'desc'];
In config/app.php
change timezone
and locale
In config/nova.php
change path
and currency
php artisan nova:user
composer require david-griffiths/nova-dark-theme php artisan nova-dark-theme:add-switch
Create a model but at the same time also create a migration:
php artisan make:model Command -m
Create your first ENUM. Programming is all about consistency. To keep databases values consistent (and in lowercase), but still have a refactorable UI, we use ENUMs. Once you do one, you can do 100.
<?php namespace App\Enums; class CommandStatus { const NEW = "new"; const IDEA = "idea"; const DRAFT = "draft"; const PRODUCTION = "production"; public static function uiOptions() { return [ self::NEW => 'New', self::IDEA => 'Idea', self::DRAFT => 'Draft', self::PRODUCTION => 'Production', ]; } }
Expand your users table with these two fields:
$table->string('api_token')->nullable(); $table->boolean('admin')->false();
You’ll need a factory to create model examples and for testing. Have a look at the UserFactory, but here’s the command:
php artisan make:factory CommandFactory -m Command
Here’s an example of a custom Seeder (here’s the docs). Here’s the inside:
protected $model = Command::class; public function definition() { return [ 'name' => $this->faker->name, ]; }
Here’s a nice way of calling related records:
Category::factory(3) ->has(Command::factory()->count(3)) ->create();
You’ll need log file troubleshooting:
composer require kabbouchi/nova-logs-tool
In tools:
new \KABBOUCHI\LogsTool\LogsTool(),
Publish:
php artisan vendor:publish --provider="KABBOUCHI\LogsTool\LogsToolServiceProvider"
Edit nova-logs-tools.php and specify 25
BelongsTo Create Related Record:
BelongsTo::make('Lead Source') ->showCreateRelationButton(),
You want compact table styles / columns by default. In the base resource
class:
public static $tableStyle = 'tight';
footer.php
and logo.php
and comment the code. While you’re doing cleanup, also remove the ‘help’ card in the Nova service provider or comment it. To be really fancy, you can publish the help card in the right folder and then modify it! Instructions will follow.uiOptions()
static method:Select::make('Status') ->options(CommandStatus::uiOptions()) ->displayUsingLabels(),
Badge::make('Status')->map([ 'production' => 'success', 'draft' => 'info', 'idea' => 'warning', 'new' => 'danger', ])->sortable(),
composer require optimistdigital/nova-notes-field php artisan migrate
php artisan vendor:publish --provider="OptimistDigital\NovaNotesField\NotesFieldServiceProvider" --tag="config"
php artisan vendor:publish --provider="OptimistDigital\NovaNotesField\NotesFieldServiceProvider" --tag="migrations"
use HasNotes
and in resource NotesField
public function register()
{
Nova::sortResourcesBy(function ($resource) {
return $resource::$priority ?? 99999;
});
}
public static $priority = 1;
->withoutTrashed()
Old Article with Descriptions
Here are some of our favourite Laravel packages for bootstrapping successful projects:
- Nova Grouped Permissions
- Permissions handling to the next level
- https://novapackages.com/packages/eminiarts/nova-permissions
- Dark Theme
- Tabs Panel
- Buttons
- https://novapackages.com/packages/dillingham/nova-button
- Nova Impersonate
- Ideal to test permissions and roles
- https://novapackages.com/packages/kabbouchi/nova-impersonate
- https://github.com/KABBOUCHI/nova-impersonate
- Nova Permission
- Works perfect with Spatie’s permissions library which is amazing
- https://novapackages.com/packages/vyuldashev/nova-permission
- https://github.com/vyuldashev/nova-permission
- Spatie
- Permissions Library
- Truly powerful permissions library, highly recommend and works really well with Nova permissions
- https://github.com/spatie/laravel-permission
- Laravel Server Monitor
- Laravel Uptime Monitor
- https://github.com/spatie/laravel-uptime-monitor
- Permissions Library
- Beyond Code Nova Custom Dashboard Card
- Superb programming that gives you drag and drop for your dashboards
- https://novapackages.com/packages/beyondcode/nova-custom-dashboard-card
- https://github.com/beyondcode/nova-custom-dashboard-card
- Maatwebsite Laravel Nova Excel
- Quickly add highly customizable export functionality to your website
- https://novapackages.com/packages/maatwebsite/laravel-nova-excel
- https://github.com/Maatwebsite/Laravel-Nova-Excel
- Multiple Custom Dashboard
- Great if you’re planning on having a lot of dashboards
- https://novapackages.com/packages/alexbowers/nova-multiple-dashboard
- https://github.com/alexbowers/nova-multiple-dashboard
- Server Monitor
- https://novapackages.com/packages/insenseanalytics/nova-server-monitor