Created
March 13, 2020 19:15
-
-
Save AhmedHelalAhmed/fa770c693b7520b1830b7efebb506726 to your computer and use it in GitHub Desktop.
example for helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!function_exists('user')) { | |
/** | |
* Get the authenticated user. | |
* | |
* @return \App\Models\Auth\User | |
*/ | |
function user() | |
{ | |
// Get user from api/web | |
if (request()->is('api/*')) { | |
$user = app('Dingo\Api\Auth\Auth')->user(); | |
} else { | |
$user = auth()->user(); | |
} | |
return $user; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if (!function_exists('user')) ===> important so that if the method exists somwhere not to use this method