Answer the question
In order to leave comments, you need to log in
How to retrieve data from database?
Good afternoon. I'm starting to learn laravel, tell me how to correctly add tables to display data from the database there is such a code
$user = User::where('id', Auth::user()->id)->first();
$user->money = $user->money - $r->amount;
$user->save();
DB::table('withdraw')->insertGetId(['user_id' => Auth::user()->id, 'system' => $r->currency, 'wallet' => $r->purse ,'amount' => $r->amount]);
return json_encode($r->amount);
}
}
Answer the question
In order to leave comments, you need to log in
auth()->user()
and so returns you an instance of your user. Why are you asking him again?
It's also not clear what to output. $r is defined somewhere above, this piece of code is not here.
All you have done is change the user and insert into the table.
Use MOdel for insert, not DB. Either use one approach rather than kneading everything.
I also advise you to use the debugbar for development
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question