PHP code example of sanchescom / laravel-rest

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

    

sanchescom / laravel-rest example snippets


'providers' => [
    ...
    Sanchescom\Rest\RestServiceProvider::class,
],

$app->register(Sanchescom\Rest\RestServiceProvider::class);

'default' => env('REST_CLIENT', 'localhost'),



return [
    'clients' => [
        'localhost' => [
            'provider' => 'guzzle',
            'base_uri' => 'https://localhost/',
            'options' => [
                'headers' => [
                    'Content-Type' => 'application/json',
                ],
            ],
        ],
    ],
];



use Sanchescom\Rest\Model;

class User extends Model {
    /** {@internal} */
    protected $dataKey = 'data';

    /** {@internal} */
    protected $fillable = [
        "id",
        "first_name",
        "last_name",
        "email",
    ];
}

$users = User::get();

$user = User::get('1');

$users = User::getMany(['1', '2']);

$users = User::get()->where('first_name', 'Bob');

User::post(['first_name' => 'Tim']);

$user = User::get('2');
$user->email = '[email protected]';
$user->put();

User::put('2', ['email' => '[email protected]']);

$user = User::get('1');
$user->delete();

User::delete('1');