简体   繁体   English

如何将数据库模式转换为 Lumen API

[英]How to convert database schema into Lumen API

I have such following Database Schema that I want to convert into Lumen API with migration, model and API.我有这样的以下数据库模式,我想通过迁移、model 和 API 将其转换为 Lumen API。 Since I am new to Lumen Laravel Framework so need experts help:由于我是 Lumen Laravel 框架的新手,所以需要专家帮助:

在此处输入图像描述

Lumen is the light weight stripped version of Laravel, that is why I rever to the Laravel documentation in this answer. Lumen 是 Laravel 的轻量级剥离版本,这就是为什么我在此答案中参考 Laravel 文档的原因。

First step is to write migration files, see:第一步是编写迁移文件,见:

https://laravel.com/docs/8.x/migrations 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 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).这是使用 Eloquent(Laravel 中的 ORM)从数据库中查询数据所必需的。

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:下一步是创建一个 controller,这个 class 将用作视图/api 和数据模型之间的层,请参阅:

https://laravel.com/docs/8.x/controllers https://laravel.com/docs/8.x/controllers

Last step: After creating your logic, you can register the controller in your api routes file, see:最后一步:创建逻辑后,您可以在 api 路由文件中注册 controller,请参阅:

https://laravel.com/docs/8.x/routing https://laravel.com/docs/8.x/routing

The routes file you are looking for is called: api.php您正在查找的路由文件称为: api.php


If the ORM isn't what you are looking for then you can also use the query builder:如果 ORM 不是您正在寻找的,那么您也可以使用查询生成器:

https://lumen.laravel.com/docs/8.x/database https://lumen.laravel.com/docs/8.x/database

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM