drehimself / laravel-ecommerce-example

Code for YouTube series on building a Laravel E-Commerce application.
https://www.youtube.com/watch?v=o5PWIuDTgxg&list=PLEhEHUEU3x5oPTli631ZX9cxl6cU_sDaR
1.02k stars 585 forks source link

ErrorException Trying to access array offset on value of type null #98

Closed Shayboniyshoh closed 4 years ago

Shayboniyshoh commented 4 years ago

public function handle($event)

{

    $couponName = session()->get('coupon')['name'];

    if ($couponName) {

        $coupon = Coupon::where('code', $couponName)->first();

        dispatch_now(new UpdateCoupon($coupon));

    }

}

I have following error when I click to "Add To Cart" button: ErrorException Trying to access array offset on value of type null.

it points me to the following line of code which I pasted above, and it is the peace of code inside CardUpdateListener.php:$couponName = session()->get('coupon')['name'];

Martin-1182 commented 4 years ago

$couponName = session()->get('coupon')['name'] ?? null;