Support the ongoing development of Laravel.io →
Input Eloquent Architecture
Last updated 2 years ago.
0

Up up up !

Last updated 2 years ago.
0

Looks good to me.

Last updated 2 years ago.
0

Thank you for your answer.

Last updated 2 years ago.
0

Hi again,

I'm trying to use Confide and Entrust. Now my User Model extends ConfideUser and uses the HasRole Trait. I added a Role Model (extends EntrustRole), a Permission Model (extends EntrustPermission) and corresponding tables. I also updated the static factory method inside my User Model.

##Static factory method

###User Model

    public static function createUser($type, array $userAttributes, array $typeAttributes)
    {

        if(class_exists($type)) {

            $role = \Role::where('name', '=', $type)->first();

            $userType = $type::create($typeAttributes);

            $user = $userType->user()->create($userAttributes);

            $user->attachRole($role);

            return $accountType;

        } else {

            throw new InvalidAccountTypeException('Invalid account type.');

        }

    }

Is there a better way to do this ?

Last updated 2 years ago.
0

Can someone explain to me how morph works? What I mean is, I don't know what fields are required in my tables to get it working. I see you are using userable_id and userable_type. Are these necessary? I fail to understand how I should make my table constraints.

UDPATE: Silly me, I seem to have missed the part in the docs about the table structure. I think I understand it now.

Last updated 2 years ago.
0

I am new to Laravel and trying to create an application with different types of users. The users have both common and unique characteristics. After looking at Single Table Inheritance models, I decided to try polymorphic relations. Most of the examples deal with retrieving the records. This is the first post I found with an example of how to create new (different type) users.

The problem is, I am too inexperienced to fill in the blanks for all of the above code. I am confused, for example, by the label User Model being used under Polymorphic relationships and again under Static factory method. What should the file name be for the factory if it is a separate file, and where should it be saved in the folder structure? Could you post the complete scripts or a link to the examples above as a learning aide? Thank you.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

AnasT anast Joined 14 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.