on-internet
← Community

Cannot use a scalar value as an array after using pluck()

Stack Overflow ·

I'm trying to send an array of my Model Role to Blade like this: public function create() { $roles = Role::pluck('name','id'); return view('admin.users.create', compact(['roles'])); } And on the Blade, I added this: <div class="form-group"> {!! Form::label('roles', 'Role:') !!} {!! Form::text('roles[]', $roles, null, ['multiple' => 'multiple', 'class' => 'form-control']) !!} </div> Now I get this error: ErrorException Cannot use a scalar value as an array on create.blade.php However, when I add {{ dd($roles) }}, I get this as result: Illuminate\Support\Collection {#1155 ▼ #items: array:1 [▼ 1

Comments

Sign in or sign up to comment and upvote.

No comments yet.