<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Lab extends Model
{
    use HasFactory;

    protected $table = 'labs';

    public function address($short = false){
        $address = json_decode($this->addresss);
        $labAddress = [];
        $labAddressShort = [];

        if($address->street) {
            $labAddress[] = $address->street;
        }
        
        if($address->city) {
            $labAddress[] = '<br>' . $address->city;
            $labAddressShort[] = $address->city;
        }
        if($address->stateAbbr) {
            $labAddress[] = ' ' . $address->stateAbbr;
            $labAddressShort[] = $address->stateAbbr;
        }
        if($address->postalCode) {
            $labAddress[] = ' ' . $address->postalCode;
            $labAddressShort[] = $address->postalCode;
        }
        $labAddress = implode('', $labAddress);
        $labAddressShort = implode(' ', $labAddressShort);
        if($short) return $labAddressShort;
        return $labAddress;
    }

}
