1. Go to this page and download the library: Download ghanuz/relations 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/ */
ghanuz / relations example snippets
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use GhanuZ\FindInSet\FindInSetRelationTrait;
class User extends Authenticatable
{
use Notifiable, FindInSetRelationTrait;
public function city ()
{
return $this->FindInSetOne( 'App\City', 'city_ids', 'id', 1);
}
public function state ()
{
return $this->FindInSetOne( 'App\State', 'city_ids', 'id', 2);
}
public function country ()
{
return $this->FindInSetOne( 'App\Country', 'city_ids', 'id', 3);
}
public function hobbies ()
{
return $this->FindInSetMany( 'App\Hobbies', 'hobbies_id', 'id');
}
}
public function order_product (){
return $this->FindInSetMany( CLASS_NAME, FOREIGN_KEY, LOCAL_KEY);
}
public function order_product (){
return $this->FindInSetOne( CLASS_NAME, FOREIGN_KEY, LOCAL_KEY);
}
public function order_product (){
return $this->FindInSetMany( CLASS_NAME, FOREIGN_KEY, LOCAL_KEY, Number);
}
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'FIELD' => CUSTOM_CLASS::class,
];
/**
*
* To retrive array of relational tables
*
*/
public function order_products ()
{
return $this->FindInSetMany( CLASS_NAME, FOREIGN_KEY, LOCAL_KEY, Number);
}
/**
*
* To retrive single data of the relational table
*
*/
public function order_product ()
{
return $this->FindInSetOne( CLASS_NAME, FOREIGN_KEY, LOCAL_KEY, Number);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.