2014-07-24 150 views
0

我试图验证表单中的一些数据,并将用户重定向到任何错误的页面。我的代码不会重定向到任何路线。我的所有路由的路由工作正常。我使用Input :: all()回显输入,并且它具有用户输入。验证器也可以工作。我不知道到底发生了防止工作Laravel没有重定向到路由

public function postPurchase() 
{ 
    $validator = Validator::make(Input::all(), array(
     'condition' => 'required', 
     'memory' => 'required', 
     'color' => 'required', 
     'accessories' => 'required', 
     'shipping' => 'required' 
    )); 

    // $input = Input::all(); 
    // dd($input); 

    if ($validator->fails()) { 
     // echo "string"; 
     return Redirect::route('home'); 

    } else { 
     echo "this succedded"; 
    } 
    //Get prices, item id, etc and send user to checkout page 
    // echo "Get prices, item id, etc and send user to checkout page"; 
} 

重定向::路线这是先于购买后的方法的代码:

public function getPurchase() 
    { 
     return View::make('general.purchase'); 
    } 

    public function getCheckout() 
    { 
     return View::make('general.checkout'); 
    } 

    public function postPurchaseCheck() 
    { 
     $input = Input::all(); 
     $this->input = $input; 

     if (Input::get('buy')) { 
      $this->postPurchase(); 
     } 
     elseif (Input::get('cart')) { 
      $this->postAddCart(); 
     } 

    } 
+0

你得到任何错误消息?你还可以发布你的'routes.php'文件内容吗? – lowerends

回答

2

你调用函数 - 但你不要“回归”将重定向回馈给您。

变化

if (Input::get('buy')) { 
      $this->postPurchase(); 
     } 

if (Input::get('buy')) { 
      return $this->postPurchase(); 
     } 
0

更改您postPurchaseCheck()方法返回什么是这个 - $>购后()这样的返回。因为你在内部调用购后()方法,但后上postPurchaseCheck发生()方法,因此重定向必须通过处理POST请求的方法返回

public function postPurchaseCheck() 
{ 
    $input = Input::all(); 
    $this->input = $input; 

    if (Input::get('buy')) { 
     return $this->postPurchase(); 
    } 
    elseif (Input::get('cart')) { 
     return $this->postAddCart(); 
    } 

} 
2

尝试更新此

if (Input::get('buy')) { 
      return $this->postPurchase(); 
} elseif (Input::get('cart')) { 
    return $this->postAddCart(); 
} 

if ($validator->fails()) { 
     // echo "string"; 
     return Redirect::to('home'); 

    } else { 
     echo "this succedded"; 
    } 

也不要忘了把它定义在路由文件