Getting infyom generator installed and working

As previously discussed Laravel does not come with the ability to scaffold out of the box. Instead we must install an Admin Panel Generator.

My review of the Generators available for Laravel was by no means exhaustive. As I mentioned I more interested in the simple core functionality that they offer then all of the bells and whistles. Infyom is a Generator that is well established with a good community behind it. It possesses all of the functionality we need and more. The code base appears to be kept well up to date and new releases and revisions tend to track the new releases of Laravel itself. In short, it will do nicely.

Before you install Infyom it's a good idea to double check the version of Laravel that you're working with. To do this change directory into the tennisClub folder which was created when you created your Laravel project. The command line we used creates a project with the latest stable release of Laravel.

cd tennisClub

Now type

php artisan --version

To get the version. At the time of writing the version was 6.5.2. The most recent version of Infyom which track this is (at the time of writing) version 6.0. Composer uses a file called composer.json which resides in your project folder (i.e. laravel\tennisClub). The require block in this file specifies all the packages that composer should pull-in (along with the packages on which they depend). To add new packages to your project you need to edit this file and add additional packages to the "require" block.

    "infyomlabs/laravel-generator": "^3.0",
    "laravelcollective/html": "^6.2",
    "infyomlabs/adminlte-templates": "^3.0",
    "doctrine/dbal": "~2.3",
    "eoinok/basic-template": "dev-main"

Open the composer.json file now and add these lines. Double-check the version in the latest code on this link

After editing the composer.json should look appear as follows - with the added lines from above highlighted in the red box

Note carefully if you're using the code from the link that you need to include the line for doctrine/dbal as we will be relying heavily on the "generate-from-tables" functionality.

To ensure we can use composer in this folder we need to copy composer.phar into our current folder (tennisClub). To do this type

copy ..\composer.phar .

To download the necessary packages and their dependent packages, at the command prompt in the laravel\tennisClub folder type:

php composer.phar update

Once this has completed there are two more brief steps before we are ready to generate BREAD functionality.

We need to add the necessary aliases to Laravel to point to the necessary Infyom components. To do this open the file config/app.php scroll down to the aliases array and ad the following lines.

    'Form'      => Collective\Html\FormFacade::class,
    'Html'      => Collective\Html\HtmlFacade::class,
    'Flash'     => Laracasts\Flash\Flash::class, 

Your config/app.php file will now look something like this

Open the file app\Providers\RouteServiceProvider.php and replace the line of code which sets the namespace inside the mapApiRoutes method with the following code. Although it looks the same there is a slight difference in the code you've replaced.

    ->namespace($this->namespace."\\API")

Effectively you'll just be adding ."\\API" as below

Next, we need to create the Infyom\Laravel-generator config file which allows us total control over all the settings. To do this type the following command into the Command Line Interface

php artisan vendor:publish --provider="InfyOm\Generator\InfyOmGeneratorServiceProvider"

Before we can publish the Infyom package and add the necessary templates we need to make some changes to the Laravel-generator config file. Open the file config\Infyom\laravel_generator.php, find the setting 'templates_dir' underneath the path settings and change it to point to eoinok/basic-template as below.

    'templates_dir'     => resource_path('eoinok/basic-template/'),

Next find the 'templates' section and modify the setting as below so that it points to point to the correct

    'templates'         =>  base_path('vendor/eoinok/basic-template'),

Save the laravel_generator.php file. Now we can publish the Infyom Package in a way that will let the generator use simple templates without the Admin Panel. To do this type

 php artisan infyom:publish

You may be prompted with a list of packages to be published. Type 0 and press enter to publish them all.

Finally, before we can use the generator fully we need to publish the layout associated with the Admin Panel. To do this type

php artisan infyom.publish:layout 

You may be notified that an existing routes file has been detected and asked if you would like to add standard authentication routes. if this happens, leave the default setting at n for No for yes and press enter.

Now that the Infyom Admin Panel Generator has been added we can go ahead and scaffold BREAD from a pre-existing database table. This will be explained in the next post.

Leave a Reply