【发布时间】:2021-08-23 13:17:28
【问题描述】:
我使用这个命令生成了一个模型:
php artisan make:model Notification
模型文件如下所示:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
/**
* App\Models\Notification
*
* @property int $id
* @property int|null $address_id
* @property string $business_name
* @property string $legal_structure
* @property string|null $siret_number
* @property string|null $rna_number
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @mixin \Eloquent
*/
class Notification extends Model
{
/**
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $guarded = ['id'];
}
然后我使用 make migration 命令在数据库中创建模型的表,但它没有返回任何要迁移的内容,也没有创建任何表
【问题讨论】:
-
不用单独执行命令,可以在制作模型时生成迁移,只需传递
-m选项即可;php artisan make:model -m Notification。有关所有选项的列表,您可以检查 ModelMakeCommand 类上的getOptions方法。 -
之后如何将模型属性添加到表格中?
-
关于模型和迁移如何工作的一切都在官方Laravel documentation 中有很好的记录。文档范围从 Laravel v4.2 到 v8.x。我建议通读它以更好地理解框架。
标签: php laravel artisan-migrate