Cannot use class because it is not a trait

I followed the tutorial here about creating a validation service for laravel. I am having problems trying to call a validator from one of my controllers. I see an error:

validController cannot use Portal\Service\Validation\Laravel\AppInstancesValidator - it is not a trait

here is my controller:

 class validController extends BaseController { use \Portal\Service\Validation\Laravel\AppInstancesValidator; public function validateInstance() { $post = Input::all(); $instVal = new AppInstancesValidator( App::make('validator')); return $instVal->with($post)->passes(); } } 

and my validator:

 namespace Portal\Service\Validation\Laravel; use Portal\Service\Validation\ValidableInterface; class AppInstancesValidator extends LaravelValidator implements ValidableInterface { protected $rules = array( 'app_name' => 'required', 'app_instance_name' => 'required', 'app_instance_ip' => 'required|ip' ); } 
+6
source share
2 answers

Try putting use before the class declaration:

 <?php // namespace Portal\Controllers; use \Portal\Service\Validation\Laravel\AppInstancesValidator; class validController extends BaseController { public function validateInstance() {} } 
+16
source

Your 'use' statement must be above the definition of the validController class

+1
source

All Articles