三种不同 table 一次观看 laravel 5.2

three different table in one views laravel 5.2

您好,我想使用 laravel 5.2 在一个视图中显示三个不同的 table。但我似乎遇到了问题。

我的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

我无法显示第三个,即 $services。请帮助我。 当我添加第三个时,它会显示错误

请更改:

        return view('master', ['about' => $about], ['teams' => $teams], ['services' => $services]);

对此:

        return view('master', ['about' => $about, 'teams' => $teams, 'services' => $services]);

在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
]);

这现在正在调用同一个函数,但只传递 两个 个参数。