Closed johndalangin closed 10 years ago
I think another use case would be creating functions for every type of user for various purposes such as templating.
For example, if I had different types of 3 different types of users, I'd currently have to create 3 different templates for all of them since I can't access the current user without specifying a type prefix.
Thanks!
You could do something like this:
$users = array();
foreach (Config::get('auth.multi') as $type => $config) {
if (Auth::$type()->check()) {
$users[] = Auth::$type()->get();
}
}
return $users;
This package was created with the idea in mind that the different user types would be fairly separate so that shouldn't really be the case. If you have three types of users that access the same stuff, you should really be using a single table. That being said, there's no way to do so as it's perfectly possible to be logged in as all of the different types of users, at the same time.
Thanks mcampa! That's a pretty awesome solution!
I think what I'm trying to say is that there should be a set of helper functions to serve as convenience methods for accessing the current user without having to know its type.
mcampa has a pretty convenient solution right there and I'll think I'll go and use something similar to that (although I'd definitely like to develop something that does not involve recursion for performance reasons.
In any case, thanks guys!
Like I said, multi user table designs should never hit that problem as there shouldn't be a situation where the same thing is being done for a different type of user. Anyway, glad you found a solution.
Hello!
Wonderful plugin by the way!
Just wondering if there was a way to reference the current user without the type prefix (e.g., Auth::user_type()->get() without the user_type()).
I think there are a lot of use cases where you would like to programmatically access the current user, moreso when the type of user is unknown at runtime.
Thanks and and a prompt response is highly appreciated!
Cheers!