PHP code example of resultsystems / relationships

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

    

resultsystems / relationships example snippets


"resultsystems/relationships": "~0.4.0"

composer update

composer 



namespace App;

use ResultSystems\Relationships\Model;

class Frequency extends Model
{
    public function subject()
    {
        // You can add several model in array

        return $this->hasOneThroughSeveral([
            Subject::class,
            Skill::class,
            Schedule::class,
        ], null, null); // null -> optional (foreignKey -> schedule_id, localKey -> id)
    }

    // or
    public function subject()
    {
        // You can add several model in array

        return $this->hasOneThroughSeveral([
            Subject::class => [
                'subjects.id' => 'skills.subject_id',
            ],
            Skill::class => [
                'skills.id' => 'schedules.skill_id',
            ],
            Schedule::class => [
                'schedules.id' => 'frequencies.schedule_id',
            ],
        ], null, null); // null -> optional foreignKey -> schedule_id, localKey -> id)
    }
}



namespace App;

use ResultSystems\Relationships\Model;

class Group extends Model
{
    public function teachers()
    {
        return $this->hasManyThroughSeveral([
           Teacher::class,
           Skill::class,
           Schedule::class => [
                'schedules.group_id' => 'groups.id',
            ],
        ]);
    }
}



namespace App;

use ResultSystems\Relationships\Model;

class Group extends Model
{
    public function subjects()
    {
        return $this->hasManyThroughSeveral([
            Subject::class,
            Skill::class,
            Schedule::class => [
                'schedules.group_id' => 'groups.id',
            ],
        ]);
    }
}



namespace App;

use Illuminate\Database\Eloquent\Model;
use ResultSystems\Relationships\Traits\RelationshipsTrait;

class Frequency extends Model
{
    use RelationshipsTrait;

    public function subject()
    {
        // You can add several model in array

        return $this->hasOneThroughSeveral([
            Subject::class,
            Skill::class,
            Schedule::class,
        ], null, null); // null -> option (foreignKey -> schedule_id, localKey -> id)
    }
}