main

filamentphp/demo

Last updated at: 29/12/2023 09:42

Address.php

TLDR

This file defines the Address model class, which represents an address in the application. The model has relationships with the Customer and Brand models, allowing addresses to be associated with customers and brands.

Methods

There are no additional methods defined in this file.

Classes

Address

The Address class extends the Model class and represents an address in the application. It uses the HasFactory trait for easy model creation.

The Address class has the following properties:

  • $table: Specifies the name of the database table associated with the model (addresses).

The Address class also has the following relationships:

  • customers(): Defines a morphedByMany relationship with the Customer model. This allows an address to be associated with multiple customers.
  • brands(): Defines a morphedByMany relationship with the Brand model. This allows an address to be associated with multiple brands.
<?php

namespace App\Models;

use App\Models\Shop\Brand;
use App\Models\Shop\Customer;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Address extends Model
{
    use HasFactory;

    protected $table = 'addresses';

    public function customers()
    {
        return $this->morphedByMany(Customer::class, 'addressable');
    }

    public function brands()
    {
        return $this->morphedByMany(Brand::class, 'addressable');
    }
}