L
L
lompas232018-09-04 00:01:15
MySQL
lompas23, 2018-09-04 00:01:15

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);
    }

  }

how to add your own 3 more fields

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vyacheslav Barsukov, 2018-09-04
@slavabars

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 question

Ask a Question

731 491 924 answers to any question