2
I have a model called Processo
, this model has a relationship hasMany with the model Andamento
, the model Andamento
has a queryScope what use to return the data already with other relations of this model, what I want to do is: through the relationship of Processo
with the Andamento
, it is also possible to return the relations of the queryScope of Andamento
, this is possible?
Code:
model Process.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Processo extends Model {
function andamentos () {
return $this->hasMany('App\Processos\Andamento');
}
function scopeInfo($query) {
return $query->with('andamentos');
}
}
model Andamento.php
namespace App\Processos;
use Illuminate\Database\Eloquent\Model;
class Andamento extends Model
{
protected $table = 'processos_andamentos';
protected $guarded = [];
function scopeInfo ($query) {
return $query->with('fase', 'tipo_andamento');
}
function processo () {
return $this->belongsTo('App\Processo');
}
function fase () {
return $this->hasOne('App\Processos\Fase', 'id', 'fase_processo_id');
}
function tipo_andamento () {
return $this->hasOne('App\Processos\TipoAndamento', 'id', 'tipo_andamento_id');
}
}
The call would be something like:
$Processo = Processo:Info()->whereId(1);
$andamentos_fases = $Processo->andamentos->fase
tries so, if it works I create the answer Return $this->hasMany('App Processes Progress')->with('scopeInfo');
– Lodi
if you do not try Return $this->hasMany('App Processes Progress')->with('phase', 'tempo type');
– Lodi
With the "scopeInfo" it returns: "Too few Arguments to Function App Processes Progress::scopeInfo()", worked with the second comment, but is it possible to get the scopeInfo even? so you don’t have to rename each new method
– Thiago