本文介绍了无法使用类,因为它不是特质的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已在此处上进行了学习为laravel构建验证服务.我现在尝试从我的一个控制器调用验证器时遇到问题.我看到了错误:
I have followed the tutorial here on building a validation service for laravel. I am having issues now when trying to call the validator from one of my controllers. I am seeing the error:
validController cannot use Portal\Service\Validation\Laravel\AppInstancesValidator - it is not a trait
这是我的控制器:
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();
}
}
和我的验证人:
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'
);
}
推荐答案
尝试将use
放在class
声明之前:
<?php // namespace Portal\Controllers;
use \Portal\Service\Validation\Laravel\AppInstancesValidator;
class validController extends BaseController {
public function validateInstance() {}
}
这篇关于无法使用类,因为它不是特质的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!