Request in the url with Laravel

Asked

Viewed 614 times

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 this http://localhost:8000/css/app_2.min.css. So it will work out what I want.

2 answers

1

but if I do localhost:8000/hotels/hotel name it is not working

Can you fix error information that appears? However, make sure you have . htaccess configured.

At the root of the project:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_URI} !^public
  RewriteRule ^(.*)$ /public/$1 [L]
</IfModule>

In the /public folder

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

1


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 the current route in the CSS path.

  • 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.

  • 1

    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.

  • helped yes, thank you

  • How does it get all the way ? The link I put in place of that ?

  • 1

    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.

  • Gave everything right

  • Ok. I just edited the answer. Mark it as correct to close this topic. Thank you.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.