1. Go to this page and download the library: Download flipboxstudio/api-fracture 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/ */
flipboxstudio / api-fracture example snippets
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Flipbox\Fracture\Routing\Controller as FractureController;
class Controller extends FractureController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
namespace App\Http\Controllers\Api;
use App\User;
use App\Http\Requests;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
Fracture::setMessage('user_list_fetched');
return User::all(); // identical with Fracture::responseCollection(User::all(), 'user_list_fetched')
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
Fracture::setMessage('user_fetched');
return User::findOrFail($id); // identical with Fracture::responseItem(User::findOrFail($id), 'user_fetched')
}
return Fracture::responseCollection(
$collection, // Collection
'user_list', // API Message
true, // API success status
200, // HTTP status code
['Custom-Header' => 'Flipbox'] // Your header goes here
);
return Fracture::responseItem(
$item, // Item
'user_info', // API Message
true, // API success status
200, // HTTP status code
['Custom-Header' => 'Flipbox'] // Your header goes here
);
return Fracture::responseError(
'awww_snap', // API Message
new \Exception('something_goes_wrong') // An exception instance
);
php artisan vendor:publish
app/Http/Controllers/Controller.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.