Support the ongoing development of Laravel.io →
posted 8 years ago
Database

Hi fellas,

after updating to Laravel 5.4 I have received some weird errors that I don't know how to fix. It seems like it is an issue of retrieving the information from the database? Or maybe just assigning the value to the variable.

Here is the code I use:

namespace App\Providers;

use App\Setting;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use View;
use DB;

class SettingsServiceProvider extends ServiceProvider
{
    public function boot()
    {
        if(\DB::connection()->getDatabaseName() && Schema::hasTable('settings') && \DB::table('settings')->count()){

            $setting = new Setting;

            config()->set('website_desc', $setting->gets('general')->website_desc);
            config()->set('website_keywords', $setting->gets('general')->website_keywords);
        }
    }

    public function register()
    {
       // this approach worked before updating to 5.4
        view()->share('website_desc',config('website_desc'));
        view()->share('website_keywords',config('website_keywords'));
    }
}

my App/setting.php looks like this

namespace App;

use Illuminate\Database\Eloquent\Model;

class Setting extends Model
{
    protected $fillable = ['name','attributes'];

    public function gets($name){
        $attributes = $this->where('name',$name)->value('attributes');
        if($attributes){
            return json_decode($attributes);
        }
        return false;
    }
}

Can anyone see anything that became incompatible?

This is the a database entry of the table settings and the column attributes

{"website_name":"name","website_title":"title","website_desc":"description","website_keywords":"keywords","website_footer_text":"footer"}

The error I receive is that $website_desc and $website_keywords are undefined variables.

Any help would be greatly appreciate! Chris

Last updated 3 years ago.
0

Check to see if Laravel is returning it as an Array instead of an Object

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.