Files
intranet/app/Definition/hasEstado.php

38 lines
945 B
PHP
Raw Normal View History

2020-12-01 17:23:13 -03:00
<?php
namespace App\Definition;
use Stringy\Stringy;
trait hasEstado
{
public function estados()
{
$table = $this->getTable();
$self = Stringy::create(get_class($this));
$ns = $self->substr(0, $self->indexOfLast('\\'));
$self = $self->substr($self->indexOfLast('\\') + 1);
$column = $self->underscored();
$class = $ns . '\\Estado' . $self;
if (substr($table, -1, 1) == 's') {
$column .= '_id';
}
return $this->has_many($class, $column)->findMany();
}
public function estado()
{
$table = $this->getTable();
$self = Stringy::create(get_class($this));
$ns = $self->substr(0, $self->indexOfLast('\\'));
$self = $self->substr($self->indexOfLast('\\') + 1);
$column = $self->underscored();
$class = $ns . '\\Estado' . $self;
if (substr($table, -1, 1) == 's') {
$column .= '_id';
}
$id = $this->has_many($class, $column)->max('id');
return $this->has_many($class, $column)->findOne($id);
}
}
?>