0

Code:

{
    function setting($key) {
        $setting=Setting::where('key',$key)->first();
        $setting=json_decode($setting['value'],true); /* Error in this line */

        return $setting;
    }
}

Error Log :

1 D:\new\extremelab-master\test1\app\Helpers.php:148 Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Trying to access array offset on value of type null", "D:\new\extremelab-master\test1\app\Helpers.php", ["emails"])

2 D:\new\extremelab-master\test1\app\Providers\MailServiceProvider.php:29 setting("emails")

Panda
  • 6,955
  • 6
  • 40
  • 55
Shrimanta
  • 41
  • 8
  • It looks like `$setting` is null – Chris Haas Dec 18 '21 at 12:17
  • Wherever you are executing this function, You need to put condition first that If You are getting data from this Setting then only you will try to access their elements. It will give error If this function return blank array – KHIMAJI VALUKIYA Dec 18 '21 at 12:28
  • Does this answer your question? [Laravel - find by custom column or fail](https://stackoverflow.com/questions/29212982/laravel-find-by-custom-column-or-fail) – nice_dev Dec 18 '21 at 13:08
  • You have a function to retrieve a setting by key which assumes that any conceivable key will always have an associated setting. That's of course not true. – Álvaro González Dec 18 '21 at 19:06

2 Answers2

0

You probably have a settings table in your database with a column name emails. I am sure the emails column does not have the value you are interacting with. Try to put the required value there.

Hefaz
  • 526
  • 1
  • 8
  • 24
0

There is a problem in you code

❌ instead of $setting['value']

✔️ use $setting->value;

 function setting($key) {
        $setting=Setting::where('key',$key)->first();

        $setting=json_decode($setting['value'],true); /* Error in this line */

        return $setting;
    }