dtpngq3378499 2019-07-28 17:16
浏览 280

使用Slim上的Illuminate \ Database \ Eloquent \ Model定义的模型自动创建数据库表

I'm doing the following tutorial with uses the Slim PHP micro framework:

https://www.cloudways.com/blog/using-eloquent-orm-with-slim/

where I have the following model:

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model{
   protected $table = 'users';
   protected $fillable = ['name','email','password'];
}
?>

On that tutorial they say we need to run the following SQL query to create the corresponding table:

CREATE TABLE `users` (
 `id` int(11) NOT NULL,
 `name` varchar(250) NOT NULL,
 `email` varchar(250) NOT NULL,
 `password` varchar(250) NOT NULL,
 `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

The point is that in my opinion, we should be able to skip that last step since all the necessary information is on the model.

For example, on Laravel you can achieve this by running the following command:

php artisan migrate

Any idea how to do that?

Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 sub地址DHCP问题
    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大