LavaLite / cms

Multilingual PHP CMS built with Laravel and bootstrap
https://lavalite.org
2.84k stars 966 forks source link

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

Open spoutnikfr opened 5 years ago

spoutnikfr commented 5 years ago

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

ghost commented 5 years ago

Me to, on fresh install.

spoutnikfr commented 5 years ago

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();

j3rrey commented 4 years ago

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

MicVital commented 4 years ago

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.