Wednesday 5 April 2017

Generating the Laravel/Lumen Migrations from ER Diagram Model using MySQLWorkbench

To install the Migration Exporter from MySQL Workbench

Install thehttps://github.com/beckenrode/mysql-workbench-export-laravel-5-migrations/blob/master/export-laravel-5-migrations.py from Workbench > Scripting > Install Plugin/Module and browse the `export-laravel-5-migrations.py` file.

Then, go to Workbench > Tools > Catalog > Export Laravel 5 Migration and click on "Save the Migrations to the Folder..."

However got the following error: (Workbench > Help > Show Log File)
Error during "Export Laravel 5 Migration" 
Then, review the relationship index and foreign keys relations and amended few foreign keys which are not properly selected the reference columns.

Afterwards, tried generating the migration using above method, ultimately able to generate the migration.
However, found missing foreign keys relationship generated migration files.

To generate Laravel Migrations from MySQL Workbench:

To build the migrations with foreign constrains using following steps:
  1. Export the model using MySQL Workbench > File > Export > Forward Engineer approach as sample_database.sql file
  2. Create the database called 'sample_database'.
  3. Next, Import the sample_database.sql file into the above created database to build tables, which will populate all tables from the script. (you can also directly execute all the scripts from that .sql file instead, from the Query Builder)
    Note: Please make sure all the foreign keys relationships are created along with tables, once you find all the relationship are in place.
  4. Then, go to the MySQL Workbench > Database > Reverse Engineer, and establish the connection and select the database to regenerate the Model (ERD).
    This allows the MySQL Workbench to propagate the Tables' objects correctly which supports to generate the migrations.
  5. Lastly, go to Workbench > Tools > Catalog > Export Laravel 5 Migration and click on "Save the Migrations to the Folder..."
    If you already haven't install the Laravel 5 Migration plugin, refer above.

To prevent pushing the file permission in local into git repo (MacOS)

After switching to MacOS, I had to change the my applications's files permissions due to MAC permissions issue to run the application.

Afterwards, I made a commit and pushed to the Git Repo, however the modified file's permission also included on the push to the Git Repo.

Indeed, I do not want to include those permission which I have done for my local only and I have to reset my commit on the remote repo.

To prevent happening that, please follow the steps below:

1. Check the filemode status on git config:
$ git config -l

Output may contain below:
$ core.filemode=true

2. If it set as true, run the below command to set to false which will prevent including the file permission on the commits.
$ git config core.filemode false

3. Instead, run below command if you want to change the git configuration globally to apply on all the applications:
$ git config --global core.filemode false

Tuesday 4 April 2017

Configure Entrust on Laravel-lumen

## Configure Entrust on Laravel-lumen * In order to install Laravel 5 Entrust, just add the following to your composer.json. Then run composer update:
    "zizaco/entrust": "5.2.x-dev"
    
* Open your `bootstrap/app.php` and add the following to the providers array:
    $app->register(Zizaco\Entrust\EntrustServiceProvider::class);
    
* Create new `config/` directory on the project root folder. * Then, add the following package on `composer.json`:
    "laravelista/lumen-vendor-publish": "^2.0"
    
then, run
    composer update
    
* Create the `app/helpers.php` file and add the below function inside it.
    if (! function_exists('config_path')) {
        /**
         * Get the configuration path.
         *
         * @param  string  $patha
         * @return string
         */
        function config_path($path = '')
        {
            return app()->basePath() . DIRECTORY_SEPARATOR . 'config'.($path ? DIRECTORY_SEPARATOR.$path : $path);
        }
    }
    
* Add the following code into the `composer.json` inside the `autoload` after the `psr-4`
    "autoload": {
        "files": [
            "app/helpers.php"
        ]
    }
    
* Comment out the following line on `vendor/zizaco/entrust/src/Entrust/EntrustServiceProvider.php`
    //$this->bladeDirectives();
    
And, run the dump autolaod command:
    composer dump-autoload -o
    
* Then run the vendor publish command:
    php artisan vendor:publish