PHP code example of thiagoprz / laravel-enforce-json

1. Go to this page and download the library: Download thiagoprz/laravel-enforce-json 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/ */

    

thiagoprz / laravel-enforce-json example snippets



...
use Thiagoprz\EnforceJson\EnforceJson;

class Kernel extends HttpKernel
...
    protected $routeMiddleware = [
        ...
        'json' => EnforceJson::class,
    ];


...
// Example: user login
Route::post('/register', 'AuthenticationController@register')->middleware('json');
...
// Example: upload of photo (note that you must pass true as first argument to the middleware allowing uploads) 
Route::post('/uploadAvatar', 'ProfileController@uploadAvatar')->middleware('json:true');
...