PHP code example of megapixel23 / belongs-to-one

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

    

megapixel23 / belongs-to-one example snippets




namespace App\Models;

use App\Models\Group;
Use Illuminate\Database\Eloquent\Model;
use Megapixel23\Database\Eloquent\Relations\BelongsToOneTrait;

class Record extends Model
{
    use BelongsToOneTrait;
    
    public function group()
    {
        return $this->belongsToOne(Group::class);
    }
}

$record = Record::with('group')->first();