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
Check to see if Laravel is returning it as an Array instead of an Object
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community