我在laravel项目上工作,遇到错误,即直到刷新页面后才显示页面内容。如果我确实刷新页面,则会打开所需的页面。 这是我的代码,在其中提到了哪个部分引发错误:
public function adduser(Request $request){
//take a project of logged in user and a user to it
$project = Project :: find($request->input('project_id'));
if(Auth::user()->id==$project->user_id){
if($user = User::where('email', $request->input('email'))->first()){//first for single record
//Check if user is already added to project
$projectUser = ProjectUser::where('user_id',$user->id)
->where('project_id',$project->id)
->first();
if($projectUser){
//if user already exist; exit.
return redirect()->route('projects.show',['$project'=> $project->id])
->with('success',$request->input('email'). 'is already a member of this project.');
}
if($user && $project){
$project->users()->attach($user->id);
return redirect()->route('projects.show',['$project'=> $project->id])
->with('success',$request->input('email'). 'has been added successfully.');
}
}
else{//user is not registered, so do not add him
//This link is not working until I refresh the page???
return redirect()->route('projects.show',['$project'=> $project->id])
->with('errors', 'This User doesnt exist');
}
}else{
return redirect()->route('projects.show',['$project'=> $project->id])
->with('errors', 'You are not authorized to do this.');
}
}
答案 0 :(得分:0)
您要传递的数组键不应该使用$ sign
return redirect()-> route('projects.show',['project'=> $ project-> id]) -> with('success',$ request-> input('email')。'已经是该项目的成员。');