also, see your AuthController below
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'club_id' => $data[’club_id'],
why are the single quotes at the beginning and end of 'club_id', for the value, different? Not sure if this forum is presenting them differently, but maybe take a look at that.
rberlin01 said:
also, see your AuthController below
return User::create([ 'name' => $data['name'], 'email' => $data['email'], 'club_id' => $data[’club_id'],
why are the single quotes at the beginning and end of 'club_id', for the value, different? Not sure if this forum is presenting them differently, but maybe take a look at that.
Thanks for your reply! I added it wrong in the forum, the single quotes are correct. club_id is a fillable field.
Could it be because having $data['club_id'] expects getting that from a form or something with that id and can't be modified using eloquent?
You could just create the user in your controller
$newuser = User::create([
'name' => $request->input('name'),
'email' => $request->input('email'),
'club_id' => Auth::user()->club_id
]);
Also, have you done an echo on Auth::user()->club_id to ensure that the logged in user actually has a value set here?
rberlin01 said:
Also, have you done an echo on Auth::user()->club_id to ensure that the logged in user actually has a value set here?
Thanks again for your help. I did an echo and it has a valid value set.
I tried 'club_id' => Auth::user()->club_id and it worked great! But I wouldn't like it to be like that since a different role can choose the club_id from a select form. Do you have any other ideas what I could do? Thanks a lot once again!
Look for the input, if not there use the user's.
if(isset($request->input('club')){
$ClubID = $request->input('club');
}else{
$ClubID = Auth::user()->club_id;
}
$newuser = User::create([
'name' => $request->input('name'),
'email' => $request->input('email'),
'club_id' => $ClubID
]);
rberlin01 said:
Look for the input, if not there use the user's.
if(isset($request->input('club')){ $ClubID = $request->input('club'); }else{ $ClubID = Auth::user()->club_id; } $newuser = User::create([ 'name' => $request->input('name'), 'email' => $request->input('email'), 'club_id' => $ClubID ]);
Thanks again for trying to help mate! That's a good idea but I'm getting syntax errors.
First:
FatalErrorException in AuthController.php line 68:
Cannot use isset() on the result of a function call (you can use "null !== func()" instead)
Then I changed it to:
if(null !==($request->input('club_id')))
{
$ClubID = $request->input('club_id');
}
else
{
$ClubID = Auth::user()->club_id;
}
Now I'm getting:
ErrorException in AuthController.php line 68:
Undefined variable: request
rberlin01 said:
What's the route and method declaration look like?
It's the standard one from authcontroller, right now it is:
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'club_id' => Auth::user()->club_id,
'password' => bcrypt($data['password']),
]);
}
}
route:
Route::get('user/register', ['middleware' => 'auth', 'uses' => 'Auth\AuthController@getRegister']);
I managed to solve it by adding use Input; at the top of AuthController and this code:
if(Input::has('club_id'))
{
$club_id = $data['club_id'];
}
else
{
$club_id = Auth::user()->club_id;
}
Thanks for the idea rberlin01!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community