Download the PHP package calhoun/eloquent-otf without Composer
On this page you can find all versions of the php package calhoun/eloquent-otf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package eloquent-otf
Eloquent On The Fly
Eloquent On The Fly is a package that has been designed to help you to use Laravel's Eloquent to query array.
- Installation
- Usage
- As a Helper
- As a Collection Method
- As a Class
- Simple
- Advance
Installation
To install through composer, simply put the following in your composer.json
file:
And then run composer install
from the terminal.
Quick Installation
Above installation can also be simplify by using the following command:
composer require "calhoun/eloquent-otf"
Next, if you are using a version of Laravel less than 5.5 you should add the OTFServiceProvider to the providers array of your config/app.php configuration file:
Calhoun\OTF\OTFServiceProvider::class,
Usage
Use as a Helper
To use Eloquent On The Fly as a Helper, all you need is an associative array, and closure containing your eloquent or builder query.
Use as a Collection Method
To use Eloquent On The Fly as a Collection Method, all you need is a closure containing your eloquent or builder query.
Use as a Class
Simple
To use Eloquent On The Fly as a Class. Instantiate the OTF Class and use the create method, which takes a name and data as its parameters.
Advance
You can use Eloquent On The Fly as a Class with relationships.
<?php
use Calhoun\OTF\Support\OTF;
$users = [
[
'id' => 1
'first' => 'Maurice',
'last' => 'Calhoun',
],
...
];
$profiles = [
[
'id' => 1
'email' => '[email protected]',
'age' => '40',
'user_id' => 1
],
...
];
$oft = app()->make(OTF::class);
$user = $otf->create('user', $users);
$profile = $otf->create('profile',$profiles);
$relationships = [
'user' => [
'profile' => function($self) use($profile){
return $self->hasOne($profile, 'user_id');
}
],
'profile' => [
'user' => function($self) use($user){
return $self->belongsTo($user, 'id');
}
]
];
$otf->setRelationships($relationships);
$maurice = $user->find(1)->profile;