일부 데이터의 유효성을 검사하려고합니다. 나는이 scotch.io에서 tutorial을 발견했다. 나는 일부 데이터를 검증하기 위해 시도 내 UsersController에 다음을 사용하고 있습니다 :왜 '선언되지 않은 정적 속성에 액세스합니까? (Laravel)
public function store(){
$validator = Validator::make(Input::all(), User::$rules);
return Redirect::action("[email protected]");
}
을 그러나, 나는 오류 '선언되지 않은 정적 속성에 액세스 : 사용자 :: $ 규칙을'점점 계속. 내가 뭔가 잘못하고 있는거야? 나는이 같은 문제가 있었다 'PHP는 장인 덤프 - 자동로드'
<?php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password', 'remember_token');
protected $fillable = array(
'username',
'forename',
'surname',
'email',
'telephone',
'password',
'admin',
'customer',
'verification_link'
);
public static $rules = array(
'name' => 'required', // just a normal required validation
'email' => 'required|email|unique:ducks', // required and must be unique in the ducks table
'password' => 'required',
'password_confirm' => 'required|same:password' // required and has to match the password field
);
}
솔직히 모든 것이 좋게 보입니다. 'php artisan dump-autoload'를 다시 실행하십시오. 어쩌면 당신은 우연히 다른 폴더에서 그것을 실행했습니다 (전에 저에게 일어난 ..). 또는 변수를 정적이 아닌 객체로 만들려고합니다. – Diederik
코드를 시도했지만 오류가 표시되지 않았습니다. 컨트롤러를 컨트롤러로 옮길 수 있습니다. 컨트롤러가 모델이 아니라 유효성 검사를 담당하기 때문입니다. –