All Projects → spatie → laravel-or-abort

spatie / laravel-or-abort

Licence: MIT license
A trait to optionally abort a Laravel application

Programming Languages

PHP
23972 projects - #3 most used programming language

Labels

Projects that are alternatives of or similar to laravel-or-abort

Lightscript
JavaScript, with cleaned-up syntax and a few conveniences.
Stars: ✭ 141 (+161.11%)
Mutual labels:  syntax
Vue Highlight.js
📜 Highlight.js syntax highlighter component for Vue.
Stars: ✭ 180 (+233.33%)
Mutual labels:  syntax
Chroma
A general purpose syntax highlighter in pure Go
Stars: ✭ 3,013 (+5479.63%)
Mutual labels:  syntax
Udify
A single model that parses Universal Dependencies across 75 languages. Given a sentence, jointly predicts part-of-speech tags, morphology tags, lemmas, and dependency trees.
Stars: ✭ 147 (+172.22%)
Mutual labels:  syntax
Command
A library to build command line applications using PHP
Stars: ✭ 164 (+203.7%)
Mutual labels:  syntax
Ifmt
Inline expression interpolation for Rust.
Stars: ✭ 197 (+264.81%)
Mutual labels:  syntax
Sugar Rs
Rust syntax sugar collections.
Stars: ✭ 125 (+131.48%)
Mutual labels:  syntax
postcss-jsx
PostCSS syntax for parsing CSS in JS literals
Stars: ✭ 73 (+35.19%)
Mutual labels:  syntax
Lexical syntax analysis
编译原理词法分析器&语法分析器LR(1)实现 C++
Stars: ✭ 173 (+220.37%)
Mutual labels:  syntax
Vim Cpp Modern
Extended Vim syntax highlighting for C and C++ (C++11/14/17/20)
Stars: ✭ 229 (+324.07%)
Mutual labels:  syntax
Burrido
Do-notation for JavaScript
Stars: ✭ 150 (+177.78%)
Mutual labels:  syntax
React Ast
render abstract syntax trees with react
Stars: ✭ 160 (+196.3%)
Mutual labels:  syntax
Linqit
Extend python lists with .NET's LINQ syntax for clean and fast coding. Also known as PINQ.
Stars: ✭ 222 (+311.11%)
Mutual labels:  syntax
Ecsharp
Home of LoycCore, the LES language of Loyc trees, the Enhanced C# parser, the LeMP macro preprocessor, and the LLLPG parser generator.
Stars: ✭ 141 (+161.11%)
Mutual labels:  syntax
Haskell Symbol Search Cheatsheet
Haskell/GHC symbol search cheatsheet
Stars: ✭ 243 (+350%)
Mutual labels:  syntax
Es.next.syntax.vim
ES.Next syntax for Vim
Stars: ✭ 125 (+131.48%)
Mutual labels:  syntax
Phpgrep
Syntax-aware grep for PHP code.
Stars: ✭ 185 (+242.59%)
Mutual labels:  syntax
nova-vue
Vue support for Nova editor.
Stars: ✭ 35 (-35.19%)
Mutual labels:  syntax
berkeley-parser-analyser
A tool for classifying mistakes in the output of parsers
Stars: ✭ 34 (-37.04%)
Mutual labels:  syntax
Clarifyjs
Create and Execute Chained Javascript Methods In Any Order You want
Stars: ✭ 227 (+320.37%)
Mutual labels:  syntax

THIS PACKAGE ISN'T MAINTAINED ANYMORE

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.

Support us

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.

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.

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, Kruikstraat 22, 2018 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 [email protected] 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].