2
I have a simple test routine, which is not working in the final part. The idea is to query a Mysql database and compose a page with the result, which works correctly.
Clicking on a link from a line on this composite page, data referring to the line should be displayed.
For this, it will be necessary that the link pass its value to a new search routine, in order to consult again the database to collect more information, since the list obtained initially brings only summary data.
This part is not working. Results in error:
Sorry, the page you are Looking for could not be found. Notfoundhttpexception in Routecollection.php line 161:
The Routes code for the page call is like this:
<?php
Route::get('/', function () {
return view('welcome');
});
Route::get('usuarioLer','controllerUsuarios@pesquisar');//pesquisa todo o BD
Route::get('usuarioDetalhar/{nome}','controllerUsuarios@detalhar');//pesquisa um item no BD
Route::group(['middleware' => ['web']], function () {
});
?>
The 'route' userLer is the one that works 100%. This route, as noted, calls the controllerUsuarios.php page and triggers the search method.
A fragment of this php page is:
public function pesquisar (){
$listaUsuarios = DB::select
("SELECT * from usuarios INNER JOIN categorias ON
usuarios.TabFKUsuariosCategoria = categorias.TabCategoriasID");
return view('viewUsuariosLista')->with('listaU',$listaUsuarios);
}//metodo pesquisar
The above code calls a 'view' page, through Return, which displays the result of all database records.
The page viewUsuariosLista.php has the following code:
<?php
echo <<<BLOCO1
<html>
<head>
<!-- <link href="../public/css/app.css" rel="stylesheet"> -->
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
<script src="assets/js/bootstrap.min.js"></script>
</head>
<body>
<table class="table">
BLOCO1;
foreach ($listaU as $u){
echo "<tr>";
echo "<td>".$u->TabUsuariosID."</td>";
echo "<td>".$u->TabUsuariosNome."</td>";
echo "<td>".$u->TabCategoriasDescricao."</td>";
echo "<td><a href='usuarioDetalhar?nome=".$u->TabUsuariosNome."'>
<span class='glyphicon glyphicon-search'></span></a></td>";
echo "</tr>";
}//foreach
echo <<<BLOCO2
</table>
<br />
</body>
<html>
BLOCO2;
?>
Repeat, so far everything works 100%.
Now comes the error. By clicking on the link generated by the line
echo "<td><a href='usuarioDetalhar?nome=".$u->TabUsuariosNome."'>
<span class='glyphicon glyphicon-search'></span></a></td>"
it causes the user route call to Define, passing to the variable 'name' the name of the user clicked. A 'route', as demonstrated high up and which I repeat here
Route::get('usuarioDetalhar/{nome}','controllerUsuarios@detalhar');//pesquisa um item no BD
does not work, causing the mentioned error.
The view page named viewUsuariosDetalhes.php exists, and its simple code is
<html>
<head>
</head>
<body>
<h1>Detalhes do Usuário <br />
<h3><?php echo($u->TabUsuariosNome);?></h3>
</h1>
</h1>
<ul>
<li>
<b>Categoria:</b><?php echo($u->TabCategoriasDescricao); ?>
</li>
</ul>
</body>
</html>
What is the advantage of passing an array in the route setting? + 1 by
{{ route(....) }}
– rray
Well, I pass array because there are 2 parameters, one to define the name and the other to define the controller@method. I don’t know if you can name the route and inform the controller without using an array.
– Raylan Soares
Route::get('usuarioDetalhar/{nome}','controllerUsuarios@detalhar');
usually I see so, I asked why was curiosity even :)– rray
I get it, it’s because we assume that we need to change the "/user" path to "/userView". We would have to change tbm in all views. Already with her named I would not need, because I would continue calling her by name, regardless of the cainho has changed. I think q agr could explain
– Raylan Soares
Now yes :D, works as alias.
– rray
iiiiiiisso!! rs
– Raylan Soares