Laravel: Calling method of a controller class from blade template

How can I call a method of a controller from blade template and receive the data is returned by the method. For an Example:

My controller name is MeetingRoomController

class MeetingRoomController extends BaseController {
    public function index()
    {
        //get all the meeting room
        $meetingRoomCountry = MeetingRoom::select('country')->distinct()->orderBy('country')->get();
        return View::make('index')->with('meetingroom',$meetingRoomCountry);
    }


    public function findLocationForNavBar($country)
    {
        $meetingRoomLocation = MeetingRoom::select('location')
                                ->distinct()
                                ->where('country','$country')
                                ->orderBy('country')
                                ->get();
        return View::make('index')-   >with('meetingroomLocation',$meetingRoomLocation);
    }

The View is index.blade.php

<div id="dropdown-lvl1" class="panel-collapse collapse">
    <div class="panel-body">
         <ul class="nav navbar-nav">
         @foreach($meetingroom as $key => $value)                                            
             <li class="panel panel-default" id="dropdown">
                 <a data-toggle="collapse" href="#dropdown-lvl2">
                     <span class="glyphicon glyphicon-off"></span> {{$country = $value->country}} <span class="caret"></span>
                  </a>
                  <div id="dropdown-lvl2" class="panel-collapse collapse">
                      <div class="panel-body">
                          <ul class="nav navbar-nav">
                              <li><a href="#">Location</a></li>            
                          </ul>
                      </div>
                  </div>
             </li>
             @endforeach
         </ul>
     </div>
 </div>

I want to collect the location based on corresponding country. According to my logic, First of all I collected the distinct country then searched the location by findLocationForNavBar method in MeetingRoomController.


Source: laravel

Leave a Reply