Good afternoon for everyone,
I have a view where it shows me the values of my table orders, this table is referenced with another patient call, and the latter with a table called cities. the problem that I have is that the cities field does not show it to me with the city but with the id of the city.
for example for the fields: name, company, position, city ...
shows me ...
juan | Google | IT | 1
and I would like you to show me ...
juan | Google | TI | Bogota
Thanks in advance.
Order Control
<?php
namespace App\Http\Controllers;
use App\Http\Requests\CreateOrdenRequest;
use App\Http\Requests\UpdateOrdenRequest;
use App\Repositories\OrdenRepository;
use App\Http\Controllers\AppBaseController;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;
use App\Models\Ciudad;
use App\Models\Orden;
use App\Models\Paciente;
class OrdenController extends Controller
{
/** @var OrdenRepository */
private $ordenRepository;
public function __construct(OrdenRepository $ordenRepo)
{
$this->ordenRepository = $ordenRepo;
$this->middleware('auth');
}
public function index(Request $request)
{
$this->ordenRepository->pushCriteria(new RequestCriteria($request));
$ordenes = $this->ordenRepository->all();
return view('ordenes.index')->with('ordenes', $ordenes)->with('paciente_Orden');
/*return view('ordenes.index')->with('ordenes', $ordenes);**/
}
public function create(){
$ciudad = ['' => ''] + Ciudad::pluck('nombre','id')->toArray();
return view('ordenes.create', compact('ciudad','orden'));
if (empty($orden)) {
Flash::error('Orden no encontrada');
return redirect(route('ordenes.index'));
}
}
}
OrdenModel
<?php
namespace App\Models;
use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Orden extends Model
{
public $table = 'ordenes';
public function paciente_Orden(){
return $this->hasOne('App\Models\Paciente','id','id_paciente');
}
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
public $fillable = [
'id',
'id_paciente',
'empresa',
'cargo'
];
protected $casts = [
'id' => 'integer',
'id_paciente' => 'integer',
'empresa' => 'string',
'cargo'=> 'string'
];
public static $rules = [
];
}
table.blade
<table class="table" id="orden-tabla">
<thead>
<tr>
<th>Nombre</th>
<th>Empresa</th>
<th>Cargo</th>
<th>Ciudad</th>
</tr>
</thead>
<tbody>
@foreach($ordenes as $orden)
<tr>
<td>{!! $orden->paciente_Orden->nombre !!}</td>
<td>{!! $orden->empresa !!}</td>
<td>{!! $orden->cargo !!}</td>
<td>{!! $orden->paciente_Orden->id_ciudad !!}</td>
<td>
{!! Form::open(['route' => ['ordenes.destroy', $orden->id], 'method' => 'delete','style'=>'margin-left: 14%;']) !!}
<div class='btn-group'>
</div>
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>