app/Http/Controllers/Controller.php
/**
     * Returns the company for the currently authenticated user, returns NULL otherwise.
     *
     * @param Request|null $request
     * @param bool         $throwExceptionOnFail
     * @param bool         $enforcePlanAccess
     *
     * @return null|Company
     * @throws AuthorizationException
     * @throws RecordNotFoundException
     */
Returns the company for the currently authenticated user, returns NULL otherwise.
@param Request|null $request
@param bool         $throwExceptionOnFail
@param bool         $enforcePlanAccess


Returns the company for the currently authenticated user returns NULL otherwise . @param Request|null $request @param bool $throwExceptionOnFail @param bool $enforcePlanAccess
protected function company(Request $request = null, bool $throwExceptionOnFail = true, bool $enforcePlanAccess = true)
    {
        if (empty($request)) {
            $request = app('request');
        }
        $user = $request->user();
        if (empty($user)) {
            if ($throwExceptionOnFail) {
                throw new RecordNotFoundException('Sorry, we cannot retrieve your company because you are not authenticated.');
            }
            return null;
        }
        $company = $user->company;
        if (empty($company) && $throwExceptionOnFail) {
            throw new RecordNotFoundException('Sorry, we could not retrieve the company information for your account.');
        }
        if (!$enforcePlanAccess) {
            return $company;
        }
        $plan = $company->plan;
        if ($plan->price_monthly > 0) {
            if (empty($company->access_expires_at)) {
                throw new AuthorizationException(
                    'You have not yet paid the subscription fee for your selected plan ('.title_case($plan->name).')'
                );
            } elseif (Carbon::now()->greaterThan($company->access_expires_at)) {
                throw new AuthorizationException(
                    'Your access for the '.title_case($plan->name) . ' plan expired on '.
                    $company->access_expires_at->format('D jS M, Y')
                );
            }
        }
        return $company;
    }
protected function company ( Request $ request = null , bool $ throwExceptionOnFail = true , bool $ enforcePlanAccess = true ) { if ( empty ( $ request ) ) { $ request = app ( 'request' ) ; } $ user = $ request -> user ( ) ; if ( empty ( $ user ) ) { if ( $ throwExceptionOnFail ) { throw new RecordNotFoundException ( 'Sorry, we cannot retrieve your company because you are not authenticated.' ) ; } return null ; } $ company = $ user -> company ; if ( empty ( $ company ) && $ throwExceptionOnFail ) { throw new RecordNotFoundException ( 'Sorry, we could not retrieve the company information for your account.' ) ; } if ( ! $ enforcePlanAccess ) { return $ company ; } $ plan = $ company -> plan ; if ( $ plan -> price_monthly > 0 ) { if ( empty ( $ company -> access_expires_at ) ) { throw new AuthorizationException ( 'You have not yet paid the subscription fee for your selected plan (' . title_case ( $ plan -> name ) . ')' ) ; } elseif ( Carbon :: now ( ) -> greaterThan ( $ company -> access_expires_at ) ) { throw new AuthorizationException ( 'Your access for the ' . title_case ( $ plan -> name ) . ' plan expired on ' . $ company -> access_expires_at -> format ( 'D jS M, Y' ) ) ; } } return $ company ; }
Returns the company for the currently authenticated user, returns NULL otherwise.
Returns the company for the currently authenticated user returns NULL otherwise .
# get the user # we're not checking plan access # get the plan the company is on