xtremer360
6 months ago

Logging in User Types

Posted 6 months ago by xtremer360

I have a single sign-in route that is reachable by any of three user types. A teacher, student, admin. I have a User model, Student, and Teacher models with users, teachers, and students tables. Both the teacher's table and students table has a user_id. We are also using the Spatie role and permissions package. What I’m wanting to do is fix my actAs() method so that it can log in a new model based on the state I pass in. Suggestions on what I should do so that I can make sure I'm logging in a student or a teacher or admin.

/**
     * Creates a user with a given state and logs them into the system.
     *
     * @param  array  $states
     * @param  array  $attributes
     * @return \App\Models\User  $user
     */
    public function actAs($states = [], $attributes = [])
    {
        $user = ($states instanceof User) ? $states : factory(User::class)->states($states)->create($attributes);
        $this->actingAs($user);

        return $user;
    }

Please sign in or create an account to participate in this conversation.