Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
Laravel 5 SQL Relations

I have some problem with a query in Laravel. I want to create a filter query by column in server table but I don't know how to do this.

Need help to modify the following line:

$data = $video->files()->with('server')->get();

Model: server

public function files()
{
    return $this->hasMany('App\Models\File', 'id', 'server_id');
}

Model: file

public function server()
{
    return $this->belongsTo('App\Models\Server', 'server_id', 'id')->ordered();
}

My current query return this: (but it returned all, I need return only FILE flitered by type = 6 which is server table) I don;t know how to do this. On screen below data about type server is on #relations array enter image description here

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Use WhereHas. Takes the relation name and a closure as a parameter, where you can define sub query like functionality with the relation.

$data = $video->files()->with('server')->whereHas('server', function ($query) 
{
    $query->where('type', '6');
})->get();
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda