Laravel 4 - 访问验证类的验证类 [英] Laravel 4 - Access Auth Class in Validation Class
问题描述
我想我ValidatorService类中访问验证类。
I want to access the Auth Class within my ValidatorService Class.
namespace Services\Validators\User;
use \Services\Validators\Validator;
use \Illuminate\Support\Facades\Auth;
class Edit extends Validator {
public static $rules = [
'email' => 'required|unique:users,email,'.Auth::user()->id
];
}
我试图使用 \\照亮的\\ Support \\外立面\\验证
命名空间,但laravel抛出异常。
I tried to use the \Illuminate\Support\Facades\Auth
Namespace, but laravel throws an Exception.
错误:语法错误,意想不到的,期待]
Laravel只是抛出异常,当我尝试使用验证用户::() - > ID。
如果我删除验证::用户() - > ID和添加一个数字,例如1,它的工作原理
Laravel only throws the exception, when I try to use Auth::user()->id. If I remove Auth::user()->id and add a number, for example 1, it works.
我也试图实施照亮\\验证\\的UserInterface
,但它不工作。
I also tried to implement the Illuminate\Auth\UserInterface
but it is not working.
我如何使用验证类在我ValidatorService类?
How can I use the Auth Class in my ValidatorService Class?
编辑:问题解决了 - >向下滚动
Problem solved -> Scroll down.
推荐答案
解决方案:
在设置变量时,不能使用函数或变量
类。
You cannot use functions or variables when setting a variable on a class.
由于AndreasLutro在 http://laravel.io/irc
Thanks to AndreasLutro on http://laravel.io/irc
所以我删除了类变量,并添加方法。
现在,万物正常工作。
So I removed the class variable and added a method. Now everythings works fine.
code:
class Edit extends Validator{
public static function rules(){
return array(
'email' => 'required|unique:users,email,'.Auth::user()->id
);
}
}
干杯,史蒂芬。
这篇关于Laravel 4 - 访问验证类的验证类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!