vanchelo / laravel-custom-responses
This package is abandoned and no longer maintained.
No replacement package was suggested.
Laravel Custom Responses
1.0.0
2014-12-01 15:05 UTC
Requires
- php: >=5.4.0
- laravel/framework: 4.2.*
This package is not auto-updated.
Last update: 2022-01-17 13:45:59 UTC
README
#Laravel Custom Responses
##Install
Require this package with composer:
composer require "vanchelo/laravel-custom-responses dev-master"
After updating composer, add the ServiceProvider to the providers array in app/config/app.php
'Vanchelo\CustomResponses\ResponsesServiceProvider'
Create responses
folder in app/views
and three blade templates:
defult.blade.php
, 403.blade.php
, 404.blade.php
##How to use
In controller:
class PageController extends Controller { public function index($id) { if ( ! $page = Page::find($id)) App::abort(404); // or if ( ! $page = Page::find($id)) return App::make(404); return View::make('page', compact('page')); } }
##Create you own custom response
For example we will create custom response for 401 (Unauthorized) status code.
- Create class and put it on your app folder
<?php namespace Acme\Responses; // app/Acme/Responses/Unauthorized.php class Unauthorized extends Response { protected $view = 'responses.401'; protected $defaultCode = 401; }
-
Create blade template
401.blade.php
and put it onapp/views/responses
-
Put this code in
app/start/gobal.php
:
App::bind('401', 'Acme\Responses\Unauthorized');
- That's all