LukeTowers / wn-easyaudit-plugin

Easily view and manage audit logs for models within your Winter CMS projects.
Other
17 stars 10 forks source link

Call to member function is null #2

Closed seanthepottingshed closed 5 years ago

seanthepottingshed commented 5 years ago

@LukeTowers

Excellent plugin!

However I'm having some issues when extending RainLab\Blog\Models\Category:

<?php

namespace ThePottingShed\Blog\Classes;

use Event;
use RainLab\Blog\Controllers\Categories;
use RainLab\Blog\Models\Category;

/**
 * Extend Blog Category.
 */
class ExtendBlogCategory
{
    /**
     * Create a New Instance.
     */
    public function __construct()
    {
        Category::extend(function ($model) {
            $model->implement[] = '@LukeTowers.EasyAudit.Behaviors.TrackableModel';
            $model->addDynamicProperty('trackableAllowDuplicates', false);
            $model->addDynamicProperty('trackableEvents', [
                'model.afterSave',
                'model.afterCreate',
                'model.afterFetch',
            ]);
            $model->addDynamicProperty('trackableEventNames', [
                'model.afterSave'   => 'updated',
                'model.afterCreate' => 'created',
                'model.afterFetch'  => 'viewed',
            ]);
            $model->addDynamicProperty('trackableEventDescriptions', [
                'model.afterSave'   => 'The model was updated',
                'model.afterCreate' => 'The model was created',
                'model.afterFetch'  => 'The model was viewed',
            ]);
        });
        Categories::extend(function ($controller) {
            $controller->implement[] = 'Backend.Behaviors.RelationController';
            $controller->addDynamicProperty('relationConfig', '$/luketowers/easyaudit/yaml/relation.activities.yaml');
        });
        Event::listen('backend.form.extendFields', function ($widget) {
            if ($widget->isNested) {
                return;
            }
            if (!$widget->getController() instanceof Categories) {
                return;
            }
            if (!$widget->model instanceof Category) {
                return;
            }
            $widget->addSecondaryTabFields([
                '_activities' => [
                    'type' => 'partial',
                    'path' => '$/luketowers/easyaudit/partials/field.activities.htm',
                    'tab'  => 'luketowers.easyaudit::lang.models.activity.label_plural',
                ],
            ]);
        });
    }
}

Called from plugin boot method eg:

<?php

namespace ThePottingShed\Blog;

use App;
use Event;
use System\Classes\PluginBase;
use ThePottingShed\Blog\Classes\ExtendBlogCategory;

/**
 * Blog.
 *
 * @author The Potting Shed <digital@thepottingsheddesign.com>
 */
class Plugin extends PluginBase
{
    /**
     * Require.
     *
     * @var array
     */
    public $require = [
        'LukeTowers.EasyAudit',
        'RainLab.Blog',
    ];

    /**
     * Plugin Details.
     *
     * @return array
     */
    public function pluginDetails()
    {
        return [
            'name'        => 'thepottingshed.blog::lang.plugin.name',
            'description' => 'thepottingshed.blog::lang.plugin.description',
            'homepage'    => 'https://github.com/thepottingshed/octobercms-blog-plugin',
            'author'      => 'The Potting Shed',
            'icon'        => 'icon-pencil',
        ];
    }

    /**
     * Boot.
     *
     * @return void
     */
    public function boot()
    {
        new ExtendBlogCategory();
    }
}
LukeTowers commented 5 years ago

@seanthepottingshed could you post a full stack trace?

seanthepottingshed commented 5 years ago

@LukeTowers

Sorry - will do.

