2017 © Pedro Peláez
 

library laravel-or-abort

A trait to add OrAbort functions to a class

image

spatie/laravel-or-abort

A trait to add OrAbort functions to a class

  • Friday, July 29, 2016
  • by Spatie
  • Repository
  • 7 Watchers
  • 56 Stars
  • 3,157 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 5 Versions
  • 2 % Grown

The README.md

THIS PACKAGE ISN'T MAINTAINED ANYMORE, (*1)

A trait to optionally abort a Laravel application

Latest Version on Packagist Software License Build Status SensioLabsInsight Quality Score Total Downloads, (*2)

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., (*3)

 $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., (*4)

Support us

, (*5)

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products., (*6)

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. We publish all received postcards on our virtual postcard wall., (*7)

Postcardware

You're free to use this package (it's MIT-licensed), 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., (*8)

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium., (*9)

The best postcards will get published on the open source page on our website., (*10)

Install

You can install the package via composer: ``` bash $ composer require spatie/laravel-or-abort, (*11)


## 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: ```php $article = $articleRepository->find($articleId) ?: abort(404);

By using this trait on your repository you can write it a bit more readable:, (*12)

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

You can even add an extra parameter to specify an abort code., (*13)

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

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

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., (*15)

Change log

Please see CHANGELOG for more information what has changed recently., (*16)

Testing

bash $ composer test, (*17)

Contributing

Please see CONTRIBUTING for details., (*18)

Security

If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker., (*19)

Credits

About Spatie

Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website., (*20)

This package was inspired by this article by Edd Mann, (*21)

License

The MIT License (MIT). Please see License File for more information., (*22)

The Versions

29/07 2016

dev-master

9999999-dev https://github.com/spatie/laravel-or-abort

A trait to add OrAbort functions to a class

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel spatie abort

30/06 2015

1.0.2

1.0.2.0 https://github.com/spatie/laravel-or-abort

A trait to add OrAbort functions to a class

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel spatie abort

26/06 2015

1.0.1

1.0.1.0 https://github.com/spatie/laravel-or-abort

A trait to add OrAbort functions to a class

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel spatie abort

17/06 2015

1.0.0

1.0.0.0 https://github.com/spatie/laravel-or-abort

A trait to add OrAbort functions to a class

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel spatie abort

17/06 2015

0.0.1

0.0.1.0 https://github.com/spatie/laravel-or-abort

A trait to add OrAbort functions to a class

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel spatie abort