class xxx 包含 1 个抽象方法,因此必须声明为抽象方法或实现其余方法 App\Models\xxx::getActivitylogOptions
class xxx contains 1 abstract method and must therefore be declared abstract or implement the remaining methods App\Models\xxx::getActivitylogOptions
您好,我正在使用 Laravel-activitylog,当我尝试将火车添加到模型时,出现此错误
Class App\Models\Setting contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (App\Models\Setting::getActivitylogOptions)
这是我所有的模型代码
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Astrotomic\Translatable\Translatable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Astrotomic\Translatable\Contracts\Translatable as TranslatableContract;
use Spatie\Activitylog\Traits\LogsActivity;
class Setting extends Model
{
use Translatable,SoftDeletes;
use LogsActivity;
public $translatedAttributes = ['name', 'slogan', 'description', 'summary', 'address'];
protected $fillable = ['id', 'logo', 'favicon', 'phone', 'email', 'facebook', 'twitter', 'instagram', 'created_at', 'updated_at'];
// protected static $logAttributes = ['name', 'logo'];
public static function check()
{
$setting = Self::all();
if(count($setting)<1)
{
$arrayName = array();
$arrayName['id']= 1;
foreach(config("app.languages") as $key => $language)
{
$arrayName[$key]['name'] = $language;
$arrayName[$key]['description'] = $language;
}
Self::create($arrayName);
}
return $setting = Self::where('id','1')->first();
}
}
看起来您正在使用 laravel-activitylog 的第 4 版,在这种情况下您应该添加:
use Spatie\Activitylog\LogOptions;
和getActivitylogOptions()方法,例如:
public function getActivitylogOptions()
{
return LogOptions::defaults()
-> logOnly(['text'])
-> logOnlyDirty()
-> dontSubmitEmptyLogs();
}
如果你使用 PHP 8 不要忘记声明 return 类型:
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults();
}
更多信息在这里:https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/logging-model-events
对于你在代码中使用的格式,你也可以使用以前的版本,在 composer 中指出:
“spatie/laravel-activitylog”:“^3”,并遵循此文档:https://spatie.be/docs/laravel-activitylog/v3/introduction
您好,我正在使用 Laravel-activitylog,当我尝试将火车添加到模型时,出现此错误
Class App\Models\Setting contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (App\Models\Setting::getActivitylogOptions)
这是我所有的模型代码
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Astrotomic\Translatable\Translatable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Astrotomic\Translatable\Contracts\Translatable as TranslatableContract;
use Spatie\Activitylog\Traits\LogsActivity;
class Setting extends Model
{
use Translatable,SoftDeletes;
use LogsActivity;
public $translatedAttributes = ['name', 'slogan', 'description', 'summary', 'address'];
protected $fillable = ['id', 'logo', 'favicon', 'phone', 'email', 'facebook', 'twitter', 'instagram', 'created_at', 'updated_at'];
// protected static $logAttributes = ['name', 'logo'];
public static function check()
{
$setting = Self::all();
if(count($setting)<1)
{
$arrayName = array();
$arrayName['id']= 1;
foreach(config("app.languages") as $key => $language)
{
$arrayName[$key]['name'] = $language;
$arrayName[$key]['description'] = $language;
}
Self::create($arrayName);
}
return $setting = Self::where('id','1')->first();
}
}
看起来您正在使用 laravel-activitylog 的第 4 版,在这种情况下您应该添加:
use Spatie\Activitylog\LogOptions;
和getActivitylogOptions()方法,例如:
public function getActivitylogOptions()
{
return LogOptions::defaults()
-> logOnly(['text'])
-> logOnlyDirty()
-> dontSubmitEmptyLogs();
}
如果你使用 PHP 8 不要忘记声明 return 类型:
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults();
}
更多信息在这里:https://spatie.be/docs/laravel-activitylog/v4/advanced-usage/logging-model-events
对于你在代码中使用的格式,你也可以使用以前的版本,在 composer 中指出: “spatie/laravel-activitylog”:“^3”,并遵循此文档:https://spatie.be/docs/laravel-activitylog/v3/introduction