shalvah / laravel-jsend Goto Github PK
View Code? Open in Web Editor NEWSimple helpers to generate JSend-compliant JSON responses
Home Page: http://shalvah.me/laravel-jsend/
License: MIT License
Simple helpers to generate JSend-compliant JSON responses
Home Page: http://shalvah.me/laravel-jsend/
License: MIT License
When I add the trait to App\Exceptions\Handler
as shown in the docs I get the following error:
Trait 'App\Exceptions\Shalvah\LaravelJsend\JsendExceptionFormatter' not found
Can you please point out where I am going wrong with using it in this file?
Error:
Declaration of Shalvah\LaravelJsend\JsendExceptionFormatter::prepareJsonResponse($request, Exception $e)
should be compatible with Illuminate\Foundation\Exceptions\Handler::prepareJsonResponse($request, Throwable $e)
My Handler Code
<?php
namespace App\Exceptions;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Shalvah\LaravelJsend\JsendExceptionFormatter;
use Throwable;
use Illuminate\Database\Eloquent\ModelNotFoundException;
class Handler extends ExceptionHandler
{
use JsendExceptionFormatter;
/**
* A list of the exception types that are not reported.
*
* @var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* @var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* @param \Throwable $exception
* @return void
*
* @throws \Exception
*/
public function report(Throwable $exception)
{
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Throwable $exception
* @return \Symfony\Component\HttpFoundation\Response
*
* @throws \Throwable
*/
public function render($request, Throwable $exception)
{
if ($exception instanceof ModelNotFoundException) {
return response()->json([
'error' => 'Entry for '.str_replace('App\\', '', $exception->getModel()).' not found'], 404);
}
return parent::render($request, $exception);
}
}
Please. Include #6 or add support for Laravel 7.
PHP: 7.4 and 8.0
Laravel 8.0.42.1
Adding
use Shalvah\LaravelJsend\JsendExceptionFormatter;
to my app/Exceptions/Handler.php
class causes composer dumpautoload
to break
composer dumpautoload
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 255
simply removing that line, composer dumpautoload
returns to work
composer dumpautoload
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fideloper/proxy
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
Generated optimized autoload files containing 4696 classes
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.