Use custom helper functions for +readability

Posted 2 years ago by SaeedPrez

Hey guys,

Just a little tip/reminder to use custom helpers to make your code more readable..

Let's take the simple auth()->check() as an example. Instead of this:

    <!-- Authenticated User Navbar -->

@if(auth()->check() && auth->user()->admin == 1)
    <!-- Admin Navbar -->
@endif could do this..

    <!-- Authenticated User Navbar -->

    <!-- Admin Navbar -->

Your imagination sets the limit. Creating a custom helper takes a few seconds and can make your code much more readable and perhaps even save time.

 * Check if user is logged in
 * @return boolean
function userIsLoggedIn()
    return auth()->check();

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.