PHP code example of democracyapps / member-org

1. Go to this page and download the library: Download democracyapps/member-org library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

democracyapps / member-org example snippets


    // app/config/app.php
    
    'providers' => [
        '...',
        'DemocracyApps\MemberOrg\MemberOrganizationServiceProvider',
    ];

    class Company extends Model
    {
     ...
    }

    use DemocracyApps\MemberOrg\EloquentMemberOrganization;
    use DemocracyApps\MemberOrg\Organization;

    class Company implements MemberOrganization
    {
        use EloquentMemberOrganization;
        ...
    }

    use DemocracyApps\MemberOrg\EloquentOrganizationMember;
    use DemocracyApps\MemberOrg\OrganizationMember;

    class CompanyMember implements OrganizationMember
    {
        use EloquentOrganizationMember;
        ...
    }

    class VerifyCompanyAccess {
    
    	/**
    	 * Check that user is logged in and allowed access to this page
    	 *
    	 * @param  \Illuminate\Http\Request  $request
    	 * @param  \Closure  $next
    	 * @return mixed
    	 */
    	public function handle($request, Closure $next)
    	{
            if (\Auth::guest()) return redirect()->guest('/auth/login');
    
            $id = $request->segment(2);
            $company = Company::find($id);
    
            if ($company == null) {
                return redirect('/');
            }
    
            if (! $company->userHasAccess(\Auth::user(), 9)) {
                return redirect('/');
            }
    
    		return $next($request);
    	}
    
    }