0
What can I call a Subtipo
searching for the tipo_id
, I did some tests here but none successfully this is my first project.
Table of the Type
public $timestamps = true;
protected $table = 'tipo';
protected $fillable = ['id','titulo'];
protected $hidden = [];
public function subtipo()
{
return $this->hasMany(Subtipo::class, 'tipo_id');
}
Subtype
public $timestamps = true;
protected $table = 'subtipo';
protected $fillable = ['id','tipo_id','titulo'];
protected $hidden = [];
public function ticket()
{
return $this->hasMany(Ticket::class, 'subtipo_id');
}
public function tipo()
{
return $this->belongsTo(Tipo::class, 'tipo_id');
}
I will create a Ticket system, and put the open status read and closed in Tickets and needed to call these 'subtypes' by ticket type (id=1
)
I was testing things like this on SubTipoRepository
public function __construct()
{
$this->model = new SubTipo();
}
public function findByTipoTicket($tipo_id)
{
return $this->model->where('tipo_id',1)->all();
}
return $this->model->where('tipo_id',1)->all();
here gave some error? shouldreturn $this->model->where('tipo_id',1)->get();
!– novic
In your class models if the
id
for primary key and auto increment don’t need to put in the$fillable
– novic
Does this Answer your Question? Relationship problems one for many
– novic