seanthepottingshed commented 5 years ago
Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function getKey() on null in /Users/seandavidson/Sites/tps-base-theme/plugins/luketowers/easyaudit/classes/ActivityLogger.php:325
Stack trace:
#0 /Users/seandavidson/Sites/tps-base-theme/plugins/luketowers/easyaudit/classes/ActivityLogger.php(95): LukeTowers\EasyAudit\Classes\ActivityLogger->getHash()
#1 [internal function]: LukeTowers\EasyAudit\Classes\ActivityLogger->LukeTowers\EasyAudit\Classes\{closure}(Object(LukeTowers\EasyAudit\Models\Activity))
#2 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Support/Traits/Emitter.php(133): call_user_func_array(Object(Closure), Array)
#3 /Users/seandavidson/Sites/tps-base-theme/plugins/luketowers/easyaudit/traits/EventHelper.php(54): LukeTowers\EasyAudit\Classes\ActivityLogger->fireEvent('log', Array, true)
#4 /Users/seandavidson/Sites/tps-base-theme/plugins/luketowers/easyaudit/classes/ActivityLogger.php(169): LukeTowers\EasyAudit\Classes\ActivityLogger->fireCombinedEvent('luketowers.easy...', Array, true)
#5 /Users/seandavidson/Sites/tps-base-theme/plugins/luketowers/easyaudit/behaviors/TrackableModel.php(198): LukeTowers\EasyAudit\Classes\ActivityLogger->log()
#6 /Users/seandavidson/Sites/tps-base-theme/plugins/luketowers/easyaudit/behaviors/TrackableModel.php(162): LukeTowers\EasyAudit\Behaviors\TrackableModel->triggerModelActivity(Object(RainLab\Blog\Models\Category), 'model.afterFetc...')
#7 [internal function]: LukeTowers\EasyAudit\Behaviors\TrackableModel->LukeTowers\EasyAudit\Behaviors\{closure}()
#8 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Support/Traits/Emitter.php(133): call_user_func_array(Object(Closure), Array)
#9 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Database/Model.php(165): October\Rain\Database\Model->fireEvent('model.afterFetc...')
#10 [internal function]: October\Rain\Database\Model->October\Rain\Database\{closure}(Object(RainLab\Blog\Models\Category))
#11 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Events/Dispatcher.php(233): call_user_func_array(Object(Closure), Array)
#12 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Events/Dispatcher.php(197): October\Rain\Events\Dispatcher->dispatch('eloquent.fetche...', Array, false)
#13 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php(148): October\Rain\Events\Dispatcher->fire('eloquent.fetche...', Object(RainLab\Blog\Models\Category))
#14 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Database/Model.php(433): Illuminate\Database\Eloquent\Model->fireModelEvent('fetched', false)
#15 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(260): October\Rain\Database\Model->newFromBuilder(Object(stdClass))
#16 [internal function]: Illuminate\Database\Eloquent\Builder->Illuminate\Database\Eloquent\{closure}(Object(stdClass))
#17 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(261): array_map(Object(Closure), Array)
#18 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1477): Illuminate\Database\Eloquent\Builder->hydrate(Array)
#19 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Extension/ExtendableTrait.php(411): Illuminate\Database\Eloquent\Model->__call('hydrate', Array)
#20 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Database/Model.php(635): October\Rain\Database\Model->extendableCall('hydrate', Array)
#21 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(481): October\Rain\Database\Model->__call('hydrate', Array)
#22 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(465): Illuminate\Database\Eloquent\Builder->getModels(Array)
#23 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(360): Illuminate\Database\Eloquent\Builder->get(Array)
#24 /Users/seandavidson/Sites/tps-base-theme/plugins/thepottingshed/blog/classes/ContentBlocks.php(165): Illuminate\Database\Eloquent\Model::all()
#25 /Users/seandavidson/Sites/tps-base-theme/plugins/thepottingshed/blog/classes/ContentBlocks.php(134): ThePottingShed\Blog\Classes\ContentBlocks::getCategories()
#26 /Users/seandavidson/Sites/tps-base-theme/plugins/thepottingshed/blog/classes/ContentBlocks.php(32): ThePottingShed\Blog\Classes\ContentBlocks::getLatestNewsArticlesByCategoryContentBlock()
#27 /Users/seandavidson/Sites/tps-base-theme/plugins/thepottingshed/blog/init.php(22): ThePottingShed\Blog\Classes\ContentBlocks::get()
#28 [internal function]: System\Classes\PluginManager->{closure}(Array)
#29 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Events/Dispatcher.php(233): call_user_func_array(Object(Closure), Array)
#30 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Events/Dispatcher.php(197): October\Rain\Events\Dispatcher->dispatch('contentBlocks.r...', Array, false)
#31 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(221): October\Rain\Events\Dispatcher->fire('contentBlocks.r...', Array)
#32 /Users/seandavidson/Sites/tps-base-theme/plugins/thepottingshed/contentblocks/classes/ContentBlocksRegistry.php(71): Illuminate\Support\Facades\Facade::__callStatic('fire', Array)
#33 /Users/seandavidson/Sites/tps-base-theme/plugins/thepottingshed/contentblocks/classes/ExtendContentBlockModels.php(37): ThePottingShed\ContentBlocks\Classes\ContentBlocksRegistry->__construct(true)
#34 /Users/seandavidson/Sites/tps-base-theme/plugins/thepottingshed/contentblocks/classes/ExtendContentBlockModels.php(25): ThePottingShed\ContentBlocks\Classes\ExtendContentBlockModels->extendModels()
#35 /Users/seandavidson/Sites/tps-base-theme/plugins/thepottingshed/contentblocks/Plugin.php(144): ThePottingShed\ContentBlocks\Classes\ExtendContentBlockModels->__construct()
#36 /Users/seandavidson/Sites/tps-base-theme/modules/system/Classes/PluginManager.php(293): ThePottingShed\ContentBlocks\Plugin->boot()
#37 /Users/seandavidson/Sites/tps-base-theme/modules/system/Classes/PluginManager.php(275): System\Classes\PluginManager->bootPlugin(Object(ThePottingShed\ContentBlocks\Plugin))
#38 /Users/seandavidson/Sites/tps-base-theme/modules/system/ServiceProvider.php(93): System\Classes\PluginManager->bootAll()
#39 [internal function]: System\ServiceProvider->boot()
#40 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
#41 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#42 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(October\Rain\Foundation\Application), Array, Object(Closure))
#43 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Container/Container.php(549): Illuminate\Container\BoundMethod::call(Object(October\Rain\Foundation\Application), Array, Array, NULL)
#44 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(792): Illuminate\Container\Container->call(Array)
#45 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(775): Illuminate\Foundation\Application->bootProvider(Object(System\ServiceProvider))
#46 [internal function]: Illuminate\Foundation\Application->Illuminate\Foundation\{closure}(Object(System\ServiceProvider), 23)
#47 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(776): array_walk(Array, Object(Closure))
#48 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php(17): Illuminate\Foundation\Application->boot()
#49 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(213): Illuminate\Foundation\Bootstrap\BootProviders->bootstrap(Object(October\Rain\Foundation\Application))
#50 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(162): Illuminate\Foundation\Application->bootstrapWith(Array)
#51 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(146): Illuminate\Foundation\Http\Kernel->bootstrap()
#52 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#53 /Users/seandavidson/Sites/tps-base-theme/index.php(43): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#54 /Users/seandavidson/.composer/vendor/laravel/valet/server.php(147): require('/Users/seandavi...')
seanthepottingshed commented 5 years ago

