Skip to content

An Eloquent model and query builder with support for Restful Api Server using the original Laravel API.

Notifications You must be signed in to change notification settings

netbuild/apidriver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 

Repository files navigation

API Driver for Laravel 8.0

An Eloquent model and query builder with support for Restful Api Server using the original Laravel API. This library extends the original Laravel classes, so it uses exactly the same methods. Supports relationships to other models with methods like hasMany, belongsTo, etc.

Works great with other Laravel instances.

Installation


Installation using composer:

composer require netbuild/apidriver

And add the service provider in config/app.php:

Netbuild\Apidriver\ApiDbServiceProvider::class

Configuration


Change your default database connection name in config/database.php:

'default' => 'api'

And add a new api server connection:

'api' => [
        'driver' => 'api',
]

Usage


Create new Model extend Api Eloquent Model:

use Netbuild\Apidriver\Eloquent\Model;

class User extends Model
{
	protected $url 			= 'https://api.your_restful.url';
	protected $api_token		= 'YOUR_API_TOKEN';
	protected $table 		= 'REMOTE_MODEL';
}

Using the original Eloquent API:

$users = User::where('id', '<', 100)->take(3)->get();

or

$users = User::where('column_1', '=', 'your_term_1')->orWhere('column_1', '=', 'your_term_2')->take(3)->get();

or

$user = User::find(3);

or

$user->delete();

Relationships


Model User

<?php

namespace App\Models\API;

use Netbuild\Apidriver\Eloquent\Model;

class User extends Model
{
    protected $connection   		= 'api';
    protected $url 			= 'https://api.your_restful.url';
    protected $api_token		= 'YOUR_API_TOKEN';
    protected $table 			= 'REMOTE_MODEL';
    public    $timestamps   		= true;

}

Model Database

<?php

namespace App\Models\API;

use Netbuild\Apidriver\Eloquent\Model;

class Database extends Model
{
    protected $connection   		= 'api';
    protected $url 			= 'https://api.your_restful.url';
    protected $api_token		= 'YOUR_API_TOKEN';
    protected $table 			= 'REMOTE_MODEL';
    public    $timestamps   		= true;

    public function user()
    {
        return $this->belongsTo(User::class);
    }

}

About

An Eloquent model and query builder with support for Restful Api Server using the original Laravel API.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages