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

This package is not auto-updated.

Last update: 2022-01-17 13:45:59 UTC


#Laravel Custom Responses

Описание на русском


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


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.

  1. 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;
  1. Create blade template 401.blade.php and put it on app/views/responses

  2. Put this code in app/start/gobal.php:

App::bind('401', 'Acme\Responses\Unauthorized'); 
  1. That's all