@LukeTowers

The same error is thrown for other plugins when logged out of the backend:

Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function getKey() on null in /Users/seandavidson/Sites/tps-base-theme/plugins/luketowers/easyaudit/classes/ActivityLogger.php:325
Stack trace:
#0 /Users/seandavidson/Sites/tps-base-theme/plugins/luketowers/easyaudit/classes/ActivityLogger.php(95): LukeTowers\EasyAudit\Classes\ActivityLogger->getHash()
#1 [internal function]: LukeTowers\EasyAudit\Classes\ActivityLogger->LukeTowers\EasyAudit\Classes\{closure}(Object(LukeTowers\EasyAudit\Models\Activity))
#2 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Support/Traits/Emitter.php(133): call_user_func_array(Object(Closure), Array)
#3 /Users/seandavidson/Sites/tps-base-theme/plugins/luketowers/easyaudit/traits/EventHelper.php(54): LukeTowers\EasyAudit\Classes\ActivityLogger->fireEvent('log', Array, true)
#4 /Users/seandavidson/Sites/tps-base-theme/plugins/luketowers/easyaudit/classes/ActivityLogger.php(169): LukeTowers\EasyAudit\Classes\ActivityLogger->fireCombinedEvent('luketowers.easy...', Array, true)
#5 /Users/seandavidson/Sites/tps-base-theme/plugins/luketowers/easyaudit/behaviors/TrackableModel.php(198): LukeTowers\EasyAudit\Classes\ActivityLogger->log()
#6 /Users/seandavidson/Sites/tps-base-theme/plugins/luketowers/easyaudit/behaviors/TrackableModel.php(162): LukeTowers\EasyAudit\Behaviors\TrackableModel->triggerModelActivity(Object(ThePottingShed\Affiliations\Models\Affiliate), 'model.afterFetc...')
#7 [internal function]: LukeTowers\EasyAudit\Behaviors\TrackableModel->LukeTowers\EasyAudit\Behaviors\{closure}()
#8 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Support/Traits/Emitter.php(133): call_user_func_array(Object(Closure), Array)
#9 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Database/Model.php(165): October\Rain\Database\Model->fireEvent('model.afterFetc...')
#10 [internal function]: October\Rain\Database\Model->October\Rain\Database\{closure}(Object(ThePottingShed\Affiliations\Models\Affiliate))
#11 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Events/Dispatcher.php(233): call_user_func_array(Object(Closure), Array)
#12 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Events/Dispatcher.php(197): October\Rain\Events\Dispatcher->dispatch('eloquent.fetche...', Array, false)
#13 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasEvents.php(148): October\Rain\Events\Dispatcher->fire('eloquent.fetche...', Object(ThePottingShed\Affiliations\Models\Affiliate))
#14 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Database/Model.php(433): Illuminate\Database\Eloquent\Model->fireModelEvent('fetched', false)
#15 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(260): October\Rain\Database\Model->newFromBuilder(Object(stdClass))
#16 [internal function]: Illuminate\Database\Eloquent\Builder->Illuminate\Database\Eloquent\{closure}(Object(stdClass))
#17 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(261): array_map(Object(Closure), Array)
#18 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1477): Illuminate\Database\Eloquent\Builder->hydrate(Array)
#19 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Extension/ExtendableTrait.php(411): Illuminate\Database\Eloquent\Model->__call('hydrate', Array)
#20 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Database/Model.php(635): October\Rain\Database\Model->extendableCall('hydrate', Array)
#21 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(481): October\Rain\Database\Model->__call('hydrate', Array)
#22 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(465): Illuminate\Database\Eloquent\Builder->getModels(Array)
#23 /Users/seandavidson/Sites/tps-base-theme/plugins/thepottingshed/affiliations/components/AffiliateList.php(50): Illuminate\Database\Eloquent\Builder->get()
#24 /Users/seandavidson/Sites/tps-base-theme/plugins/thepottingshed/affiliations/components/AffiliateList.php(40): ThePottingShed\Affiliations\Components\AffiliateList->loadAffiliateList()
#25 /Users/seandavidson/Sites/tps-base-theme/modules/cms/Classes/CmsCompoundObject.php(172): ThePottingShed\Affiliations\Components\AffiliateList->onRun()
#26 /Users/seandavidson/Sites/tps-base-theme/modules/cms/Classes/Controller.php(1079): Cms\Classes\CmsCompoundObject->runComponents()
#27 /Users/seandavidson/Sites/tps-base-theme/modules/cms/Twig/Extension.php(102): Cms\Classes\Controller->renderPartial('affiliateList', Array, true)
#28 /Users/seandavidson/Sites/tps-base-theme/storage/cms/twig/24/24b1cfac644a6f6ef7fe9271f2d0a80cff3f07ad543c07a68e4b3d1eb5bfa6d8.php(42): Cms\Twig\Extension->partialFunction('template/footer', Array, true)
#29 /Users/seandavidson/Sites/tps-base-theme/vendor/twig/twig/lib/Twig/Template.php(386): __TwigTemplate_bb9d045a333b7f6100cdfae65ddf74856571317b33475a7ee2124940e87b2ca2->doDisplay(Array, Array)
#30 /Users/seandavidson/Sites/tps-base-theme/vendor/twig/twig/lib/Twig/Template.php(363): Twig_Template->displayWithErrorHandling(Array, Array)
#31 /Users/seandavidson/Sites/tps-base-theme/vendor/twig/twig/lib/Twig/Template.php(371): Twig_Template->display(Array)
#32 /Users/seandavidson/Sites/tps-base-theme/modules/cms/Classes/Controller.php(434): Twig_Template->render(Array)
#33 /Users/seandavidson/Sites/tps-base-theme/modules/cms/Classes/Controller.php(224): Cms\Classes\Controller->runPage(Object(Cms\Classes\Page))
#34 /Users/seandavidson/Sites/tps-base-theme/modules/cms/Classes/CmsController.php(50): Cms\Classes\Controller->run('favicon.ico')
#35 [internal function]: Cms\Classes\CmsController->run('favicon.ico')
#36 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): call_user_func_array(Array, Array)
#37 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction('run', Array)
#38 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Route.php(212): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Cms\Classes\CmsController), 'run')
#39 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Route.php(169): Illuminate\Routing\Route->runController()
#40 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Router.php(658): Illuminate\Routing\Route->run()
#41 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#42 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(41): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#43 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
#44 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#45 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#46 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#47 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#48 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(63): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#49 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#50 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#51 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#52 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#53 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#54 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(66): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#55 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#56 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#57 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#58 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Router.php(660): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#59 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Router.php(635): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#60 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Router.php(601): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
#61 /Users/seandavidson/Sites/tps-base-theme/vendor/october/rain/src/Router/CoreRouter.php(20): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#62 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(176): October\Rain\Router\CoreRouter->dispatch(Object(Illuminate\Http\Request))
#63 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(30): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#64 /Users/seandavidson/Sites/tps-base-theme/plugins/thepottingshed/pjax/middleware/Pjax.php(24): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#65 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): ThePottingShed\Pjax\Middleware\Pjax->handle(Object(Illuminate\Http\Request), Object(Closure))
#66 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#67 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(46): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#68 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#69 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#70 /Users/seandavidson/Sites/tps-base-theme/plugins/vdlp/redirect/classes/RedirectMiddleware.php(62): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#71 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Vdlp\Redirect\Classes\RedirectMiddleware->handle(Object(Illuminate\Http\Request), Object(Closure))
#72 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php(53): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#73 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(102): Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#74 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(151): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#75 /Users/seandavidson/Sites/tps-base-theme/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(116): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#76 /Users/seandavidson/Sites/tps-base-theme/index.php(43): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#77 /Users/seandavidson/.composer/vendor/laravel/valet/server.php(147): require('/Users/seandavi...')
#78 {main}
LukeTowers commented 5 years ago

