lumen doesn't use the right database directory on migration - laravel

in Lumen when i try to create a database migration the artisan try to store the migration file on my-project/database folder which causes an error because the migration folder in Lumen located under my-project/model/migration. so why artisan doesn't use the Lumen migration folder.

As you have stated that lumen tries to store the migrations inside the database/migrations and it is the intended behaviour and is by the design.
If you want the proof it is here:
https://lumen.laravel.com/docs/5.4/database#migrations
It has already stated that it uses laravel type of migration behaviour.
So, you must try to maintain the structure if you want to create and run migration using default standard, which would be great if in near future you want to migrate to laravel from lumen.
Also you have stated that lumen's migration is inside model. It was never there by the design. You might have changed the folder structure of the migrations.
Want the proof :
https://github.com/laravel/lumen/tree/master/database/migrations
https://github.com/laravel/lumen/tree/5.0/database/migrations
https://github.com/laravel/lumen/tree/5.2/database/migrations
https://github.com/laravel/lumen/tree/5.3/database/migrations
Hope it clears your confusions.

Related

Laravel Migrations Scripts

I would like to know is there any feature in laravel to generate migration scripts dynamically ( I mean scripts not migration files) like in Doctrine?
I have researched in the internet but didn't find a solution.
In Eloquent I generated migration files and wrote migration scripts manully. But in Doctrine I can generate migration script from entities (models) by issuing command migrations:diff, migrations:migrate etc. Thanks in advance.
You never define any of your table's fields in your Model class, so Laravel doesn't even know where to get the diff in your database.
But if your database is already there, check this question: how to create migration from existing database in laravel

How to specify folder for laravel migrations?

I am trying to put laravel database migrations in sub folders, but not sure how to do this.
When creating new migrations and executing your migrations, you can pass in a path parameter through the command line interface to specify the directory it will use to create and run the migrations respectively.
php artisan make:migration create_users_table --path=/path/to/your/migration/directory
php artisan migrate --path=/path/to/your/migration/directory
In AppServiceProvider, find a boot method and add there following
$mainPath = database_path('migrations');
$directories = glob($mainPath . '/*' , GLOB_ONLYDIR);
$paths = array_merge([$mainPath], $directories);
$this->loadMigrationsFrom($paths);
Now you can use php artisan migrate and also php artisan migrate:back when having migrations in sub folders
If you eager to do this, here is a quick solution at nscreed/laravel-migration-paths
pakcage. Very simple and easy to use.
During the periodical development phase the migrations folder may become very large. It is very helpful if we can organize the content of the migration folders. This library helps to organize migration files in different folders. Even, if your organize your existing files it will works as well.
Hope, it will help you.
You might want to take a look at this package, it's not exactly what you are looking for but it is an alternative to sorting and organizing sections of your application including controller, migrations, models, views and others.
Nwidart's Laravel Modules for modular application development with Laravel,
It helps to organize your application into modules, and so, you can create migrations in each module, and since the modules are in separate folders it helps fix this issue someway.

How to generate completely new migration in laravel 5.2

I am new to Laravel and was working on one project, which was 90% completed, and now project is 100% completed.
The project has old Migration files. I have made so many modifications in the tables (added/deleted columns) and/or added new tables in the database, now how do I update/create the Migration for that modifications? Because I don't remember where did I made the changes in the tables.
Do I have to use artisan command to create new migration for users table and all other tables same like this? php artisan make:migration create_users_table --create=users or there is any another way?
I have read the documentation but don't get how to do it.
Please correct me if I have made any mistake, because I don't know how to ask this question.
We user migration and tinker to Not use phpmyadmin , so if you have altered your tables in any way in phpmyadmin , you are all set , no need to do anything.
If you dont want to use phpmyadmin you can use migration and then start writing the sql code in there ( altering tables , etc)
And as we know the migration php files are located in your laravelfolder/database/migration . you can edit them there and then run php artisan migration and it will go throw all of them and make the changes in phpmyadmin.
Hope im clear enough :D

Can Laravel generate all mvc skeleton out of an existing table like that of cakephp's command cake bake all

I found laravel very interesting. But I'm wondering if there's any artisan command to generate all MVC skeleton files provided a database table all at ones. And how about separate generation of especially the model, given the table structure? or is there any alternative way to do the code generating?
You can create a migration file from the table via the package below.
https://github.com/Xethron/migrations-generator
Install it via : composer require --dev "xethron/migrations-generator"
Follow the package instructions, After connecting you application with the database simply run php artisan migrate:generate.
You will see number of migrations created via console message, You can also check your database/migrations folder for confirmation.
I didn't find how to do that, so I created my own code in order to create the models:
https://github.com/Triun/laravel-model-base
It is not super documented, but you can actually write your own addons in order to add custom business behaviors or include your own interfaces or traits to your models, with your own code.
And of course, reports and contributions are more than welcome.
I hope this helps.

create first user in Laravel 5

This is my first time using Laravel 5. Never experienced with any of other framework like CakePHP, CodeIgniter, Yii, etc. I just know how to use make api REST with slim framework.
I already create a table users as I can't access <<URL>>/home. I create fields and load it some data. Whenever I want to try reset the password, it show error because I dont have table password_resets. What are the steps to be taken after install the Laravel actually.
Thanks
You don't need to create any table manually (and you shouldn't). In Laravel you have migrations that help you quickly create tables in your database and seeds (where you can put initial data to those tables).
In fresh Laravel installation you have 2 ready migrations (for creating users and password_resets tables). All you need to do is running your console, go to directory where you have your Laravel project and run:
php artisan migrate
to run those migrations. After running this command Laravel will create those 2 tables for you. Before, you need to have configured your database connection (look at config/database.php file)

Resources