PHP code example of dees040 / laravel-api-responses
1. Go to this page and download the library: Download dees040/laravel-api-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/ */
dees040 / laravel-api-responses example snippets
namespace App\Http\Controllers;
use App\User;
use App\Http\Controllers\Controller;
class UsersController extends Controller
{
/**
* Show the given user.
*
* @param \App\User $user
* @return \Illuminate\Http\Response
*/
public function show(User $user)
{
if (! $user->isAdmin()) {
return forbidden();
}
return ok($user);
}
}
error_json_response('User not found.', [
'id' => 'The ID does not exists.'
]);