New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

smarch/omac

A simple ACL trait to allow authorization checks using whatever authorization package is desired. Currently supports Laravel Default, Shinobi, Sentinel and Entrust.
52 1

Larablocks Analysis

smarch/omac works with any PHP project: the latest release (v1.0.2, Jan 29, 2016) doesn't depend on Laravel.

Recommendation checks

Not advised

Not advised: no release or commit in over 2 years.

  • No release or commit in over 2 years
  • No release in the last 12 months (last: Jan 29, 2016)
  • 1 downloads a month (needs 10,000)
  • 1 GitHub star (needs 100)

State

Likely abandoned
  • No release or commit in over 2 years.
  • Last stable release: Jan 29, 2016.
  • No releases in the last 12 months.
  • First released: Jan 29, 2016.
  • Monthly downloads: 1.
  • 0 open issues on GitHub.

Data from Packagist and GitHub, checked by Larablocks on Dec 4, 2026.

Install
composer require smarch/omac
Latest Version:v1.0.2
PHP:>=5.5.9
License:MIT
Last Updated:Feb 2, 2016
Links: GitHub  ·  Packagist
Maintainer: landjea

This is probably only of use to me, but I have need of it in multiple apps so I packaged it up in case you want it too. :)


OMAC

A simple trait to allow basic authorization checks using whatever authorization package is desired. Currently supports Laravel Default, Shinobi, Sentinel and Entrust.

Installation

Installation is performed with composer.

:black_square_button: Composer
composer require "smarch/omac"

Usage

Where you want to use OMAC to check access, add the trait.

class YourController extends Controller
{
    use \Smarch\Omac\OmacTrait;

Once you have the OmacTrait in use, and you are happy with the authorization driver you are using (see parameters below), you can use the checkAccess() method of Omac by passing in the required permission to allow access.

Example of using OMAC to permit viewing an index of resources
/**
 * Display a listing of the resources.
 *
 * @return Response
 */
public function index()
{
    if ( $this->checkAccess('view.index') ) {
        $resources = Model::all();
        return view("index", compact($resources) );
    }

    return view("unauthorized", ['message' => 'Not authorized to view Index'] );
    // OR
    return false;
    // OR
    abort(401, 'Unauthorized action.');

}
Arguments

The checkAccess() method accepts both the $permission and an $arguments variable. So if your preferred authorization package accepts a second argument to its method, you can use it.

    if ( $this->checkAccess('update.post', $post) ) {

:hand: NOTE : Sentinel only accepts a $permission argument so you will not be able to pass in a second argument.

:hand: NOTE : Entrust only accepts a boolean (true/false) as it second argument.

Parameters (optional)

By default, OMAC is set to enabled and to use Laravel's built-in authorization can method. (Gate) If you wish to use a different authorization method, or to disable OMAC, you can change the parameters. You can do it in your class or method somewhere for a one-off usage, or you can set it on the constructor of your class to make the change for all the methods.

/**
 * constructor
 * 
 * @param boolean acl Whether or not ACL is enabled
 * @param string $driver Which ACL package to use
 */
public function __construct() {
    $this->acl = false;
    $this->driver = "sentinel";
}

:trident: Why "OMAC"?

I've been a DC geek for over 30 years now. While OMAC in DC is more of a "big brother is watching" type of thing, it still fits nicely with Object Managed Access Control. :smile:

Alternatives to smarch/omac

santigarcor/laratrust

This package provides a flexible way to add Role-based Permissions to Laravel

6,824,396 2,274
pktharindu/nova-permissions

Laravel Nova Grouped Permissions (ACL)

545,600 136
shanmuga/laravel-entrust

This package provides a flexible solution to add ACL to Laravel

389,191 67
casbin/laravel-authz

An authorization library that supports access control models like ACL, RBAC, ABA...

405,015 341
hasinhayder/tyro

Tyro is a complete Authentication, Authorization, and Role & Privilege (RBAC/ACL...

11,929 685

Version History

Version Released PHP License
v1.0.2 >=5.5.9 MIT
v1.0.1 >=5.5.9 MIT