How to convert database schema into Lumen API - laravel

I have such following Database Schema that I want to convert into Lumen API with migration, model and API. Since I am new to Lumen Laravel Framework so need experts help:

Lumen is the light weight stripped version of Laravel, that is why I rever to the Laravel documentation in this answer.
First step is to write migration files, see:
https://laravel.com/docs/8.x/migrations
after creating the migrations files you can migrate the schemas with:
php artisan migrate
The next step is to create models for the tables, see:
https://laravel.com/docs/8.x/eloquent#generating-model-classes
This is necessary to query the data from the database with Eloquent (ORM in Laravel).
The two steps above can be combined with the command:
php artisan make:model ModalName --migration
The next step is to create a controller, this class will be used as a layer between your view/api and the data models, see:
https://laravel.com/docs/8.x/controllers
Last step: After creating your logic, you can register the controller in your api routes file, see:
https://laravel.com/docs/8.x/routing
The routes file you are looking for is called: api.php
If the ORM isn't what you are looking for then you can also use the query builder:
https://lumen.laravel.com/docs/8.x/database

Related

How to create basic model structure using artisan?

I am new in Laravel and I want to create a model with all it's basic properties like fillable, table etc. using artisan.
I have explored some blogs but I have not found any way to create a model with basic fields. So, Is there any command to do it like we can do it in CodeIgniter 4?
There is no automatic way to create table fields using artisan, what you can do instead is create the following and modify it:
php artisan make:model Blog -mcr
Read more on model options: https://laravel.com/docs/9.x/eloquent#generating-model-classes
The above will create:
A model named "blog"
A migration file - this is where you can modify/add fields to the database
A resource controller named "BlogController"
For migrations, you need to edit your migration file that it generated, see the documentation on how to do this: https://laravel.com/docs/9.x/migrations#migration-structure
Once you finish you can run the command:
php artisan migrate
to push the changes of the migration file to the database.
Alternatively, you can always see what kind of options you have in artisan by doing:
php artisan make:model -help
And if you want to create everything related to the model, do the command:
php artisan make:model Blog -a
Generate a migration, seeder, factory, policy, resource controller,
and form request classes for the model

is there any model and database generation with column in laravel?

in ruby on rails, we can do
rails generate model note title body:text
to create:
model called Note
table called notes
column in notes table with name title as string
column in notes table with name body as text
is there any possible way to do this in laravel?
In Laravel we have artisan which has a lot of commands for performing common tasks such as Model, Controller and migration generation.
For your specific case you could do something like the following:
php artisan make:model Note -mc
The above would create a model in app/Models. The -mc flags tell artisan to also make a migration in the database/migrations directory and a controller in the app/Http/Controllers directory.
To add fields for your Note model, you will need to do that yourself in the migration file that was generated. Then you can use php artisan migrate to execute the new migration.
For other commands of artisan, just type php artisan in your console and you'll see a full list of commands.

Laravel automated view generation from models

In Laravel, I can create models and controllers automatically from the command line using
artisan
However, There is no command to generate views automatically based on the the model for CRUD operations. Wonder if there is a tool that would make this out of the box. I imagine this:
php artisan make:view model
and then I have all my views ready. I tried to search online but could not find a proper tool: LarvelCodeGenerator, and others...
Have you taken a look at Laravel View Generator.

lumen doesn't use the right database directory on migration

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.

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