2016-07-09 10 views
0

カスタム要求クラスの検証を使用して検証するのに助けが必要ですが、コントローラがリソースコントローラであるため、カスタム要求クラスをパラメータとして追加できません。どのようにリソースコントローラからのカスタムリクエストの検証を呼び出す任意のアイデアですか?リソースコントローラからカスタム要求の検証を呼び出す

これは私のリソースコントローラ

Route::resource('customers', 'CustomerController'); 

への経路であり、これは私の顧客の要求クラス

class CustomerRequest extends Request 
{ 
    //... 
    public function rules() 
    { 
     return [ 
      'customer_type'=>'required|', 
      'customer_vendor'=>'required|', 
      'customer_name'=>'required|', 
      'company_name'=>'required_if:customer_type,Company', 
      'job_position'=>'required|', 
      'street'=>'', 
      'city'=>'required|', 
      'country'=>'required|', 
      'website'=>'url', 
      'phone'=>'required_unless:mobile|', 
      'mobile'=>'required_unless:phone|', 
      'email'=>'email', 
     ]; 
    } 
} 

であり、これは私のリソースコントローラです:

class CustomerController extends Controller 
{ 
    // .... 
    // Add Customer 
    public function store() 
    { 
     //how do i call custom request validation here 

     return view('create_views/new_customer',['title' => 'New Customer','nav_links'=>CustomerController::$Links]); 
    }  
} 

を解決しました

あなたが認証ファンクション職人のPHPを使用して、カスタム要求はfalseを返していると我々は我々がログインしている場合はtrueを返す必要が作成されます

public function authorize() 
{ 
    return false;//should be return true; 
} 

答えて

0

あなたが認証ファンクション職人のPHPを使用して、カスタム要求はfalseを返していると我々は我々がログインしている場合はtrueを返す必要が作成した場合

を解決しよう:

public function authorize() 
{ 
    return false;//should be return true; 
} 
2

あなただけの要求(CustomerRequest)を、ヒントを入力する必要がありますあなたのコントローラメソッド(store())。

public function store(CustomerRequest $request) 
{ 
    return view('create_views/new_customer',['title' => 'New Customer','nav_links'=>CustomerController::$Links]); 
} 
+0

私はそれを試してみました以前は、禁じられたページを返します!私はタイプヒント 'public function store(Request $ request)' – theMohammedA

+0

あなたはユーザーとしてログインしていますか? –

+0

はい、私はログインしていますが、私も '$ this->ミドルウェア( 'auth');とauthrize()を無効にしようとしました。この問題はリソースコントローラーであり、通常のコントローラーではタイプヒントが完全に機能します。 – theMohammedA

関連する問題