2015-11-03 156 views
1

我有產品和軟件和電影屬於產品。我創建了兩個驗證請求,並希望驗證它們,如下所示。Laravel多個表單請求驗證

public function store(StoreProductRequest $old_request) 
{ 
    if ($old_request->type == 'MOVIE') 
     $request = new StoreMovieRequest; 
    else 
     $request = new StoreSoftwareRequest; 

    $request = $old_request; 
    $request->validate(); 
} 

有什麼辦法可以在Laravel 5.1中實現這個嗎?我希望你能理解我的問題。做你想達到什麼的

+0

,你可以更詳細的顯示你的表?你的結果應該是什麼? – davejal

回答

1

一種方法是

public function store(StoreProductRequest $old_request){ 
    if ($old_request->type == 'MOVIE'){ 
    $request = new Requests\StoreMovieRequest; 
    $this->validate($old_request, $request->rules()); 
    //validation passed for StoreMovieRequest 
    } 
    else { 
    $request = new Requests\StoreSoftwareRequest; 
    $this->validate($old_request, $request->rules()); 
    //validation passed for StoreSoftwareRequest 
    } 
} 
+0

這個解決方案效果很好,非常感謝。 – 2017-11-01 09:57:58