I have a problem when register a user, after save user in my table users, I try assign role for this user but I receive the error :
Class name must be a valid object or a string.
my code is
(App\Http\Controllers\auth\AuthController.php)
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Role;
use Validator;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Controller\Auth;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Illuminate\Http\Request;
class AuthController extends Controller
{
public function postRegister(Request $request){
$this->validate($request,[
'name' => 'required|min:4|max:255|unique:users',
'email'=>'required|email|max:255|unique:users',
'password'=>'required|confirmed|min:3'
]);
$user_data = array(
//$field => $request->input('login'),
'name'=> $request->input('name'),
'email' => $request->input('email'),
'password' => $request->input('password')
);
$user=User::create([
'name'=>$user_data['name'],
'email'=>$user_data['email'],
'password'=>bcrypt($user_data['password']),
'active'=>1
]);
echo $user;
$role = Role::where('name','=','admin')->first();
//$user->attachRole($role->id);
$user->roles()->attach($role->id);
//return redirect('auth/register')->with('message','store');
}
}
the echo
on $user
print this:
{"name":"bbbbbvq","email":"bb@bbv.comq","active":1,"updated_at":"2016-03-03 19:07:24","created_at":"2016-03-03 19:07:24","id":32}
I copied entrust Zizaco\Entrust\src\config\config.php
to my proyect\app\config\entrust.php
and I modified the file test\vendor\zizaco\entrust\src\Entrust\EntrustServiceProvider.php
in this method:
private function registerCommands()
{
/*
$this->app->bindShared('command.entrust.migration', function ($app) {
return new MigrationCommand();
});
$this->app->bindShared('command.entrust.classes', function ($app) {
return new ClassCreatorCommand();
});*/
$this->app->singleton('command.entrust.migration', function ($app) {
return new MigrationCommand();
});
$this->app->singleton('command.entrust.classes', function ($app) {
return new ClassCreatorCommand();
});
}