DEV Community

Discussion on: Multiple role-based authentication in Laravel

Collapse
 
picwellwisher12pk profile image
Amir Hameed

What about switch statement?

Collapse
 
martin_betz profile image
Martin Betz

Yes, switch would cut some duplicate lines. I would still propose the lookup array pattern as recommended in this extra comment as it is a lot easier to add and cut arguments and is super easy to read.

Thread Thread
 
picwellwisher12pk profile image
Amir Hameed

These if statements could also be one-liners to save some more characters and space.

Thread Thread
 
martin_betz profile image
Martin Betz

Yes, but there still would be lots of repetitions even in short-form. Maybe I can write an own article soon about possible refactorings so that people can learn and compare. The original poster went with the simple if solution but there are multiple ways to make it shorter and easier to maintain.

Thread Thread
 
picwellwisher12pk profile image
Amir Hameed

Indeed.
Tell me where can I start a new discussion?

Thread Thread
 
martin_betz profile image
Martin Betz

Just put a comment on the root of this article: dev.to/kaperskyguru/multiple-role-...