简体   繁体   中英

How to call one function inside another function in same controller in laravel 5.2

GetEstimateController.php

class GetEstimationController extends Controller
{
    public function fill_dropbox(){
        $data = ProcedureTreat::get(['pro_name']);  
        $data1 = HospitalPackage::get(['address']);  
        // return $this->get_estimate();
        // dd($data);
        return View::make('get_quote')->with('address',$data1)->with('procedureName',$data);
    }
    public function get_estimate($name,$address){
        $data = HospitalPackage::where(['pro' => 'name', 'address' => 'address'])->get();
        $Dropbox_fill = $this->fill_dropbox();
        // dd($Dropbox_fill);
        return View::make('get_quote')->with('HospitalPack',$data);
    }
}

Routes.php

Route::get('/',[
    'uses' => 'GetEstimationController@fill_dropbox',
    'as' => 'fill.dropbox'
]);
Route::any('/find/{name}/{address}',[
    'uses' => 'GetEstimationController@get_estimate',
    'as' => 'get.estimate'
]);

get_quote.blade.php

@if(isset($procedureName))
       @foreach($procedureName as $key => $data)
         <option value="{{$data->pro_name}}">{{$data->pro_name}}</option>
       @endforeach                               
    @endif
    @if(isset($address))
      @foreach($address as $key => $add)
        <option value="{{$add->address}}">{{$add->address}}</option>
      @endforeach
    @endif

I want to call fill_dropbox funtion inside get_estimate function and want to send data to get_quote.blade.php again.

Using $Dropbox_fill = $this->fill_dropbox(); I'm getting data

View {#155 ▼
  #factory: Factory {#141 ▶}
  #engine: CompilerEngine {#148 ▶}
  #view: "get_quote"
  #data: array:2 [▼
    "address" => Collection {#2507 ▼
      #items: array:1382 [▼
        0 => HospitalPackage {#2508 …24}
        1 => HospitalPackage {#2509 …24}
        2 => HospitalPackage {#2510 …24}
        3 => HospitalPackage {#2511 …24}
      }
    "procedureName" => Collection {#1124 ▶}
  ]
  #path: "C:\wamp\www\IIMTC\bmmt_new\resources\views/get_quote.blade.php"
}

so how can I access it in get_quote.blade.php with previous foreach .

There are various ways to send data to a view. One of them is as below,

return View::make('get_quote', ['HospitalPack' => $data,'Dropbox_fill' => $Dropbox_fill]);

and your view file name should be get_quote.blade.php

Try like this

public function get_estimate($name,$address){
        $HospitalPack= HospitalPackage::where(['pro' => 'name', 'address' => 'address'])->get();
        $Dropbox_fill = $this->fill_dropbox();
        // dd($Dropbox_fill);
        return View::make('get_quote',compact('HospitalPack','Dropbox_fill'));
    }

then in view, you can access like this

@if(isset($HospitalPack))
       @foreach($HospitalPackas as $key => $data)
         #your data
       @endforeach                               
    @endif
@if(isset($Dropbox_fill ))
           @foreach($Dropbox_fill as $key => $data)
             #your data
           @endforeach                               
        @endif

Pass the data like this

return View::make('get_quote')->with('data',['HospitalPack' => $data,'Dropbox_fill' => $Dropbox_fill]);

In view access data like this

    $data['HospitalPack'];  
    $data['Dropbox_fill'];

OR USE COMPACT()

 return View::make('get_quote',compact('HospitalPack','Dropbox_fill');

In view access like this

   $HospitalPack

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM