skip to Main Content

I have the following route in my laravel project

 Route::get('/',[

   'uses' => 'MakeController@index'

  ]);

Controller

   class MakeController extends Controller{


    public function index(){

        $makes = MakeType::all();        
        return View::make('Index', $makes);
        // tried this
        //  return view('Index',compact('makes'));
    }
}

index.blade.php

<select>
       <option>Select Make</option>
             @foreach($makes as $make)

                 <option>{{$make->name}}</option>

             @endforeach
</select>           

Problem:

The problem is when I try to load the index page, it shows me the following error

Use of undefined constant makes – assumed ‘makes’ (this will throw an Error in a future version of PHP) (View: /customers/6/1/4/alle-voertuigen.nl/httpd.www/resources/views/Index.blade.php)

I’ve visit all the possible links, and tried different ways of doing it, but nothing is working with me.

This is what it is showing when I do dd($makes), in attributes I have the name column

enter image description here
Please help me, thanks

3

Answers


  1. Use with in your controller.

    return View::make('Index')->with(compact('makes'));
    

    Should work.

    Login or Signup to reply.
  2. If you use this way to return a view, you must use with to add parameters :

    return View::make('Index')->with('makes', $makes);
    

    I will advise to use the view helper, I don’t know what version of Laravel you use :

    return view('Index', ['makes' => $makes]);
    

    Just only thing sure, it can’t work if you don’t pass variables as an array (with compact or ['myVariable' => $var])

    Login or Signup to reply.
  3. class MakeController extends Controller {
        public function index() {
    
            $makes = MakeType::all();        
            return View::make('index', $makes);
            // tried this
            //  return view('index',compact('makes'));
        }
    }
    

    its index not Index

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search