PHP code example of reedware / laravel-composite-relations
1. Go to this page and download the library: Download reedware/laravel-composite-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/ */
reedware / laravel-composite-relations example snippets
use Illuminate\Database\Eloquent\Model as Eloquent;
use Reedware\LaravelCompositeRelations\HasCompositeRelations;
abstract class Model extends Eloquent
{
use HasCompositeRelations;
}
public function myRelation()
{
return $this->belongsTo(MyRelated::class, 'my_column_on_this_table', 'my_column_on_the_other_table');
}
public function myCompositeRelation()
{
return $this->compositeBelongsTo(MyRelated::class, ['my_first_key', 'my_second_key'], ['their_first_key', 'their_second_key']);
}
public function myCompositeRelation()
{
return $this->compositeHasOne(MyRelated::class, ['their_first_key', 'their_second_key'], ['my_first_key', 'my_second_key']);
}
public function myCompositeRelation()
{
return $this->compositeHasMany(MyRelated::class, ['foreign_1', 'foreign_2'], ['local_1', 'local_2']);
}
class Task extends Models
{
/**
* The primary keys for the model.
*
* @var array
*/
protected $primaryKeys = ['vendor_id', 'vendor_name'];
public function importSummary()
{
return $this->compositeHasOne(TaskImportSummary::class);
}
}
class TaskImportSummary extends Models
{
public function task()
{
return $this->compositeBelongsTo(TaskImportSummary::class);
}
}
$task->joinRelation('importSummary', function($join) {
$join->where('task_import_summaries.name', 'like', '%Relation joins are cool!%');
});
public function myCompositeBelongsToRelation()
{
return $this->compositeBelongsTo(MyRelated::class, ['local_1', 'local_2'], ['foreign_1', 'foreign_2'], null, 'and');
}
public function myCompositeHasOneRelation()
{
return $this->compositeHasOne(MyRelated::class, ['foreign_1', 'foreign_2'], ['local_1', 'local_2'], 'and');
}
public function myCompositeHasManyRelation()
{
return $this->compositeHasMany(MyRelated::class, ['foreign_1', 'foreign_2'], ['local_1', 'local_2'], 'and');
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.