sissokho / laravel-dev-joke
This package offer a simple way to fetch a random dev joke from the DevJoke API
Requires
- php: ^8.1 || ^8.2
- illuminate/console: ^9.0 || ^10.0
- illuminate/support: ^9.0 || ^10.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.4
- laravel/pint: ^1.1
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0
- orchestra/testbench: ^7.0 || ^8.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2025-04-15 22:13:50 UTC
README
This package offer a simple way to fetch a random dev joke from this DevJoke API.
Prerequisites
This package requires:
- PHP 8.1 or higher
- Laravel 9.0 or higher
If you are on the PHP version 8.0 just use an older version of this package.
Installation
You can install the package via composer:
composer require sissokho/laravel-dev-joke
Usage
This package can be used by resolving the Sissokho\LaravelDevJoke\DevJoke
class from the container or by injecting it into a method:
use Sissokho\LaravelDevJoke\DevJoke; public function joke(DevJoke $devJoke) { $joke = $devJoke->random(); $joke->question; // retrieve the question $joke->punchline; // retrieve the punchline $joke->toArray(); // ['question' => 'lorem', 'punchline' => 'ipsum'] }
The randomJoke
method will return a Sissokho\LaravelDevJoke\DataTransferObjects\Joke
object, which includes the question and the punchline of the joke;
You can also use the Facade:
use Sissokho\LaravelDevJoke\Facades\DevJoke; $joke = DevJoke::random();
Artisan
An artisan command is provided for you to display a random joke:
php artisan devjoke
The joke is displayed like this:
Testing
You can run PHPUnit tests, PHPStan/Larastan static analysis and inspect the code for style errors without changing the files (with Laravel Pint):
composer test
However, you can run these tests separately.
- Static analysis:
composer test:types
- PHPUnit tests:
composer test:unit
- Code inspection:
composer test:style
To fix code style issues, run the following command:
composer stylefix
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
Huge thanks to @askudhay for providing this API.
License
The MIT License (MIT). Please see License File for more information.