Access all tutorials in sprocket icon.
Published May 27, 2016 by Bill Keck.
This week new features were released for ViewMaker, which now adds a total of 12 new artisan commands to the Laravel artisan command line tool. This week we picked up make:chart, remove commands, and the ability to add slugs.
For those unfamiliar with ViewMaker: It’s an artisan plugin installed via composer. It’s built to supercharge workflow for standing up complete foundations of code, everything from model and migration to controller and factory method for seeding. It even creates a unit test for your create form, and of course it creates views, with the option of a fully working datagrid.
You can build all of that in under a minute, including migrating and seeding the db table. It’s a lot of fun to use.
A quick reminder on how to install via composer, just run:
composer require evercode1/view-maker
Then in your config/app.php providers array, add the following:
You can also refer to the docs, which have extensive descriptions and a workflow tutorial.
Before we talk about the make:chart command, let’s get caught up on the other big improvement, the slug option for make:foundation, make:crud, make:parent-child, and make:child-of.
Let’s do a Widget model example and run a foundation. Please note, you should use the make:master page to set up your master page with all the dependencies you need for the make:foundation command to work. See the docs for instructions on that, it’s very simple.
So assuming your master page has the dependencies, you can run the foundation command as follows:
php artisan make:foundation Widget master vue slug
In the above, Widget is the model you want to create, master is the name of your master page, and vue is the template type. Except for the slug, that is what was in the earlier versions of ViewMaker, which stands up the routes, model, controllers, factory method, unit test, migration, and views for a fully working, searchable, sortable, paginated datagrid in vue.js, all in one go.
What’s new is the slug flag, which defaults to false, so if you don’t want it, you don’t have to include it. But if you do want slugs on your show view, just include it like we did above, and you will get a fully-formatted and functional slug for all records, so that comes in handy.
So in this case if your first widget record had a name of ‘my first widget’, your show url would look like the following:
We use the convention of the id, followed by the slug to make sure there is no duplicate content. You can of course change that to suit your needs.
ViewMaker also now features remove commands to make stepping backwards simple. For example:
php artisan remove:foundation Widget
When removing, we only need to supply the model name. This is really helpful, especially if you made a typo in creation of the foundation. You can just remove it and then do the correct command, and still get it done in under a minute.
All in all there are 5 remove commands, which makes stepping backwards on most commands very easy. Right now, however, if you want to step backwards on make:parent-child, which is essentially two related foundations, use the remove:foundation twice, once for each model.
Ok, so onto the really big feature. ViewMaker now has a make:chart command, which will stand up a vue.js implementation of chart.js. After making a foundation, which is a dependency for the chart, just run the following command:
php artisan make:chart Widget
This will create a fairly advanced chart for you and place it at the top of your index page. You can change that to suit your needs, but that is where it will default to.
The chart UI allows you to select chart type, bar or line. You can also select the following dataperiods:
- 1 year
- 90 days
- 1 month
- 1 week
Your results will be pulled from your database and displayed with the proper labels.
The formatting takes place in the ApiController, which the make:foundation command builds for you. It’s a fairly big method, and you are free to extract parts out to your model or other classes to suit your own taste. The code generated by ViewMaker gets you up and running quickly, but you should do some housekeeping by organizing it with whatever format you are comfortable with. If the project is small, you can leave it as is.
The main thing is you get a working prototype and since there are not that many out there in vue.js, this can be a big help in getting started and learning how to work with it. It’s actually fairly easy to work with, once you know your way around it.
While the chart works right out of the box, you’ll want to organize your assets. I don’t extract out the js and css for you, you have to do that on your own. The reason for that is that I have no way to know how you are organizing your assets, whether you are using Elixir or not, so I leave those decisions to you.
Ultimately, using Elixir is probably the best choice, if you are ready to work with that. Consult with Laracasts for how to use Elixir, they have an awesome series on that.
All of ViewMaker features a very minimal bootstrap implementation, which leaves a lot of decisions up to you on how you want to customize it. The bootstrap that it does have is enough for you to get a clear idea of everything, while at the same time, keeping it simple, so you can do your own design.
Well, that’s it for now. More will be coming…
I hope you find ViewMaker useful. I don’t have a donate button, but If you would like to support my work and learn more about Laravel, you can do so by buying one of my books, Laraboot: laravel 5.2 For Beginners, I really appreciate it.