所以我正在尝试将一些查询从控制器发送到视图,但是当尝试使用第三个变量时,它说:
未定义的变量:类型(视图:(
我使用的代码在控制器中是这样的:
$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]);
并在以下观点中:
@foreach($type as $types)
<option value="{{$types->id}}">{{$types->type}}</option>
@endforeach
你应该返回一个数组:
return view('dashboard',['doc'=>$doc,'user'=>$user,'type'=>$type]);
还有其他方式,例如我们:
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);