【问题标题】:three different table in one views laravel 5.2三个不同的表在一个视图中 laravel 5.2
【发布时间】:2016-01-05 21:03:16
【问题描述】:

您好,我想使用 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

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

【问题讨论】:

  • 第三个不能显示是什么意思?您只发布了两个的代码。
  • 当我添加第三个时,它会显示一个错误@ceejayoz
  • 显示什么错误?

标签: php arrays laravel laravel-5.2


【解决方案1】:

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

现在调用的是同一个函数,但只传递了两个参数。

【讨论】:

    【解决方案2】:

    请改一下:

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

    到这里:

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

    【讨论】:

    • 没问题!我喜欢拉拉维尔!快乐编码:-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 2016-11-02
    相关资源
    最近更新 更多