1

I'm trying to pass trough form dropdown selection but I can't pass array(the rest of the form is using objects. This is my code

Controller

$var->user = $request->users->id;

view

{!! Form::select('users', $users,null, ['placeholder' => 'Pick a user']) !!}

One solution is converting array to object using eloquent, how can that be done

OunknownO
  • 1,186
  • 3
  • 21
  • 41

2 Answers2

1

If you want to get selected user's ID, I guess you need to do this:

$request->users

You're getting "Trying to get property of non-object" error, because $request->users is not an object.

Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
0

If you want to get the user list you can follow this:

In Controller:

$user_id = UserModel::lists('username','id')->all();

"usename" and "id" is user-table fields.you can replace any other fields which you will show in user list.

In view:

{!! Form::select('user_id', $user_id,Input::old('user_id'),['placeholder'=>'select  user']) !!}
tanvirjahan
  • 164
  • 1
  • 1
  • 8