Laravel - Set global variable from settings table

前端 未结 3 1459
渐次进展
渐次进展 2020-12-13 22:52

I\'m trying to store all my settings from my settings table into a global variable, but I\'m stucked now(I have no idea what\'s the next step), this is my actua

3条回答
  •  伪装坚强ぢ
    2020-12-13 23:28

    You can store the data in the database just like you do it normally in Laravel. \App\Setting::create(), \App\Setting::new() and other methods.

    For using the values in blade, you can do {{\App\Setting::where('name','title')->pluck('value')}}

    And, you can also use scopes for this.

    class Setting extends Model
    {
        public function scopeFor($query, $settingName)
        {
            return $query->where('name', $settingName);
        }
    }
    

    then you could use \App\Setting::for('title')->pluck('value')

提交回复
热议问题