doulouxun6756
doulouxun6756
2017-04-18 13:03
浏览 63
已采纳

更改活动日志表名称

I installed spatie/activitylog for logging user activity,

the default table name in this package is activity_log I want change the table name to users_activity_log

I created a model and named Activity but not work:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Models;

class Activity extends Model
{
    //
    protected $table = "user_activity_log";
}

How can I do it?

图片转代码服务由CSDN问答提供 功能建议

我安装了 spatie / activitylog

此包中的默认表名是 activity_log 我想将表名更改为 users_activity_log

我创建了一个模型并命名为 Activity 但不起作用:

 &lt;?php 
 
namespace App; 
 
use Illuminate \ Database \ Eloquent \ Model; 
use Spatie \ Activitylog \ Models; 
 
class Activity扩展Model 
 {
 // 
 protected $ table  =“user_activity_log”; 
} 
   
 
 

我该怎么办?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douhuan6157
    douhuan6157 2017-04-18 13:22
    已采纳

    I found the solution,

    1- Create a model : php artisan make:model Activity

    2- put this code in your model (change $table with your table name):

    <?php
    
    namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    
    class Activity extends \Spatie\Activitylog\Models\Activity
    {
        //
        protected $table = "user_activity_log";
    }
    

    3- publish the logactivity config file:

    php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="config"
    

    4- change the activity_model in laravel-activitylog.php :

    'activity_model' => \App\Activity::class
    

    DON'T FORGET to change table name in migration file

    Thanks to @devk

    点赞 评论

相关推荐