3

I am create complaint For that while inserting department for their complaint I am using pluck() method to retrieve data from department table and display complaint in select dropdown as array but the problem is it is not working as it says

Array to string conversion (View: C:\xampp\htdocs\test\resources\views\complaint\create.blade.php)

ComplaintController

 $department = Department::pluck('name','id')->all();

    return view('complaint.create',compact('department'));

create.blade.php

<strong>Department : </strong>
{!! Form::select('dep_id',$department,null,['class'=>'form-control']) !!}

Please help!

Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109
story ks
  • 855
  • 1
  • 16
  • 39

2 Answers2

1

If it is not working try this:-

$department = Department::select('id','name')->get();
return view('complaint.create')->with(compact('department'));

Now your view like this:-

<strong>Department : </strong>
<select class="form-control" name="any-name">
@foreach($department as $dept)
 <option value="{{$dept->id}}">{{$dept->name}}</option>
@endforeach

Hope it helps!

kunal
  • 4,122
  • 12
  • 40
  • 75
-1
{!! Form::select('dep_id',$department,old('dep_id'),['class'=>'form-control', 'placeholder'=>'Select Any name']) !!}
Inzimam Tariq IT
  • 6,548
  • 8
  • 42
  • 69