PHP code example of blasttech / eloquent-related-plus

1. Go to this page and download the library: Download blasttech/eloquent-related-plus 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/ */

    

blasttech / eloquent-related-plus example snippets


class Customer extends Eloquent
{
    public function sales_rep()
    {
        return $this->hasOne(Contact::class, 'id', 'sales_rep_id');
    }
}

use App\Contact;
use Blasttech\EloquentRelatedPlus\RelatedPlusInterface;
use Blasttech\EloquentRelatedPlus\RelatedPlusTrait;

class Customer extends Eloquent implements RelatedPlusInterface
{
    use RelatedPlusTrait;
    
    public function sales_rep()
    {
        return $this->hasOne(Contact::class, 'id', 'sales_rep_id');
    }
}

namespace App\Http\Controllers;

use App\Customer;

class CustomerController extends Controller
{
    public function getCustomers()
    {
        return Customer::select('*')
            ->modelJoin('Contacts', '=', 'left', false, false)
            ->get(); 
    }
    
    ...
}

use App\Customer;
use Blasttech\EloquentRelatedPlus\RelatedPlusInterface;
use Blasttech\EloquentRelatedPlus\RelatedPlusTrait;

class CustomerController extends Controller
{
    public function getCustomers()
    {
        return Customer::select('*')
            ->modelJoin('Contacts', '=', 'left', false, false)
            ->orderByCustom('contact_name'); 
    }
    
    ...
}

use Blasttech\EloquentRelatedPlus\RelatedPlusInterface;
use Blasttech\EloquentRelatedPlus\RelatedPlusTrait;

class MyModel extends Eloquent implements RelatedPlusInterface
{
    use RelatedPlusTrait;
    
    public function getContact($contact_name)
    {
        return Customer::select('*')
            ->modelJoin('Contacts', '=', 'left', false, false)
            ->search($contact_name); 
    }
    
    ...
}