1. Go to this page and download the library: Download gem-partij/gemboot-lara 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/ */
gem-partij / gemboot-lara example snippets
use App\Models\User;
class UserControllerApi extends Controller {
// method to return all users
public function index() {
$status = 200;
$message = 'Success!';
$data = [];
try {
// add user data to response
$data = User::all();
} catch(\Exception $e) {
// if catch error...
// log error
\Log::error($e->getMessage());
\Log::error($e->getTraceAsString());
// add error response
$status = 500;
$message = "Internal Server Error";
$data = [
'error' => $e->getMessage(),
];
}
// return response json
return response()->json([
'status' => $status,
'message' => $message,
'data' => $data,
], $status);
}
}
use GembootResponse;
use App\Models\User;
class UserControllerApi extends Controller {
// method to return all users
public function index() {
return GembootResponse::responseSuccessOrException(function() {
return User::all();
});
}
}