P
P
Pavel2018-09-25 14:30:55
Laravel
Pavel, 2018-09-25 14:30:55

Why empty $this inside the model?

Hello. Faced with the fact that after transferring to another server, the application stopped working. Found out that none of the methods of getting dependencies works, because. $this contains an empty model.
For example, one of the methods of the User class

public function dialogs()
    {
        dd($this);
        return $this->belongsToMany('App\Models\Dialog', 'dialog_user', 'userId', 'dialogId');
    }

on the old server in $this is the user
5baa1c0ae8d18939778039.png
on the new one - an empty object
5baa1c48ebf5e554699009.png
in which direction to dig?
UPD.
Controller method
public function getDialogs()
    {
        $user = Auth::user();
        $dialogs = $this->dialogService->getDialogs($user);
        return response()->json($dialogs);
    }

dialogService->getDialogs()
public function getDialogs(User $user)
    {
        $user->load(['dialogs' => function($query) {
            $query->latest('updated_at');
        }]);
        if (!count($user->dialogs)) {
            $responseHelper = new SendJsonResponse();
            $responseHelper->sendWithError('no_dialogs');
        }
        
        return $user->dialogs;
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vism, 2018-09-25
@vism

Because you have it empty, that's all.
No data received - no data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question