Open carnevalle opened 11 years ago
Are you still getting this error?
I am having this error running the said command.
[BadMethodCallException] Call to undefined method Illuminate\Database\Query\Builder::attachRole()
Didn't mean to close it :-)
I have tried once again with no problems. So don't know what caused the problem.
Hey guys,
I too am getting this error like @carnevalle said. I am not sure why is it coming up. Any solution for this?
PHP Fatal error: Call to undefined method stdClass::attachRole() in /Users/jenil/Sites/esperanto/app/database/seeds/RolesTableSeeder.php on line 19 {"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Call to undefined method stdClass::attachRole()","file":"\/Users\/jenil\/Sites\/esperanto\/app\/database\/seeds\/RolesTableSeeder.php","line":19}}{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Call to undefined method stdClass::attachRole()","file":"\/Users\/jenil\/Sites\/esperanto\/app\/database\/seeds\/RolesTableSeeder.php","line":19}}
Fresh install Same here...
This is not the exactly the same problem. But it is a very close error to open a new issues. Take a look:
$ php artisan db:seed
PHP Fatal error: Trait 'Zizaco\Entrust\HasRole' not found in /vagrant/laravel/app/models/User.php on line 7
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Trait 'Zizaco\\Entrust\\HasRole' not found","file":"\/vagrant\/laravel\/app\/models\/User.php","line":7}}{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Trait 'Zizaco\\Entrust\\HasRole' not found","file":"\/vagrant\/laravel\/app\/models\/User.php","line":7}}
$ cat composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.1.*",
"zizaco/confide": "dev-master",
"intervention/image": "dev-master",
"google/apiclient": "dev-master"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "dev"
}
$ cat ./app/models/User.php
<?php
use Zizaco\Confide\ConfideUser;
use Zizaco\Entrust\HasRole;
class User extends ConfideUser {
use HasRole;
public $errors;
protected $table = 'user';
protected $softDelete = true;
protected $fillable = array('access_token', 'refresh_token');
public $skipValidations = false;
/**
* Validation rules
*/
public static $rules = array(
'email' => 'unique:users|required|email',
'password' => 'required|between:4,11|confirmed',
);
public static function boot() {
parent::boot();
static::saving(function($model) {
return $model->validate();
});
}
public function delete() {
$this->roles()->detach();
return parent::delete();
}
public function name() {
$arr = explode( '@', $this->email );
return array_shift( $arr );
}
public function setAccessToken($token) {
$this->skipValidations = true;
return $this->update(array(
'access_token' => $token,
));
}
public function validate(array $rules = array(), array $customMessages = array()) {
if ($this->skipValidations) return true;
$validator = Validator::make($this->attributes, static::$rules);
if ($validator->passes()) return true;
$this->errors = $validator->messages();
return false;
}
}
me too with this same issue {"error":{"type":"ErrorException","message":"parse_url() expects parameter 1 to be string, array given","file":"\/var\/www\/www.magazine.dev\/vendor\/symfony\/http-foundation\/Symfony\/Component\/HttpFoundation\/Request.php","line":321}}[Finished in 0.1s]
Call to undefined method stdClass::attachRole()
I'm not completely new to Laravel (v4.2.*) and definitely not to PHP (PHP v5.4.19), so I understand what's going on here, but I can't get this to work:
$admin = DB::table('roles')->where('name', '=', 'Admin')->pluck('id');
$user = DB::table('users')->where('id', '=', '1')->first();
/* role attach alias */
$user->attachRole( $admin );
models/user.php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
use Zizaco\Entrust\HasRole;
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait, HasRole;
You probably have a role relation in your User model that overrides the HasRole's role relation method. Remove it and it will work.
I have the same Error
PHP Fatal error: Call to a member function attachRole() on null in /var/www/b4x/app/database/seeds/RolesTableSeeder.php on line 18
I haven't an override for HasRole method
if u combine confide with zicaco
see your user model
<?php
use Zizaco\Confide\ConfideUser;
use Zizaco\Confide\ConfideUserInterface;
use Zizaco\Entrust\HasRole;
class User extends Eloquent implements ConfideUserInterface
{
use ConfideUser;
use HasRole;
}
When I run php artisan db:seed i get the following error message:
{"error":{"type":"ErrorException","message":"call_user_func_array() expects parameter 1 to be a valid callback, non-static method Role::beforeSave() should not be called statically","file":"\/Users\/me\/Web\/project\/bootstrap\/compiled.php","line":5233}}
I am completely new to Laravel, so don't know how and where to debug what is going on. Is it perhaps something with the validation of the model?
I can get it working if i substitute the content of RolesTableSeeder with
There is another problem, that you can't execute db:seed multiple times, as some ID's are hardcoded and running multiple db:seed will empty the table but not reset the incrementing ID's. To resolve this issue wipe the database and migrate before seeding.