cmandersen/has-one-specific

Add a Laravel relationship where you can specify a set ID, instead of a dynamic relationship

dev-main 2023-06-05 07:40 UTC

This package is auto-updated.

Last update: 2024-05-05 09:37:27 UTC


README

Add a Laravel relationship where you can specify a set ID, instead of a dynamic relationship

Installation

composer require cmandersen/has-one-specific

Usage

This package is basically just a trait that uses a relationship class, so it's just a case of using the trait where you need it.

class User extends Model {
    use \CMAndersen\HasOneSpecific\HasOneSpecific;
    
    public function company(){
        return $this->hasOneSpecific(Company::class, 97);
    }
}