Download the PHP package enriko/laravel-attribute-restrictor without Composer

On this page you can find all versions of the php package enriko/laravel-attribute-restrictor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-attribute-restrictor

LaravelAttributeRestrictor

This package offers an easy way to hide specific attributes from a model to specific situations. You can hide important data to specific users by using a trait with a couple of methods. Every other place that uses the model's data, will be restricted

How to use

Install

Install the package from packagist using composer:

(Recomended) Publish the config file:

Configure

Add the RestrictedAttributes Trait to your model:

Choose the attributes you wish to restrict with the getRestrictedAttributes method:

Define the restrictions conditions by:

Specific definition using getAttributeRestrictions

If the attribute's condition is false, the attribute will be replaced:

Specific definition using array

Same as the previous options, but expects an array returning method:

Globally restriction

Defines a single restriction, if it's false, all attributes defined on getRestrictedAttributes will be restricted

Define the substitute text

If the attribute is restricted, you can return something else in it's place. If you published the config file, you can modify it on:

root\config\enriko\attribute-restriction.php

But, you can also set individual messages for the model using the getReplacedText method:

Get the data

Finally, when you get the model's data, it will validate the restrictions. If your user pass, it'll see the info, unchanged. If not, it'll be replaced by the substitute restriction text.

Examples

Imagine a User model with the following data:

id name account_number
1 Foo 12345
2 Bar 55555
3 Baz 00220

Normally, if you use $User->get(), you will get:

Now, let's say we configure the account_number as restricted. If the user can't access this information, $User->get() will return:

Same thing for using $User->only(['name', 'account_number']) and $User->account_number.

Get original data

Sometimes, you might want to deal with the data, in this case, you don't want it to be substituted by some generic text.

Fundamentally, the restriction works as another cast, so you can ignore with by using getRawOriginal:


All versions of laravel-attribute-restrictor with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
laravel/framework Version ^11.9
laravel/tinker Version ^2.9
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package enriko/laravel-attribute-restrictor contains the following files

Loading the files please wait ....