PHP code example of vanchelo / laravel-custom-responses

1. Go to this page and download the library: Download vanchelo/laravel-custom-responses 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/ */

    

vanchelo / laravel-custom-responses example snippets


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'));
    }
}

 namespace Acme\Responses;

// app/Acme/Responses/Unauthorized.php

class Unauthorized extends Response
{
    protected $view = 'responses.401';
    protected $defaultCode = 401;
}

App::bind('401', 'Acme\Responses\Unauthorized');