Base
This commit is contained in:
38
app/Definition/hasEstado.php
Normal file
38
app/Definition/hasEstado.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user