PHP code example of kriit24 / project-rest-server

1. Go to this page and download the library: Download kriit24/project-rest-server 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/ */

    

kriit24 / project-rest-server example snippets


php artisan project-rest-server:install

//API dynamic request
Route::get('/fetch/{model_name}/{id?}', function (Request $request, $model, $id = null) {

    $primary_key = app("App\\Models\\" . $model)->getKeyName();    

    $to_request = \Project\RestServer\Http\Requests\ToRequest::Get();
    $to_request->request->add(['where' => array_filter([$primary_key => $id])]);    
    
    $event = new Project\RestServer\Broadcasting\DBBroadcast(
        Project\RestServer\Getter\MysqlGetter::class
    );
    $data = $event->fetch('channel_name', $model, $to_request);
    return response(['status' => 'ok', 'count' => count($data), 'data' => $data]);
});
//https://localhost/fetch/object
//https://localhost/fetch/address
//https://localhost/fetch/client
//...