A
A
Alexey Sklyarov2018-10-26 23:54:41
Laravel
Alexey Sklyarov, 2018-10-26 23:54:41

How to return all field values ​​for him from the database when creating a user?

I'm trying to figure out the registration, there is such a method:

public function register(RegisterFormRequest $request)
    {
      $invite = $request->input('invite');
      $invite = \App\Invite::where('invite',$invite)->first();

      // Creating user
      $user = new User;
      $user->login = $request->login;
      $user->email = $request->email;
      $user->username = $request->name;
      $user->password = bcrypt($request->password);
      $user->invite_id = $invite->id;

      $user->save();


      // Закрепили инвайт за пользователем

      $invite->user_id = $user->id;
      $invite->save();

      return response([
          'status' => 'success',
          'data' => $user
      ], 200);
    }

After registration, an array with user data is returned, but only the data that I specify for registration is shown there, that is:
$user->login = $request->login;
      $user->email = $request->email;
      $user->username = $request->name;
      $user->password = bcrypt($request->password);
      $user->invite_id = $invite->id;

And how can you in an array $userin a fragment:
return response([
          'status' => 'success',
          'data' => $user
      ], 200);

add the required fields from the table (some are NULL by default), for example the field "avatar" and so on?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2018-10-27
@0example

$user->fresh()/$user->refresh()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question