mercredi 1 août 2018

how to properly get plucked name by going through multiple tables and compare it to a string?

I am still am not familiar with laravel and I want to get the 'name' of the Organization that the $user is joined. I have 3 tables: Users, Organizations and Organization_users with their respective models User, Organization, and OrganizationUser.

The logic that I want to implement is: get the uuid of the currently logged in user and find the user_id in OrganizationUser which is a foreign key of the uuid in the Users table. After that, I want to find which organization the user is in by using the OrganizationUsers table in which the Organization's primary uuid is a foreign key to the OrganizationUser's organization_id then pluck the name and then compare it to a string.

here is my code.

    $user   = JWTAuth::parseToken()->authenticate();

    $org_user_profile = OrganizationUser::where('user_id',$user->uuid)->get();
    $profile_org_relation = Organization::where('uuid',$org_user_profile->organization_id)->pluck('name');

    if ($profile_org_relation == "Org1") {
#condition here

It works until the $org_user_profile line and it sends an error

Property [organization_id] does not exist on this collection instance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire