2014-10-23 4 views
0

일부 데이터의 유효성을 검사하려고합니다. 나는이 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 
    ); 

} 
+1

솔직히 모든 것이 좋게 보입니다. 'php artisan dump-autoload'를 다시 실행하십시오. 어쩌면 당신은 우연히 다른 폴더에서 그것을 실행했습니다 (전에 저에게 일어난 ..). 또는 변수를 정적이 아닌 객체로 만들려고합니다. – Diederik

+0

코드를 시도했지만 오류가 표시되지 않았습니다. 컨트롤러를 컨트롤러로 옮길 수 있습니다. 컨트롤러가 모델이 아니라 유효성 검사를 담당하기 때문입니다. –

답변

0

를 사용하려고 봤는데, 온라인 저에 대한 해결책을 찾을 수 없습니다, 나는 PHPStorm으로 문제를 추적하고 있음을 발견 내 클래스는 "TWICE"로 정의되었으므로 원하는 클래스가 아니라 두 번째 클래스를 먼저 읽었습니다.

당신은 아마이 문제는 마이그레이션 파일이 "사용자"테이블에 대한 마이그레이션 파일을 포함하도록하고, 이는 Class User extends Migration {로의 클래스를 정의하고 모델의 Class User의 정의 Class User extends Eloquent 같이 갈 것 등의 해결책이 하나에 그 중 하나를 변경하려면 : 당신은 유지 하나, 그래서

Class CreateUser extends Migration 또는 Class UserModel extends Eloquent

다음 변화에 따라 모델의 방법을 사용하는 것이

User::$rules 또는 UserModel::$rules이고 모델 클래스 이름을 변경 한 경우에만 해당됩니다.

관련 문제