dimanche 10 septembre 2017

Laravel 5 Async Database Transaction?

Odd issue here, I have a view content.home that relies on the authenticated user's User model to resolve and be passed to it.

Before the User model is ready, I have a simple function in which I pass a name to the authenticated user's User model.

That code is below, including the view return:

    public function name()
    {
    $input = Input::all();
    $name = $input['name'];
    if(strlen($name)>2) //some validation
    {
    $user = User::where('id',Auth::id())->first();
    $user->name = $name;
    $user->save();
    return view('content.home')->with('user', Auth::user());        
    }
    }

My problem is, when I return the view I don't have the user's name. As soon as I refresh the page, it appears. Other user data provided by Auth::user() is there, but not the name. How can that be when I just saved it? It isn't NULL, again if I refresh the page right away it shows up.

I'm getting the name in the blade view like so:



Is save() async? I don't think so. Is there some latency?

How can I make sure that the model being passed is properly resolved?

Thank you!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire