Support the ongoing development of Laravel.io →
posted 11 years ago
Validation

hello friends I'm making an Insertion and get this errror

Access to undeclared static property: User :: $ rules

in which he points to the following line of code $ validator = Validator :: make ($ data = Input :: all (), User :: $ rules);

Model

<?php
 
class User extends \Eloquent {
 
public static $rules = array(
'email' => 'required'
 
);
public function grupos(){
return $this->belongsToMany('Group', 'users_groups', 'user_id', 'group_id');
}
 
}

Controller

public function store()
{
$validator = Validator::make($data = Input::all(), User::$rules);
 
if ($validator->fails())
{
return Redirect::back()->withErrors($validator)->withInput();
}
 
$user = Sentry::createUser(array(
'email' => Input::get('email'),
'password' => Input::get('password'),
'activated' => false,
'first_name' => Input::get('first_name'),
'last_name' => Input::get('last_name'),
'username' => Input::get('username'),
'cedula' => Input::get('cedula'),
));
 
$adminGroup = Sentry::findGroupById(2);
$user->addGroup($adminGroup);
 
return Redirect::route('users.index');
}
Last updated 3 years ago.
0

This could be be just because you haven't run: 'php artisan dump-autoload' I myswlf ran into this error because I still had the default users model file residing in my project and thus couldn't find the rules property.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

montes2012 montes2012 Joined 11 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.