3-3-: agregar una ruta de recursos-Mostrar registros individualmente
Mostrar registros individualmente
Ahora crearemos la acción para mostrar el registro, así que modificamos el método show() con el siguiente código:
public function show($id) {
$user = User::find($id);
return View::make('users.show')->with('user', $user);
}Muy fácil. Un método que recibe el id del registro y lo recupera pasándolo a la vista show.blade.php.
Ahora vamos a editar la vista show.blade.php con el siguiente código:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title> Datos de usuario </title>
</head>
<body>
<h1> {{ $user->real_name }} </h1>
<ul>
<li> Nombre de usuario: {{ $user->real_name }} </li>
<li> Email: {{ $user->email }} </li>
<li> Nivel: {{ $user->level }} </li>
<li> Activo: {{ ($user->active) ? 'Sí' : 'No' }} </li>
</ul>
<p> {{ link_to('users', 'Volver atrás') }} </p>
</body>
</html>Y en index.blade.php agregamos el enlace para ver los registros en forma individual modificando:
<td style="text-align: center;"> Ver </td>
Por:
<td style="text-align: center;"> {{ link_to('users/'.$item->id, 'Ver') }} </td>
Comentarios
Publicar un comentario