Laravel:我不能从控制器向视图发送2个以上的变量

ped*_*and 0 php laravel laravel-5

所以我试图从控制器向视图发送一些查询,但是当尝试使用第三个变量时,它说:

未定义的变量:类型(查看:)

我正在使用的代码是控制器中的代码:

    $doc=DB::table('documents')
        ->join('users', 'users.id', '=', 'documents.id_user')
        ->join('type_docs', 'type_docs.id', '=', 'documents.id_tipo_doc')
        ->join('departments', 'departments.id', '=', 'documents.id_departamento')
        ->select('documents.*', 'type_docs.type', 'users.name','departments.abbreviation')
        ->get();
  $user=DB::table('users')
  ->select('users.*')
  ->get();
  $type=DB::table('type_docs')
  ->select('type_docs.*')
  ->get();


        //$doc = Document::all();
  return view('dashboard',['doc'=>$doc],['user'=>$user],['type'=>$type]);
Run Code Online (Sandbox Code Playgroud)

并在视图中:

       @foreach($type as $types)
                  <option value="{{$types->id}}">{{$types->type}}</option>
       @endforeach
Run Code Online (Sandbox Code Playgroud)

Mar*_*boc 10

你应该返回一个数组:

return view('dashboard',['doc'=>$doc,'user'=>$user,'type'=>$type]);
Run Code Online (Sandbox Code Playgroud)

我们还有其他方式:

return view('dashboard', array('doc'=>$doc,'user'=>$user,'type'=>$type));

return view('dashboard', compact('doc','user','type'));

return view('dashboard')
            ->with('doc', $doc)
            ->with('user', $user)
            ->with('type', $type);

return view('dashboard')            //using laravel Magic method.
            ->withDoc($doc)
            ->withUser($user)
            ->withType($type);
Run Code Online (Sandbox Code Playgroud)