Crinsane / LaravelShoppingcart

A simple shopping cart implementation for Laravel
MIT License
3.66k stars 1.72k forks source link

Error storing data in DB #487

Open n-osennij opened 6 years ago

n-osennij commented 6 years ago

Apache 7.2 PHP 7.2 MariaDB 10.2 Laravel 5.5.42 gloudemans/shoppingcart 2.5.0

In my CartCotroller I have next

public function __construct()
{
    $this->middleware('auth');
    $this->middleware(function ($request, $next) {
        Cart::restore(Auth::user()->id);
        return $next($request);
    });
}

public function __destruct()
{
    Cart::store(Auth::user()->id);
}

Data is not saving to shoppingcart table. In content field I have only part next

O:29:"Illuminate\Support\Collection":1:{s:8:"

Only this piece of code. No more. As result data not restored from DB

rariteth commented 6 years ago

This is possible because Auth::user() is null while controller destructing, maybe. Но это не точно ))

n-osennij commented 6 years ago

@rariteth No. If try this

public function __destruct()
{
    dd(Auth::user()->id);
    Cart::store(Auth::user()->id);
}

I can see id of my user at the page. So Auth::user() not null while controller destructing

public function __destruct()
{
//    dd(Auth::user()->id);
    dd(Cart::content());
    Cart::store(Auth::user()->id);
}

Cart data I can see too.

rariteth commented 6 years ago

Try this: \Log::debug(\Auth::user()->id);

to be completely sure

rariteth commented 6 years ago

Unfortunately this is big deal to save Cart items and restore every request. Why cart items is deleted while restoring? I thing is it bug.

n-osennij commented 6 years ago

\Log::debug(\Auth::user()->id); return null

Hmm... What can I do with it?

This is very strange, because in DB in field identefer I can see usser id. Or if I do next - Cart::store(Auth::user()); I can see all user data in DB in field identefer

rariteth commented 6 years ago

If you testing through dd your session is alive! Its a magic )))

my ugly code maybe helps you - https://pastebin.com/DEzC5xsu

n-osennij commented 6 years ago

@rariteth I think need to replace all serialize in this repo to json_encode and unserialize to json_decode