PHPackages                             spatie/laravel-or-abort - 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. spatie/laravel-or-abort

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

spatie/laravel-or-abort
=======================

A trait to add OrAbort functions to a class

1.0.2(10y ago)534.0k21MITPHPPHP &gt;=5.4.0

Since Jun 17Pushed 4y ago6 watchersCompare

[ Source](https://github.com/spatie/laravel-or-abort)[ Packagist](https://packagist.org/packages/spatie/laravel-or-abort)[ Docs](https://github.com/spatie/laravel-or-abort)[ RSS](/packages/spatie-laravel-or-abort/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (5)Used By (1)

**THIS PACKAGE ISN'T MAINTAINED ANYMORE**

A trait to optionally abort a Laravel application
=================================================

[](#a-trait-to-optionally-abort-a-laravel-application)

[![Latest Version on Packagist](https://camo.githubusercontent.com/05072651598ef893004339572d8db329dde4435196b67ef03a7454573d158740/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d6f722d61626f72742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-or-abort)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/6c84c1aa5edd45c4a070efa40a03bac0c895198345a21d21497c0f9dcd16228e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7370617469652f6c61726176656c2d6f722d61626f72742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/spatie/laravel-or-abort)[![SensioLabsInsight](https://camo.githubusercontent.com/dbe7f145098ffee49411e6d3b6eec7ef1f722e73ae638d02139f9b2c11b94b94/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f66393161393436612d383365352d343035662d383534362d3463666436613239623933652e7376673f7374796c653d666c61742d737175617265)](https://insight.sensiolabs.com/projects/f91a946a-83e5-405f-8546-4cfd6a29b93e)[![Quality Score](https://camo.githubusercontent.com/b6c1cf729f8b73411c4422b18d156fdf4f9d92e863ae18a68e9486261da1b4ec/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f6c61726176656c2d6f722d61626f72742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/laravel-or-abort)[![Total Downloads](https://camo.githubusercontent.com/82593addc441ab3f5cb56dfc12eebf787db04dc59ba041b3ec74eeee7a6240c0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d6f722d61626f72742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-or-abort)

This package adds an `OrAbort`-trait to your Laravel project. You can use it for example to choose your abort code when a `find`-call returns false.

```
 $eloquentModel->findOrAbort($modelId, 500);
```

Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/0535b70db5ee7f2d74709d32c63cbc770d08592dee7ce09f0539b911bb61406b/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d6f722d61626f72742e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-or-abort)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Postcardware
------------

[](#postcardware)

You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

The best postcards will get published on the open source page on our website.

Install
-------

[](#install)

You can install the package via composer:

```
$ composer require spatie/laravel-or-abort
```

Usage
-----

[](#usage)

You can use the `Spatie\OrAbort\OrAbort`-trait on any class you want. All the methods of the class will gain `orAbort`-variant. When the original function returns a falsy value Laravel's `abort`-function will be called with code 404.

Why in the world would you want use this trait?

If you use repositories you probably have written this kind of code:

```
$article = $articleRepository->find($articleId) ?: abort(404);
```

By using this trait on your repository you can write it a bit more readable:

```
$article = $articleRepository->findOrAbort($articleId);
```

You can even add an extra parameter to specify an abort code.

```
$article = $articleRepository->findOrAbort($articleId, 500);
```

If the `find`-function on your repository returns a falsy value `abort(500)` will be called.

A word to the wise
------------------

[](#a-word-to-the-wise)

The `orAbort`-trait uses the magic method `__call`. If your class already implements that call, you shouldn't use our trait.

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://murze.be)
- [All Contributors](../../contributors)

About Spatie
------------

[](#about-spatie)

Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

This package was inspired by [this article](http://tech.mybuilder.com/optional-value-control-flows-in-php-using-traits-and-magic-methods/) by [Edd Mann](https://twitter.com/edd_mann)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 73.9% 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.

###  Release Activity

Cadence

Every ~4 days

Total

4

Last Release

3970d ago

Major Versions

0.0.1 → 1.0.02015-06-17

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (17 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (4 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (2 commits)")

---

Tags

phpsyntaxspatielaravelabort

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spatie-laravel-or-abort/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-or-abort/health.svg)](https://phpackages.com/packages/spatie-laravel-or-abort)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[spatie/laravel-feed

Generate rss feeds

9743.6M28](/packages/spatie-laravel-feed)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[spatie/laravel-pjax

A pjax middleware for Laravel 5

513371.8k11](/packages/spatie-laravel-pjax)

PHPackages © 2026

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