If $id
does not match to $sessionPackage['id']
it should execute
return Redirect::to('/order/' . $id . '/details');
For some reason it does redirect to a page, however it does output "Test" as debugging, so it mean that if condition is working.
In the controller:
public function showDetails($id)
{
if (!$this->checkPackage($id)) {
return Redirect::to('/');
}
$data = SessionOrder::getPersonalDetails();
return View::make("order.order-details")->withData($data);
}
checkPackage() function:
protected function checkPackage($id)
{
$this->package = Packages::getPackage($id);
if (!$this->package) {
return false;
}
$sessionPackage = SessionOrder::getPackage();
if (SessionOrder::hasPackage() && $sessionPackage['id'] != $id) {
SessionOrder::clearPackageExceptPersonalDetails();
SessionOrder::storePackage([
'id' => $id
]);
echo "Test";
return Redirect::to('/order/' . $id . '/details');
}
return true;
}
Update: If package ID does not exist then it would redirect return Redirect::to('/');
but if package ID does exist and it does not match to $sessionPackage['id']
it should redirect to Redirect::to('/order/' . $id . '/details');
Instead of the redirection, you need to return false, and do the redirection in an else-clausule in your showDetails method.
Laravel route doesn't support cascade routing. So you have to redirect in your showDetail funciton, not in the child funciton checkPackage().