#Handle User Selecting Which Company To Manage

1 messages · Page 1 of 1 (latest)

rancid olive
#

Hey there!

I have this situation where the user can manage many companies (many-to-many relationship), and I need to know which company he wants to manage before letting him access the dashboard.

I thought about creating a page with all the companies he has access to and from there he can choose one and then store the company slug in the session, but don't know if its a good approach to this situation or not, and would like to know if there's a better approach .

Any suggestions/approaches are very much appreciated, and thanks in advance!

maiden palm
#

Why don't you just use the company in the routes to handle what dashboard he is accessing?

rancid olive
maiden palm
#

Just have them choose a company

#

You can have a company selection page, or a drop down menu in the navigation, or on login.

rancid olive
#

before accessing the dashboard subdomain, so I can always take that company slug/id

maiden palm
#

That is a development choice.

rancid olive
#

right?

maiden palm
#

You could just have a dropdown in the navigation if you wanted like I said above.

rancid olive
#

@maiden palm What do you think about this approach?

#

I mean, the company selection page, and then a dropdown in the dash-nav o switch between companies

#

Is it a good approach?

maiden palm
#

Seems fine to me.

#

Perfectly normal way to handle it

rancid olive
maiden palm
#

I don't see why it wouldn't be, but why can't you just use url structures?

rancid olive
#

sorry, didn't understand

maiden palm
#

Like, /{company}/dashboard

#

Then whenever you refresh the page, you know where you are going to end up. If you do it in the session, and they move to another company in another browser window, then the original window when refreshed will point to the new session company. Might lead to confusion.

rancid olive
maiden palm
#

Your page that has them select a company will just redirect to the appropriate company url, you shouldn't need to store anything in the session.

rancid olive
#

I think I' gonna lose the company slug no?

maiden palm
#

Every page related to the company would be under the company slug.

rancid olive
maiden palm
#

Its in the url.

#

So if a company had posts, the routes would be /{company}/posts/{post} - not /posts/{post}.

#

And your controllers would look like

public function show(Company $company, Post $post) {
   //
}
rancid olive
#

I see!

#

And I think I should set a CompanyPolicy to check whether or not they own that company

#

Oh fuck! I forgot to let you know that this feature was told to me after everytinhg is set

maiden palm
#

Yeah, that makes sense.

rancid olive
#

currently, all the dashboard are set like this php Route::post('/company/brands', [CompanyBrandsController::class, 'store'])->name('.company-brands');

#

hundreds of routes

maiden palm
#

😦

rancid olive
#

because at first, every user could manage only one company

#

and now they want to let the user manage many companies with roles

maiden palm
#

Well I'd recommend a route refactor, personally - but I guess using session is a fall back.

rancid olive
#

I'm just asking to know more about the approach

#

by the way thanks for your time

maiden palm
#

You lose the reliability of a url pointing to exactly what its doing, and you'll need to handle what happens if there is no company in the session.

rancid olive
#

the only thing that pushes me to use session is the refactoring (routes/controllers) I need to update

#

which is insanely annoying

supple jacinth
#

Like @maiden palm, I identify the current “company” in both my video on demand platform and multi-tenant CMS by putting the identifier in the URI, i.e.
/channels/{channel:uuid}/admin/videos/{video}/edit
/websites/{website:uuid}/admin/articles/{article}/edit

#

The advantage of this is then you can scope route bindings, so that if video-a belongs to channel-a, then it can only be accessed and edited if the {channel} parameter is channel-a.

/channels/channel-a/admin/videos/video-a/edit -> 200 OK
/channels/channel-b/admin/videos/video-a/edit -> 404 Not Found
maiden palm
#

And call me old fashioned, but if I bookmark a page or come back to it later it should be what I expect it to be.

rancid olive
supple jacinth
#

Joys of development 🙂

rancid olive
#

@supple jacinth I get you're also against the sessions

supple jacinth
#

Requirements change. Usually the code needs to as well.

rancid olive
#

I totally get why sessions aren't the good approach to go with

rancid olive
rancid olive
#

you're with or against it?

#

Because I won't know which company slug to structure the url with

supple jacinth
rancid olive
#

And also a dropdown menu in the dash-nav to let theu user switch between the companies

#

I guess I should check if the user has many companies or just one

#

to skip the selection page if they have only one, right?

supple jacinth
#

Yeah. I’ve done a redirect to the “first” company is a user only has one in the past.

rancid olive
#

awesome!

supple jacinth
#

I just have a dropdown in the nav menu if a user is associated with more than one website.

rancid olive
#

Thank you so much for your assistance @supple jacinth @maiden palm

#

Should I delete this thread or keep it for admins?

supple jacinth
rancid olive
supple jacinth
rancid olive
#

the user can go to the front side of the platform and maybe come back to the dashboard, should I always ask him which company to manage if he has many?

rancid olive
supple jacinth
rancid olive