laravel-or-abort

A trait to optionally abort a Laravel application

  • 所有者: spatie/laravel-or-abort
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

A trait to optionally abort a Laravel application

Latest Version on Packagist
Software License
Build Status
SensioLabsInsight
Quality Score
Total Downloads

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.

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.

Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium.

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

Install

You can install the package via composer:

$ composer require spatie/laravel-or-abort

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

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

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

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

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.

This package was inspired by this article by Edd Mann

License

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

主要指標

概覽
名稱與所有者spatie/laravel-or-abort
主編程語言PHP
編程語言PHP (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2015-06-17 11:28:16
推送於2022-01-19 10:46:17
最后一次提交2022-01-19 11:46:17
發布數4
最新版本名稱1.0.2 (發布於 )
第一版名稱0.0.1 (發布於 )
用户参与
星數53
關注者數7
派生數2
提交數23
已啟用問題?
問題數1
打開的問題數0
拉請求數0
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?