10
Apr

How to build tool for Laravel Nova? Step-By-Step Guide.

So to publish a tool for your Laravel Nova, this article is going to help you with that. Laravel Nova gives an easy way to manage the data in our Laravel applications.

With a few lines of code, you can determine “resources” corresponding to your Eloquent models, and Nova will generate attractive interfaces for common CRUD tasks. Its real power, yet, lies in the customization options.

Moreover, there are four Nova elements you can create:

They are:    

  • Tools.
  • Resource Tools.
  • Cards and
  • Fields.

Before going to the steps, let’s know something about Laravel Nova.

So, What is Laravel Nova?

Nova is a single-page application which is built with Laravel and Vue Js. It is smooth as silk and writing the custom components is simple and easy.

Moreover,  Laravel Nova is the administration dashboard designed by the team behind Laravel.

Laravel Nova is a gorgeous backend tool for configuring and administering your multiple database tables.

This article provides a step by step approach, to create a tool!

Steps for Building tool for Laravel Nova:                                                         

  • Initial Step: Pull Laravel Nova into your application

If you have already installed Nova, you can skip this step.

The first step is to add Nova to your existing Laravel application.

Here is how you can install:

  • Download and unzip the freshest Nova release into a nova folder in the root directory of your Laravel application.
  • Tell the Composer where to find Nova using a local ‘path’ repository.

This is what you should do:

“repositories”: [

   {

       “type”: “path”,

       “url”: “./nova”

   }

],

  • The third step is to Add laravel/nova to the required section of your composer.json file

This can be done as:

“require”: {

   “php”: “^7.1.3”,

   “fideloper/proxy”: “^4.0”,

   “laravel/framework”: “5.6.*”,

   “laravel/nova”: “*”

},

  • Update your dependencies using

composer update

  • Install Nova with the help of Artisan using the command:

php artisan nova:install

php artisan migrate

You can view the installation by browsing to http://<your-app>/nova.

  • Initializing your tool

php artisan nova:tool sbine/route-viewer

This is how initialization needs to be done.

This command will create your tool in nova-components/<YourTool>. It will then assist you to install its NPM dependencies, compile them, and update your parent application’s composer.json with the new tool dependency.

Added, it will also symlink your tool’s directory to your vendor directory, as though you had installed it via Composer.

  • Registering your tool

Your Parent application needs to activate your tool once your scaffolding has been done. Open app/Providers/NovaServiceProvider and attach your tool to the tools() method. It will be residing in the src directory under the name you used in the Nova tool command.

use Sbine\RouteViewer\RouteViewer;

public function tools()

{

   return [

       new RouteViewer,

   ];

}

Once this is done, your tool should be available with a fancy landing page.

It will look just like this picture.

  • Write some code there

You can find all your code for your tool in the folder nova-components/<YourTool>.

Every tool ships with a routes/api.php file for you to register your individual routes. Everything registered here will be prefixed with /nova-vendor/<your-tool-name>/.

  • Upload your tool to Github

Create a new repository on GitHub, and put your code to it.

git init

git remote add origin git@github.com:<your-name>/<your-repository>.git

git add.

git commit -am “Initial commit.”

git push origin master

  • Make a release

You can tag the versions of your users can rely on a particular version, rather than whatever’s on the master. To tag a version corresponding to your recent commit, use git tag <version>:

git tag 0.0.1 && git push –tags

  • Submit it to Packagist.org

To make your tool installable with Composer initially, you need to register on Packagist.org.

Log in, go to ‘Submit’, and insert your repository URL.

Your Packagist.org entry won’t automatically update when you launch new code by default. To do that, you will need to create a GitHub Service Hook.

You can also manually update it by using the ‘Update’ button, but experts recommend automating this process.

  • Install it in a new Nova app

We are all done! Now you can install your package in any of the Nova apps.

composer require sbine/route-viewer

Just like in step 2, you will need to register the tool in your app/Providers/NovaServiceProvider in order to use it.

For additional information on Nova tools and other types of customization, take a look at the official documentation.

Final Words

These tools would definitely get you a high standard for Laravel.

If you have any queries, jot down your comments in the comments section below!

Thanks for stopping by!

Comments

[bws_google_captcha]