php - Laravel: i can't send more then 2 variables from controller to a view -
so trying send query controller view when try use third variable says:
undefined variable: type(view:)
the code i'm using in controller :
$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]); and in view:
@foreach($type $types) <option value="{{$types->id}}">{{$types->type}}</option> @endforeach
you should return 1 array :
return view('dashboard',['doc'=>$doc,'user'=>$user,'type'=>$type]); there other ways such :
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);
Comments
Post a Comment