gpt4 book ai didi

php - Blade Laravel 中的 undefined variable

转载 作者:行者123 更新时间:2023-12-01 21:57:05 26 4
gpt4 key购买 nike

我的 Controller 里有这个:

public function detail($id) {
$data = DB::table('data_api')->where('id', $id)->get();
$carousel = DB::table('data_carousel')->where('data_api_id', $id)->get();
return view('detail', ['data_api' => $data]);
return view('detail', ['data_carousel' => $carousel]);
}

但是当我尝试通过 {{ $carousel }} 回显 $carousel 时,它说找不到。但是 $data 工作得很好。有什么想法吗?

Undefined variable: carousel (View: /mylaravelproject/resources/views/detail.blade.php)

最佳答案

您需要将双返回语句更改为单返回

return view('detail', ['data_api' => $data]);
return view('detail', ['data_carousel' => $carousel]);

return view('detail', ['data_api' => $data, 'data_carousel' => $carousel]);

关于php - Blade Laravel 中的 undefined variable ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56105723/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com