0
I’m trying to get started on Laravel
, and I’m having trouble with requests
, when I make just one request
as an example localhost:8000/hoteis
everything works it searches the page and works perfectly, but if I do localhost:8000/hoteis/nomedohotel
it is not working, the routes file is as follows:
Route::get('/hoteis', 'HotelCrontroller@listarHoteis');
Route::get('/hoteis/{nome}', 'HotelCrontroller@mostraHotel');
My controller is programmed like this:
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use Request;
class HotelCrontroller extends Controller
{
public function listarHoteis()
{
//DB::select('Aqui vem a query');
$hoteis = 'Aqui vem os hoteis.';
return view('hotel')->with('hoteis', $hoteis);
}
public function mostraHotel(){
$nomeHotel = Request::route('name');
return view('detalhehotel')->with('hotel', $nomeHotel);
}
}
and on my page it is as follows:
@extends('index')
@section('conteudo')
<?php
$hoteis = $hotel;
echo $hoteis;
?>
@stop
What will be the problem ? To take the test I tried to go straight to the page and it worked perfectly.
I found that there might be something with css or something like that, because all the pages I write
/algo
it displays the stylized 404 error page but when I put/algo/algo
it appears the same page but without being stylized.I visualized that the files he’s picking up come like this
http://localhost:8000/aa/css/app_2.min.css
for this reason all the style is coming wrong, how to make it load just like thishttp://localhost:8000/css/app_2.min.css
. So it will work out what I want.
This does not solve my problem, the problem is on the route, because when I put sub n error route. Example /hotels and /hotels/hotel name in the second of the problem and not bald the site, I saw that the path of CSS, JAVASCRIPT, THIS WITH PROBLEMS.
– Renan Rodrigues
In this case, you must be inserting the Assets the wrong way. When referring to the path of an Asset, you should use the stab
asset
in your template like this:{{ asset('css/app_2.min.css') }}
. You’re probably using the current url, so you’re adding this to your route. If it helps, let me know that I change the answer.– juniorgarcia
helped yes, thank you
– Renan Rodrigues
How does it get all the way ? The link I put in place of that ?
– Renan Rodrigues
The function
asset
will write the path based on your application settings. If you have the default Laravel setting, just write the function as I commented earlier. The final path remains as you mentioned in the question:http://localhost:8000/css/app_2.min.css
. You should use this function in your Blade template q contains the style part.– juniorgarcia
Gave everything right
– Renan Rodrigues
Ok. I just edited the answer. Mark it as correct to close this topic. Thank you.
– juniorgarcia