php - Laravel 5 Async Database Transaction? -
odd issue here, have view content.home relies on authenticated user's user model resolve , passed it.
before user model ready, have simple function in pass name authenticated user's user model.
that code below, including 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 return view don't have user's name. refresh page, appears. other user data provided auth::user() there, not name. how can when saved it? isn't null, again if refresh page right away shows up.
i'm getting name in blade view so:
{{$user->name}} is save() async? don't think so. there latency?
how can make sure model being passed resolved?
thank you!
answering in case has similar issue:
the reason failed without refresh there kind of cache on auth::user().
when pass $user saved rather auth::user(), though same user, works.
so change return view('content.home')->with('user', auth::user());
to
return view('content.home')->with('user', $user);
Comments
Post a Comment