所以我试图从控制器向视图发送一些查询,但是当尝试使用第三个变量时,它说:
Undefined variable: type(View:)
$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);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。