doulouxun6756
doulouxun6756
2017-04-18 13:03

更改活动日志表名称

已采纳

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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • douhuan6157 douhuan6157 4年前

    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

    点赞 评论 复制链接分享