php - Make a global validation for all requests in Laravel -


i have make validation of of date format using class/request in laravel. can make validation of requests ? think in request.php abstract class.

you may try this, @ first create basecontroller following:

<?php  namespace app\http\controllers;  use illuminate\http\request;  class basecontroller extends controller {      public function __construct(request $request) {          $this->request = $request;          $this->hasvaliddate();     }      protected function hasvaliddate()     {         if($this->request->method() == 'post') {             // adjust rules needed             $this->validate($this->request, ['date' => 'required|date']);         }     } } 

then in other controllers, extend basecontroller example:

namespace app\http\controllers\user;  use app\http\controllers\basecontroller;  class usercontroller extends basecontroller {      public function index()     {         // ...     }  } 

hope got idea. use wisely.


Comments