0
votes

When i run my project, i get the error

Object of class Illuminate\Support\Collection could not be converted to int

pointing to the code line

$classes =['0'=>'All']+ClassModel::pluck('name','code');

How can i get this solved?

PS: Laravel Beginner

Controller

public function show()
    {
        $selectedClass = Input::get('class',0);
        $classes =['0'=>'All']+ClassModel::pluck('name','code');
        if($selectedClass){
            $Subjects=  DB::table('Subject')
                ->join('Class', 'Subject.class', '=', 'Class.code')
                ->select('Subject.id', 'Subject.code','Subject.name','Subject.type', 'Subject.subgroup','Subject.stdgroup','Subject.totalfull',
                    'Subject.totalpass','Subject.gradeSystem','Subject.wfull', 'Subject.wpass','Subject.mfull','Subject.mpass','Class.Name as class','Subject.sfull','Subject.spass',
                    'Subject.pfull','Subject.ppass')
                ->where('Subject.class',$selectedClass)
                ->get();
        }
        else{
            $Subjects=  DB::table('Subject')
                ->join('Class', 'Subject.class', '=', 'Class.code')
                ->select('Subject.id', 'Subject.code','Subject.name','Subject.type', 'Subject.subgroup','Subject.stdgroup','Subject.totalfull',
                    'Subject.totalpass','Subject.gradeSystem','Subject.wfull', 'Subject.wpass','Subject.mfull','Subject.mpass','Class.Name as class','Subject.sfull','Subject.spass',
                    'Subject.pfull','Subject.ppass')
                ->get();
        }
        return View::Make('app.subjectList',compact('Subjects','classes','selectedClass'));
    }
1
What are you trying to achieve? The line is invalid logic, trying to add (sum) an array with another (collection to be exact).DevK
Are you trying to concatenate two arrays with that +?Alex Harris
@devk, it is not invalid logic. But i have had an answer belowuser9653376

1 Answers

0
votes

You have to convert the collection into an array:

$classes = ['0'=>'All'] + ClassModel::pluck('name','code')->all();