ModuleAccess.php 939 Bytes
<?php namespace App\Http\Middleware;

use Closure;
use Route;
use Auth;

class ModuleAccess {

	public function __construct()
	{
		
	}

	/**
	 * Handle an incoming request.
	 *
	 * @param  \Illuminate\Http\Request  $request
	 * @param  \Closure  $next
	 * @return mixed
	 */
	public function handle($request, Closure $next)
	{
	
  $rparts=explode(".",Route::currentRouteName());
  if(in_array($rparts[0],array("index","home","login","logout")));
  else
  {
    if($rparts[1]=="index"||$rparts[1]=="show")
      {if(!Auth::user()->moduleACL($rparts[0],true,false,false))return view('layout.noaccess',array("value"=>Route::currentRouteName()));}
    else if($rparts[1]=="create"||$rparts[1]=="store"||$rparts[1]=="edit"||$rparts[1]=="update"||$rparts[1]=="destroy")
      {if(!Auth::user()->moduleACL($rparts[0],true,true,false))return view('layout.noaccess',array("value"=>Route::currentRouteName()));}
  }

		return $next($request);
	}

}