Laravel 动态创建数据库表和一个 model 操作动态表名

Laravel ⋅ tytrock ⋅ at 2018-05-16 17:14:28 ⋅ 8465 Reads

动态创建数据库表

if(!Schema::hasTable('test')){
    Schema::create('test', function ($table) {
        $table->increments('id');
        $table->string('name'); 
    });
}


一个model操作指定的表名

$post = new Post();
$post->setTable('post_2018');


This topic has been mark as Excenllent Topic.
Total Reply Count: 0
    No comments~~
    • publish_typography
    • publish_markdown
    • 支持表情,使用方法请见 Emoji 自动补全来咯,可用的 Emoji 请见 :metal: :point_right: Emoji 列表 :star: :sparkles:
    • publish_image
    • publish_draft
    Ctrl+Enter