Require the Nova package in your composer.json and run the nova:install and migrate artisan commands:
php artisan nova:install
php artisan migrateDefault path: http://localhost/nova
php artisan nova:userUpdate the language setting in your config/app.php config file:
'locale' => 'de'Copy translations from franzdumfart/laravel-nova-localizations to your repo:
php -r "copy('https://raw.githubusercontent.com/franzdumfart/laravel-nova-localizations/master/lang/de.json', './resources/lang/vendor/nova/de.json') || exit (1);"Generate a new Nova resource from an existing model:
php artisan nova:resource PostGenerate a new Laravel policy for the Post model:
php artisan make:policy PostPolicy -m PostAfter that, map the new policy to the model in app/Providers/AuthServiceProvider.php:
protected $policies = [
'App\Post' => 'App\Policies\PostPolicy',
];Modify the Nova resource index query in app/Nova/Post.php so that Users can only see their own Posts:
public static function indexQuery(NovaRequest $request, $query)
{
return $query->where('user_id', $request->user()->id);
}Remove the public static $title = 'title'; in app/Nova/Post.php to define a custom title property on the resource class to modify the global search results:
public function title()
{
return $this->title . ' - ' . $this->category;
}public function subtitle()
{
return "Author: {$this->user->name}";
}To exclude the resource from the global search add the $globallySearchabl property on the resource app/Nova/Post.php:
public static $globallySearchable = false;An empty $search array in app/Nova/Post.php will remove the searchbar of the resource:
public static $search = [];Generate a new filter using the available artisan command:
php artisan nova:filter PostPubliishedAttach the filter to a resource via the filters() method.
public function filters(Request $request)
{
return [
new PostPubliished()
];
}Lenses are custom views in the admin panel. Generate a new lens:
php artisan nova:lens MostViewsAttach the lens to a resource via the lenses() method.
Actions are custom tasks that can be performed on eloquent models. Generate a new action:
php artisan nova:action PublishPostAttach the action to a resource via the actions() method.
Populate the fields() method to request additional information (in a prompt) before running an action. The data is available in the handle() method:
Action::message($fields->message);Customize to whom and where actions are available with the canSee() with canRun() resource methods:
public function actions(Request $request)
{
return [
(new PublishPost())->canSee(function ($request) {
// Restrict to user with ID 1.
return $request->user()->id === 1;
})->canRun(function ($request, $post) {
// Restrict to post with ID 1.
return $post->id === 1;
})
];
}Add the Actionable trait to the Post model to enable a detailled log of all performed actions:
class Post extends Model
{
use Actionable;
}php artisan nova:value PostCountphp artisan nova:trend PostsPerDayphp artisan nova:partition PostsPerCategoryphp artisan nova:tool acme/nova-toolThis command prompts to:
Would you like to install the tool's NPM dependencies? (yes/no)
Would you like to compile the tool's assets? (yes/no)
Would you like to update your Composer packages? (yes/no)
php artisan nova:card acme/nova-cardThis command prompts to:
Would you like to install the card's NPM dependencies? (yes/no)
Would you like to compile the card's assets? (yes/no)
Would you like to update your Composer packages? (yes/no)
php artisan nova:field acme/nova-fieldThis command prompts to:
Would you like to install the field's NPM dependencies? (yes/no)
Would you like to compile the field's assets? (yes/no)
Would you like to update your Composer packages? (yes/no)
php artisan nova:theme acme/nova-themeThis command prompts to:
Would you like to update your Composer packages? (yes/no)