For what you want to do, my solution would be for you to have your models well created using the php artisan make:model NombreModelo
command, once created as shown below:
Model Vacaciones
:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Vacaciones extends Model
{
//Atributos
//Relaciones
public function solicitante(){
return $this->belongsTo('App\Models\Empleado', 'solicita_id');
}
public function autoriza(){
return $this->belongsTo('App\Models\Empleado', 'autoriza_id');
}
}
Employed Model:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Empleado extends Model
{
//Atributos
//Relaciones
public function vacacionesSolicitante(){
return $this->hasMany('App\Models\Empleado', 'solicita_id');
}
public function vacacionesAutoriza(){
return $this->hasMany('App\Models\Empleado', 'autoriza_id');
}
}
If your driver wants to obtain who authorizes and who requests vacations from a record of the vacation table, it would be enough:
//Importar Modelo hasta arriba
use App\Models\Vacaciones;
//Método dentro de tu controlador
public function obtenerDatos(){
$id = 1;
$vacaciones = Vacaciones::where('id', $id)->with('solicitante', 'autoriza')->first();
//Aquí ya tienes los datos que necesitas
$nombre_solicitante = $vacaciones->solicitante->nombre;
$nombre_autoriza = $vacaciones->autoriza->nombre;
}
And now, there you have your data, do not try to avoid using Laravel's Eloquent ORM, it really helps you too, you should only use "raw" expressions when it is really necessary and there is no other. / p>