PHP code example of daniesy / rodels

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

    

daniesy / rodels example snippets


// config/app.php
'providers' => [
	'...',
	Daniesy\Rodels\RodelsServiceProvider::class
],

'aliases' => [
	'...',
	'Remote' => \Daniesy\Rodels\Facade\Remote::class,
],

public function index()
{
	$users = Remote::users()->list();
	return response()->json($users); 
}


return [  
/*  
 |-------------------------------------------------------------------------- 
 | The remote API host 
 |-------------------------------------------------------------------------- 
 | 
 | Set this value to the url of the remote API you want to connect to | 
*/  

  'host' => env('RODELS_HOST'),  
  
/*  
 |-------------------------------------------------------------------------- 
 | The HTTP client used to send HTTP requests 
 |-------------------------------------------------------------------------- 
 | 
 | This option defines the http client that rodels will be using to connect 
 | to the remote API. 
 | 
 | Supported: "curl" 
*/  

  'client' => 'curl',  
  
/*  
 |-------------------------------------------------------------------------- 
 | The authentication method 
 |-------------------------------------------------------------------------- 
 | 
 | You can set the authentication method that will be used when connecting 
 | to the API. 
 | 
 | Supported: "key" 
*/  

  'auth' => 'key',  
  
/*  
 |-------------------------------------------------------------------------- 
 | Authentication configuration 
 |-------------------------------------------------------------------------- 
 | 
 | Configure the key authentication method. 
 | 
*/  

  'key' => [  
  'name' => 'api-key',  
  'value' => env('RODELS_KEY')  
 ],
];

  
  
namespace App\Endpoints;  
  
  
use App\Rodels\User;  
use Daniesy\Rodels\Api\Components\Endpoint;  
use Daniesy\Rodels\Api\Components\RodelCollection;  
use Daniesy\Rodels\Api\Exceptions\InvalidModelException;  
  
class Users extends Endpoint  
{  
	/**  
	* @param array $params  
 	* @return RodelCollection  
	* @throws InvalidModelException  
	*/  
	public function list(array $params = []) : RodelCollection  
	{  
		$response = $this->authRequest()->get("users", $params);  
		return new RodelCollection($response, User::class);  
	}  
	
	/**  
	* @param string $name  
	* @return User  
	*/
	public function find(string $name) : User  
	{  
		$response = $this->authRequest()->get("users", compact('name'));  
		return new User($response);  
	}  
}

bash
php artisan vendor:publish

// Or...

php artisan vendor:publish --provider="Daniesy\Rodels\RodelsServiceProvider"
bash
php artisan make:endpoint Users -r

php artisan make:rodel User