I am working on a laravel project, I encountered with an error i.e, page content is not being displayed until I refresh the page. If I do refresh my page, desired page will opens up. Here is my code, inside which I mentioned which part is throwing error:
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.');
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire