So I have the "User" model and "usersetting" model. the "usersettings" model has a column called "users_id" key to link it back to the User Model.
I'm using the spatie permissions and role module...
So in the Users model I have
use Spatie\Permission\Traits\HasRoles;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
use HasRoles;
......
public function usersettings()
{
#return $this->hasOne('\App\usersettings','users_id');
return $this->belongsTo('\App\usersettings','users_id');
}
}
In the user setting model I have
namespace App;
use Illuminate\Database\Eloquent\Model;
use Spatie\Permission\Traits\HasRoles;
class usersettings extends Model
{
use HasRoles;
protected $guard_name = 'web'; // or whatever guard you want to use
protected $table = 'usersettings';
protected $fillable = [
'users_id','stripe_customer',
];
//
}
And in my Controller I have
public function chooseUser(Request $request){
$theuserID = $request->input('id');
\Log::info('The User ID:'.$theuserID);
$whichuser = \App\User::find($theuserID)->with('usersettings')->get();
$whichuser2 = \App\User::find($theuserID);
/*if($isadmin = $whichuser2->hasRole('admin')){
$whichuser->admin ='isadmin';
}*/
#\Log::info('THE HAVE:'.$isadmin);
\Log::info('THE USER:'.$whichuser);
#$roles = $whichuser->getRoleNames();
#\Log::info('THE USER:'.$roles);
return $whichuser;
}
My GOAL is to return all the user information with the user settings as well as looking up whether or not the user has the admin role. I haven't been able to figure out how to put the three of these together.
I'm thinking that it may be a join instead of a realtion but then I dont' have a uUser model anymore and can't use the methods in the spatie package.
Thanks R