【问题标题】:error: Showing undefined variable .in laravel 5.2 while passing two array to View错误:在将两个数组传递给 View 时显示未定义的变量 .in laravel 5.2
【发布时间】:2017-10-17 01:16:15
【问题描述】:

GetEstimateController.php

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,$addr){
        // dd($name);
        $HospitalPack = HospitalPackage::where(['pro' => $name, 'address' => $addr])->orderBy('treat_price', 'desc')->get()->first();
        $Dropbox_fill = $this->fill_dropbox();
        // dd($HospitalPack);
        return View::make('get_quote')->with(compact('Dropbox_fill','HospitalPack'));
    }

如果我正在使用

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

这一行在使用时显示错误

return View::make('get_quote')->with(compact('HospitalPack'));

这段代码没有显示错误。

【问题讨论】:

  • 好吧,你得到了未定义的变量,我想你执行了 dd($HospitalPack);,但你是否也在 $Dropbox_fill 上执行了它?试试 dd($Dropbox_fill);看看它是否返回任何东西。
  • 两者都显示了一些数据,但是当我尝试在查看页面访问时显示错误。
  • 你如何从你的视角访问Dropbox_fill
  • 我刚刚注意到,当你执行 $this->fill_dropbox() 时,fill_dropbox() 方法本身有一个返回视图,所以你可能甚至没有点击这一行 return View::make ('get_quote')->with(compact('Dropbox_fill','HospitalPack'));到底,你在哪一行得到了错误?
  • {{dd($Dropbox_fill)}} 这样做是为了检查

标签: php arrays database eloquent laravel-5.2


【解决方案1】:

原来问题确实出在 fill_dropbox() 方法中的 return 语句中,所以如果你这样做:

public function get_estimate($name,$addr){

$HospitalPack = HospitalPackage::where(['pro' => $name, 'address' => $addr])->orderBy('treat_price', 'desc')->get()->first();

$data = ProcedureTreat::get(['pro_name']);

$data1 = HospitalPackage::get(['address']);

return View::make('get_quote')->with(compact('data', 'HospitalPack', 'data1'));
}

现在一切都应该正常了:)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-01
    • 2016-09-20
    • 2015-07-22
    • 1970-01-01
    • 2014-12-09
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多