PHP code example of ymigval / laravel-sl-response
1. Go to this page and download the library: Download ymigval/laravel-sl-response library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ymigval / laravel-sl-response example snippets
use Ymigval\LaravelSLResponse\Facades\SLResponse;
use Ymigval\LaravelSLResponse\Exceptions\SLException;
// Collection of users
return SLResponse::ok(User::all());
// A User resource
return SLResponse::ok(new UserResource(User::find(1)));
// If you want to disable the outermost wrapping.
return SLResponse::ok(UserResource::collection(User::paginate(10)))
->withoutWrapping();
// Attach additional messages.
return SLResponse::ok(User::find(6)->isAdmin())
->withMessage("This user is an admin");
// Return an error response.
return SLResponse::error('Limit exceeded');
// Additionally, you can add an error code as the second argument.
return SLResponse::error('Limit exceeded', '3748');
// Throw an exception
throw new SLException('This is a message.');
bash
php artisan vendor:publish --tag="slresponse"