PHPackages                             agandra/amp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. agandra/amp

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

agandra/amp
===========

Improving Laravel functionality and creating a base reusable code across projects

197[1 issues](https://github.com/agandra/amp/issues)PHP

Since Oct 14Pushed 11y ago1 watchersCompare

[ Source](https://github.com/agandra/amp)[ Packagist](https://packagist.org/packages/agandra/amp)[ RSS](/packages/agandra-amp/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

AMP functionality
=================

[](#amp-functionality)

This is a plugin to help me structure projects and stop me from rebuilding the same core elements for every project. The aim of this project is to extend some of the core laravel functionality, and generate boilerplate to jumpstart projects.

#### Composer Install

[](#composer-install)

```
"require": {
    "agandra/amp": "dev-master"
}

```

#### Import config setting and run migrations

[](#import-config-setting-and-run-migrations)

```
php artisan config:publish agandra/amp

```

#### Include Service Provider

[](#include-service-provider)

```
\Agandra\Amp\Providers\AmpServiceProvider

```

### AMP Philosophy

[](#amp-philosophy)

This package should be primarily used for large packages where the standard Laravel structure does not provide enough organization. Projects will be broken down into 3 main components: Models, Services, and Repos. Each component serves a unique purpose.

#### Models

[](#models)

These are the standard model files that inherit from \\Eloquent. Each instance of a model represents one row from the table. We do not use these model files to build queries to get results, in controllers. We do not create instances of the Models in the controller files, we should only be manipulating these model files in Services and Repos.

#### Repos

[](#repos)

Repos are used to collect data from your datasources. Repos can be used to combine multiple models and obtain relevent datasets. The idea behind calling a Repo to collect data instead of just doing Model::get() is to be able to filter data sets without having to change calls throughout the code.

Usually you gather data from the Repo by calling the query Method: Repo-&gt;query($params); In the params you pass an array of attributes you want the dataset to return. Query method will return a DB builder instance.

Repo's also have other helpers such as find, and findOrFail.

For instance, say you are developing an Item Model, for users to purchase items. And throughout the code you have multiple calls to $item-&gt;get(); to return the relevent items. Now lets say you add an attribute to the items table 'purchasable'. If this field is set to true, only then do you want the relevent rows to be returned. Instead of going everywhere through the code and adding $item-&gt;where('purchasable','=',true)-&gt;get(), you can add one line in your query method to change what is returned on every repo call.

This is a very basic example and real world usages will get much more complex. But it is convenient to have one method where you gather your dataset.

#### Services

[](#services)

Services are repeatable actions to manipulate data. Services can consist of actions such as sending emails to users, or creating models, editing models, or deleting. Usually services pertain to actions or manipulating data.

### AMP Validator

[](#amp-validator)

The AMP validator works by setting the rules and customMessages array in a model. Then we pass the class and input to the amp validator instance. The advantage of the AMP validator is the use of multiple contexts. Instead of a one dimensional array for rules, it can now be multi dimensional to allow for different rulesets to be allowed in different circumstances.

Example rules attribute:

```
$rules = [
			'create'=>
				['name'=>'required'],
			'edit'=>
				['price'=>'required','value'=>'numeric'],
			'other_context'=>
				['name'=>'required']
		];

```

The validator will only use the context specified when created. For instance:

```
$validator = \Amp::validator($input, new User);
$validator->addContext('create');
if($validator->fails())
	throw new Exception;

```

You can also add multiple contexts to one validator, and it will merge the rulesets and validate all of them.

### AMP Model

[](#amp-model)

The AMP Model comes with an auto save feature to make saving user input easy. It will automatically use the AMP Validator and pass the correct context.

```
if($user->autoSave()) {
	// Passes the save
} else {
	// Save has failed
	throw new Exception($user->messages());
}

```

If the autosave fails, then there will be validation errors, that you can obtain by calling the messages method of the model.

The AMP model also has hooks to call before and after saving, and validation. You can also set the autoHash attribute on the model and it will hash the value before saving to the database. The saving is also done in a DB Transaction, so if any errors or thrown or the before or after save generate errors, the entire database will remain unchanged.

To use the AMP Model, make your model file extend \\Agandra\\Amp\\Base\\AmpModel

### AMP Reply

[](#amp-reply)

### API

[](#api)

### AMP

[](#amp)

The main AMP class is just a helper to access the different attributes available through the AMP project. For instance to access a repo just call

```
\Amp::repo('RepoName')->query();

```

To get an instance of the validator just call

```
\Amp::validator($input, $class);

```

Of course these elements are available without calling AMP but are made easier through this class.

###  Health Score

17

—

LowBetter than 8% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/68a2f5b89a65afa952eeb462926a7fa23ca050278a0bd58f4efb0a78ab0a53a3?d=identicon)[agandra](/maintainers/agandra)

---

Top Contributors

[![agandra](https://avatars.githubusercontent.com/u/1072647?v=4)](https://github.com/agandra "agandra (24 commits)")

### Embed Badge

![Health badge](/badges/agandra-amp/health.svg)

```
[![Health](https://phpackages.com/badges/agandra-amp/health.svg)](https://phpackages.com/packages/agandra-amp)
```

###  Alternatives

[alfonsobries/nova-froala-editor

A Laravel Nova froala editor field.

1710.0k](/packages/alfonsobries-nova-froala-editor)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
