cms icon indicating copy to clipboard operation
cms copied to clipboard

data(compact('settings')) - Undefined variable: settings

Open spoutnikfr opened this issue 6 years ago • 4 comments

On fresh install, trying to view Settings directly from menu :

ErrorException (E_NOTICE) compact(): Undefined variable: settings

in vendor/lavalite/framework/src/Litepie/Settings/Http/Controllers/SettingResourceController.php

spoutnikfr avatar Sep 25 '19 16:09 spoutnikfr

Me to, on fresh install.

ghost avatar Nov 06 '19 04:11 ghost

patched with public function index(SettingRequest $request) { $settings = Setting::all(); return $this->response->setMetaTitle(trans('settings::setting.names')) ->view('settings::index') ->data(compact('settings')) ->output(); }

$settings = Setting::all();

spoutnikfr avatar Nov 12 '19 22:11 spoutnikfr

Original:

    /**
     * Display a list of setting.
     *
     * @return Response
     */
    public function index(SettingRequest $request)
    {
        return $this->response->setMetaTitle(trans('settings::setting.names'))
            ->view('settings::index')
            ->data(compact('settings'))
            ->output();
    }

Fix:

     * Display a list of setting.
     *
     * @return Response
     */
    public function index(SettingRequest $request)
    {
        return $this->response->setMetaTitle(trans('settings::setting.names'))
            ->view('settings::index')
            ->data(Setting::all())
            ->output();
    }

PR: https://github.com/LavaLite/framework/pull/51

j3rrey avatar Feb 15 '20 15:02 j3rrey

I think it has to do with the $request variable. Creating an instance of the SettingRequest class with $request variable seem to return $request instead of $setting variable. Changing the $request variable to $settings variable on the class instance solves the problem.

MicVital avatar Apr 21 '20 03:04 MicVital