@seanthepottingshed should be fixed now

seanthepottingshed commented 5 years ago

@LukeTowers

Sorry to revisit this after so long, got massively waylaid:

 \RainLab\Blog\Models\Category::extend(function ($model) {
    /**
     * Implement `LukeTowers.EasyAudit` plugin.
     */
    $model->implement[] = '@LukeTowers.EasyAudit.Behaviors.TrackableModel';
    $model->addDynamicProperty('trackableAllowDuplicates', false);
    $model->addDynamicProperty('trackableEvents', [
        'model.afterSave',
        'model.afterCreate',
    ]);
    $model->addDynamicProperty('trackableEventNames', [
        'model.afterSave'   => 'updated',
        'model.afterCreate' => 'created',
    ]);
    $model->addDynamicProperty('trackableEventDescriptions', [
        'model.afterSave'   => 'The model was updated',
        'model.afterCreate' => 'The model was created',
    ]);
});

When updating everything is OK, however when creating it throws the following error:

"Unexpected type of array when attempting to save attribute "trackableEvents"
LukeTowers commented 5 years ago

@seanthepottingshed you need to add those dynamic values to the purgeable property to prevent them from being saved. If the model you're extending already uses the Purgeable trait you just have to add the properties by calling addPurgeable() or you can just implement the Purgeable behavior (https://octobercms.com/docs/database/behaviors#purgeable) to have it do that for you automatically.

seanthepottingshed commented 5 years ago

@LukeTowers

Makes total sense, I feel at one with the code now.