[英]Laravel pass variable from 1 function in controller to another one
I have 2 functions in a controller 我在控制器中有2个功能
This is the get function 这是获取功能
public function getAllDept($allDEPT2)
{
$allDEPT = Facultyform::where('Home_Department_Desc', '=', $allDEPT2)->paginate(1);
$allDEPTs = View::make('faculty/dept', compact('allDEPT','certifications','certifications1','advisment','facultydata','facultydata1','facultydegree','facultydegree1','commembership', 'commembership1','otherpro','otherpro1','priorteaching','priorteaching1','publication','publication1','professioncourse','professioncourse1','support','support1','otherschool','otherschool1' ));
return $allDEPTs;
}
This is the post function 这是发布功能
public function getAllDept2()
{
if ( Session::token() !== Input::get( '_token' ) ) {
return Response::json( array(
'msg' => 'Unauthorized attempt to create setting'
) );
}
$fId = Input::get( 'faculty_id' );
$faculty = Facultyform::where('File_Number', '=', $fId)
->get();
if($faculty[0]['isChair'] == 'Y'){
$allDEPT2 = $faculty[0]['Home_Department_Desc'];
$allDEPT = Facultyform::where('Home_Department_Desc', '=', $allDEPT2)->paginate(1);
$this->getAllDept($allDEPT2);
$allDEPTs = View::make('faculty/dept', compact('allDEPT','certifications','certifications1','advisment','facultydata','facultydata1','facultydegree','facultydegree1','commembership', 'commembership1','otherpro','otherpro1','priorteaching','priorteaching1','publication','publication1','professioncourse','professioncourse1','support','support1','otherschool','otherschool1' ));
return $allDEPTs;
}
I have created both routes 我已经创建了两条路线
Route::get('faculty/dept',array(
'uses' => 'FacultyController@getAllDept'
));
Route::post('faculty/dept', array(
'as' => 'faculty/dept',
'uses' => 'FacultyController@getAllDept2'
));
When the end user uses the faculty/getDept and put the id it shows the 1st item in the list utilizing the view, but when I click on the next page I get the following error Missing argument 1 for FacultyController::getAllDept() If i hard code a department the pagination works but its only for the hard coded department. 当最终用户使用faculty / getDept并放置ID时,它将利用视图显示列表中的第一项,但是当我单击下一页时,出现以下错误FacultyController :: getAllDept()缺少参数1硬编码部门的分页工作,但仅适用于硬编码部门。
I tried $this->getALLDept($allDEPT2); 我尝试了$ this-> getALLDept($ allDEPT2); I tried creating a session of the variable I tried to make the variable global is there something I can do in the controller to pass the variable from one function to the other function or do I do this in the route? 我试图创建一个变量的会话,我试图使变量成为全局变量,是否可以在控制器中执行一些操作,以将变量从一个函数传递给另一个函数,还是在路由中执行此操作?
This is what the one of the functions look like 这就是其中一个功能的样子
public function getFacultyId() {
//check if its our form
if ( Session::token() !== Input::get( '_token' ) ) {
return Response::json( array(
'msg' => 'Unauthorized attempt to create setting'
) );
}
//check if its our form
if ( Session::token() !== Input::get( '_token' ) ) {
return Response::json( array(
'msg' => 'Unauthorized attempt to create setting'
) );
}
$fId = Input::get( 'faculty_id' );
$faculty = Facultyform::where('File_Number', '=', $fId)
->get();
$lastNames = $faculty[0]['Last_Name'];
$firstNames = $faculty[0]['First_Name'];
$certCount = Certifications::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($certCount < 1)
{
$certifications1 = "N/A";
}
else
{
$certifications1 = " ";
}
$certifications = Certifications::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$advisment = Advisment::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
$fsCount = $facultydata = Facultydata::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($fsCount < 1)
{
$facultydata1 = "N/A";
}
else
{
$facultydata1 = " ";
}
$facultydata = Facultydata::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$eduCount = Facultydegree::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($eduCount < 1)
{
$facultydegree1 = "N/A";
}
else
{
$facultydegree1 = " ";
}
$facultydegree = Facultydegree::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$comCount = Commembership::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($comCount < 1)
{
$commembership1 = "N/A";
}
else
{
$commembership1 = " ";
}
$commembership = Commembership::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$otherCount = OtherPro::where('Last_Name', '=', $lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($otherCount < 1)
{
$otherpro1 = "N/A";
}
else
{
$otherpro1 = " ";
}
$otherpro = OtherPro::where('Last_Name', '=', $lastNames)
->where('First_Name','=',$firstNames)
->get();
$ptCount = PriorTeaching::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($ptCount < 1)
{
$priorteaching1 = "N/A";
}
else
{
$priorteaching1 = " ";
}
$priorteaching = PriorTeaching::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$pubCount = Publications::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($pubCount < 1)
{
$publication1 = "N/A";
}
else
{
$publication1 = " ";
}
$publication = Publications::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$pcCount = ProfessionCourse::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($pcCount < 1)
{
$professioncourse1 = "N/A";
}
else
{
$professioncourse1 = " ";
}
$professioncourse = ProfessionCourse::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$supportCount = Support::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($supportCount < 1)
{
$support1 = "N/A";
}
else
{
$support1 = " ";
}
$support = Support::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$osCount = OtherSchool::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($osCount < 1)
{
$otherschool1 = "N/A";
}
else
{
$otherschool1 = " ";
}
$otherschool = OtherSchool::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$allviews = View::make('faculty.faculty', compact('faculty','certifications','certifications1','advisment','facultydata','facultydata1','facultydegree','facultydegree1','commembership', 'commembership1','otherpro','otherpro1','priorteaching','priorteaching1','publication','publication1','professioncourse','professioncourse1','support','support1','otherschool','otherschool1'));
I was making one for each department that requested it. 我正在为每个要求的部门制作一个。 I had 3 (all, financial and academic)so far then it hit me to make one that each department chair can view only their department info by entering their credentials. 到目前为止,我有3个(全部,包括财务和学术方面的),这使我震惊,使每个部门主席只能通过输入其凭据来查看其部门信息。 The security works just want to pass their department to the other function 安全工作只想将其部门传递给其他职能
I made a variable in the controller called department 我在名为Department的控制器中做了一个变量
public function getAllDept($department){
$department = Facultyform::where('Home_Department_Desc', '=',$department)->get();
echo($department[0]['Home_Department_Desc']);
$allDEPT = Facultyform::where('Home_Department_Desc', '=',$department[0]['Home_Department_Desc'])->paginate(1);
$lastNames = $allDEPT[0]['Last_Name'];
$firstNames = $allDEPT[0]['First_Name'];
$certCount = Certifications::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($certCount < 1)
{
$certifications1 = "N/A";
}
else
{
$certifications1 = " ";
}
$certifications = Certifications::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$advisment = Advisment::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
$fsCount = $facultydata = Facultydata::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($fsCount < 1)
{
$facultydata1 = "N/A";
}
else
{
$facultydata1 = " ";
}
$facultydata = Facultydata::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$eduCount = Facultydegree::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($eduCount < 1)
{
$facultydegree1 = "N/A";
}
else
{
$facultydegree1 = " ";
}
$facultydegree = Facultydegree::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$comCount = Commembership::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($comCount < 1)
{
$commembership1 = "N/A";
}
else
{
$commembership1 = " ";
}
$commembership = Commembership::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$otherCount = OtherPro::where('Last_Name', '=', $lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($otherCount < 1)
{
$otherpro1 = "N/A";
}
else
{
$otherpro1 = " ";
}
$otherpro = OtherPro::where('Last_Name', '=', $lastNames)
->where('First_Name','=',$firstNames)
->get();
$ptCount = PriorTeaching::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($ptCount < 1)
{
$priorteaching1 = "N/A";
}
else
{
$priorteaching1 = " ";
}
$priorteaching = PriorTeaching::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$pubCount = Publications::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($pubCount < 1)
{
$publication1 = "N/A";
}
else
{
$publication1 = " ";
}
$publication = Publications::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$pcCount = ProfessionCourse::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($pcCount < 1)
{
$professioncourse1 = "N/A";
}
else
{
$professioncourse1 = " ";
}
$professioncourse = ProfessionCourse::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$supportCount = Support::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($supportCount < 1)
{
$support1 = "N/A";
}
else
{
$support1 = " ";
}
$support = Support::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$osCount = OtherSchool::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
if ($osCount < 1)
{
$otherschool1 = "N/A";
}
else
{
$otherschool1 = " ";
}
$otherschool = OtherSchool::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->get();
$allDEPTs = View::make('faculty/dept', compact('allDEPT','certifications','certifications1','advisment','facultydata','facultydata1','facultydegree','facultydegree1','commembership', 'commembership1','otherpro','otherpro1','priorteaching','priorteaching1','publication','publication1','professioncourse','professioncourse1','support','support1','otherschool','otherschool1' ));
return $allDEPTs;
//$queries = DB::getQueryLog();
//$last_query = end($queries);
//var_dump($last_query);
//die();
}
In my route I added the variable to the uri 在我的路线中,我将变量添加到了uri
//faculty get users by department//
Route::get('faculty/dept/{department}',
'FacultyController@getAllDept'
);
When I do faculty/dept/ACDS I go get data Here is a pic of it 当我做教职/部门/ ACDS时,我去获取数据这是一张照片
When I click next I get the error 当我单击下一步时,我得到错误
Symfony \\ Component \\ HttpKernel \\ Exception \\ MethodNotAllowedHttpException Symfony \\组件\\ HttpKernel \\异常\\ MethodNotAllowedHttpException
This is the uri I get when I click next /facultyform/faculty/dept?page=2 这是当我单击下一个/ facultyform / faculty / dept?page = 2时获得的uri。
maybe I have to make it go /facultyform/faculty/dept/department?page2 instead? 也许我必须让它进入/ facultyform / faculty / dept / department?page2吗?
Here is more info of the error I am getting 这是我得到的错误的更多信息
GET Data 获取数据
Key Value 核心价值
page 2 第2页
POST Data empty 开机自检数据为空
Files empty 文件为空
Here is a working url 这是一个有效的网址
/facultyform/faculty/dept/Health%20Science%20and%20Technologies?page=2 / facultyform / faculty / dept / Health%20Science%20and%20Technologies?page = 2
Now I just have to get the department in the url and I am done :) 现在我只需要在URL中获取部门,就可以完成了:)
When I go to the view I am able to hardcode the department and all works Now I just need to pass the variable from the controller to the view 转到视图时,我可以对部门和所有工作进行硬编码现在,我只需要将变量从控制器传递到视图
{{ Form::open(array(
'route' => ['faculty/dept/{department}','ACDS'],
'method' => 'post',
'id' => 'form-getdept-setting'
))}}
{{ Form::label( 'faculty_id', 'Faculty Id:' ) }}
{{ Form::text( 'faculty_id', '', array(
'id' => 'faculty_id',
'placeholder' => 'Enter Faculty Id',
'maxlength' => 20,
'required' => true,
) ) }}
{{ Form::submit( 'Find Information', array(
'id' => 'btn-getdeptsetting',
) ) }}
{{ Form::close() }}
public function getAllDept2($department){
if ( Session::token() !== Input::get( '_token' ) ) {
return Response::json( array(
'msg' => 'Unauthorized attempt to create setting'
) );
}
$fId = Input::get( 'faculty_id' );
$faculty = Facultyform::where('File_Number', '=', $fId)
->get();
if($faculty[0]['isChair'] == 'Y'){
$department = Facultyform::where('Home_Department_Desc', '=',$department)->get();
$department2 = $department[0]['Home_Department_Desc'];
$allDEPT2 = $faculty[0]['Home_Department_Desc'];
dd($department);
$allDEPT = Facultyform::where('Home_Department_Desc', '=', $allDEPT2)->paginate(1);
$this->getAllDept($allDEPT2);
$lastNames = $allDEPT[0]['Last_Name'];
$firstNames = $allDEPT[0]['First_Name'];
$certCount = Certifications::where('Last_Name','=',$lastNames)
->where('First_Name','=',$firstNames)
->count();
...
$allDEPTs = View::make('faculty/dept',compact('allDEPT','certifications','certifications1'
,'advisment','facultydata','facultydata1','facultydegree','facultydegree1','commembership',
'commembership1','otherpro','otherpro1','priorteaching','priorteaching1','publication'
,'publication1','professioncourse','professioncourse1','support','support1','otherschool'
,'otherschool1'));
return $allDEPTs;
/* $queries = DB::getQueryLog();
$last_query = end($queries);
var_dump($last_query);
die(); */
}
else{
return Redirect::to('/');
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.