嗨,我想使用laravel 5.2在一个视图中显示三个不同的表。但我似乎有问题。
我的HomeController.php
namespace App'Http'Controllers;
use Illuminate'Http'Request;
use DB;
use App'Http'Requests;
use App'Http'Controllers'Controller;
class HomeController extends Controller
{
public function index()
{
$about = DB::select('select * from about');
$teams = DB::select('select * from teams');
$services = DB::select('select * from services');
return view('master', ['about' => $about], ['teams' => $teams], ['services' => $services]);
}
}
在我看来:
@foreach ($about as $abt)
<h4>{{$abt->title}}</h4>
<span class="semi-separator center-block"></span>
<p>{{$abt->description}}</p>
@endforeach
@foreach ($teams as $team)
<div class="creative-symbol cs-creative">
<img src="assets/images/new/{{$team->icon}}" alt="">
<span class="semi-separator center-block"></span>
<h4><b>{{$team->title}}</b></h4>
<p>{{$team->description}}</p>
</div>
@endforeach
我无法显示第三个,即$服务。请帮帮我。当我添加第三个时,它将显示一个错误
在Laravel 5.1中,我在/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php
:中发现了以下代码
if (! function_exists('view')) {
/**
* Get the evaluated view contents for the given view.
*
* @param string $view
* @param array $data
* @param array $mergeData
* @return 'Illuminate'View'View|'Illuminate'Contracts'View'Factory
*/
function view($view = null, $data = [], $mergeData = [])
{
$factory = app(ViewFactory::class);
if (func_num_args() === 0) {
return $factory;
}
return $factory->make($view, $data, $mergeData);
}
}
这是您试图调用的函数。注意有多少个参数(共有3个)。你正试图在4号传球。我想你想做的是这样的事情:
return view('master', [
'about' => $about,
'teams' => $teams,
'services' => $services
]);
这现在调用相同的函数,但只传递两个参数。
请更改此项:
return view('master', ['about' => $about], ['teams' => $teams], ['services' => $services]);
到此:
return view('master', ['about' => $about, 'teams' => $teams, 'services' => $services]);