Характеристика событий модели журнала LogsActivity не работает на конкретной модели, возвращает BadMethodCallException ()

Привет я использовал spatie / Laravel-activitylog Версия 1.16 для Laravel 5.4.

Практически я использовал LogsActivity Признак, предоставленный в пакете для регистрации событий модели, и большая часть моей модели зарегистрированы правильно. За исключением одной модели, которую я создал ниже.

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Functions;
use Carbon;
use Spatie\Activitylog\Traits\LogsActivity;

class RoomClassServiceCharge extends Model
{
use LogsActivity;

protected $fillable = [
'room_class_id',
'service_charge_id',
'patient_finance_id',
'default_price'
];

protected static $logAttributes = [
'service_charge_name',
'patient_finance_name',
'default_price'
];

protected $appends = [
'service_charge_name',
'patient_finance_name'
];

protected $table = "roomclass_servicecharges";

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $guarded = [
'created_at',
'updated_at',
];

protected $dates = [
'created_at',
'updated_at',
];

// create/update the record from the passed $request
public function saveFromRequest($request)
{
$inputs = $request->all();

// compose the user data we will create
$data = [
'room_class_id' => $inputs['room_class_id'],
'service_charge_id' => $inputs['service_charge_id'],
'patient_finance_id' => $inputs['patient_finance_id'],
'default_price' => $inputs['default_price'],
];

$this->fill($data);

// insert/update record in db
$this->save();
}

public static function getRoomClassServiceChargeOptions($room_class_id)
{
$options = self::where('room_class_id', '=', $room_class_id)
->get()
->pluck('service_charge_name', 'id')
->all();

return $options;
}

public function getServiceChargeNameAttribute()
{
return $this->serviceCharge->name ?? '';
}

public function getPatientFinanceNameAttribute()
{
return $this->patientFinance->name ?? '';
}

public function serviceCharge()
{
return $this->belongsTo('App\Models\ServiceCharge');
}

public function roomClass()
{
return $this->belongsTo('App\Models\RoomClass');
}

public function patientFinance()
{
return $this->belongsTo('App\Models\PatientFinance');
}

protected static function boot()
{
parent::boot();
}

}

Всякий раз, когда выполняется какая-либо операция CRUD, она вернется BadMethodCallException Call to undefined method Illuminate\Database\Query\Builder::getFullnameAttribute() ошибка. Я не уверен, что является причиной этого, но я думаю, что пакет может быть подключен к другой модели, потому что getFullnameAttribute существует в другой модели или, может быть, потому что это имя модели и таблица похожи на сводную таблицу. Полный журнал ошибок приведен ниже

[2018-10-03 00:43:12] local.ERROR: BadMethodCallException: Call to undefined method Illuminate\Database\Query\Builder::getFullnameAttribute() in /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php:2445
Stack trace:
#0 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1254): Illuminate\Database\Query\Builder->__call('getFullnameAttr...', Array)
#1 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1374): Illuminate\Database\Eloquent\Builder->__call('getFullnameAttr...', Array)
#2 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(432): Illuminate\Database\Eloquent\Model->__call('getFullnameAttr...', Array)
#3 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(444): Illuminate\Database\Eloquent\Model->mutateAttribute('fullname', NULL)
#4 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(102): Illuminate\Database\Eloquent\Model->mutateAttributeForArray('fullname', NULL)
#5 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(900): Illuminate\Database\Eloquent\Model->attributesToArray()
#6 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php(230): Illuminate\Database\Eloquent\Model->toArray()
#7 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(900): Illuminate\Database\Eloquent\Model->relationsToArray()
#8 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Support/Collection.php(1616): Illuminate\Database\Eloquent\Model->toArray()
#9 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Support/Collection.php(46): Illuminate\Support\Collection->getArrayableItems(Object(App\Models\RoomClassServiceCharge))
#10 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Support/helpers.php(393): Illuminate\Support\Collection->__construct(Object(App\Models\RoomClassServiceCharge))
#11 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/spatie/laravel-activitylog/src/Traits/DetectsChanges.php(79): collect(Object(App\Models\RoomClassServiceCharge))
#12 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/spatie/laravel-activitylog/src/Traits/DetectsChanges.php(50): App\Models\RoomClassServiceCharge::logChanges(Object(App\Models\RoomClassServiceCharge))
#13 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/spatie/laravel-activitylog/src/Traits/LogsActivity.php(37): App\Models\RoomClassServiceCharge->attributeValuesToBeLogged('deleted')
#14 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(348): App\Models\RoomClassServiceCharge::Spatie\Activitylog\Traits\{closure}(Object(App\Models\RoomClassServiceCharge))
#15 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(199): Illuminate\Events\Dispatcher->Illuminate\Events\{closure}('eloquent.delete...', Array)
#16 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Events/Dispatcher.php(172): Illuminate\Events\Dispatcher->dispatch('eloquent.delete...', Array, false)
#17 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php(148): Illuminate\Events\Dispatcher->fire('eloquent.delete...', Object(App\Models\RoomClassServiceCharge))
#18 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(758): Illuminate\Database\Eloquent\Model->fireModelEvent('deleted', false)
#19 /mnt/c/Users/reyna/Workspaces/Projects/simrs/app/Http/Controllers/RoomClassServiceChargeController.php(73): Illuminate\Database\Eloquent\Model->delete()
#20 [internal function]: App\Http\Controllers\RoomClassServiceChargeController->remove('16')
#21 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(55): call_user_func_array(Array, Array)
#22 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(44): Illuminate\Routing\Controller->callAction('remove', Array)
#23 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Route.php(203): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(App\Http\Controllers\RoomClassServiceChargeController), 'remove')
#24 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Route.php(160): Illuminate\Routing\Route->runController()
#25 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Router.php(572): Illuminate\Routing\Route->run()
#26 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#27 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#28 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
#29 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#30 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(43): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#31 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Auth\Middleware\Authenticate->handle(Object(Illuminate\Http\Request), Object(Closure))
#32 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#33 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(65): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#34 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#35 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#36 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#37 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#38 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#39 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#40 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#41 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#42 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#43 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#44 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#45 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#46 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#47 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#48 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#49 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Router.php(574): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#50 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Router.php(533): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#51 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Router.php(511): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#52 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#53 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#54 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/barryvdh/laravel-debugbar/src/Middleware/Debugbar.php(51): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#55 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Barryvdh\Debugbar\Middleware\Debugbar->handle(Object(Illuminate\Http\Request), Object(Closure))
#56 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#57 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(30): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#58 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#59 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#60 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(30): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#61 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
#62 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#63 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#64 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))
#65 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#66 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(46): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#67 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(148): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#68 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#69 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#70 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#71 /mnt/c/Users/reyna/Workspaces/Projects/simrs/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#72 /mnt/c/Users/reyna/Workspaces/Projects/simrs/public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#73 {main}

Любое понимание или предложение по этому вопросу будет с благодарностью

0

Решение

Насколько я могу прочитать из трассировки стека, эта проблема не имеет прямого отношения ни к классу RoomClassServiceCharge, ни к журналу spatie / activity-log. (Смотрите строку трассировки стека # 7)

Есть ли у каких-либо связанных классов атрибут $ appends?

Атрибуты, перечисленные там, добавляются к представлению массива объекта. Увидеть https://laravel.com/docs/5.7/eloquent-serialization#appending-values-to-json для дополнительной информации.

Посмотрите на классы, которые имеют отношение к RoomClassServiceCharge, где-то есть $ appends, определенный без требуемой функции доступа.

0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]