Computer Lover
Computer Lover

Reputation: 61

Laravel routing not working, How to fix it?

layout.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
        <meta charset="UTF-8">
        <title>Learning Laravel With Tut.</title>
</head>
<body>
        <ul>
                <li><a href="/">Home</a></li>
                <li><a href="/about">About Us</a></li>
                <li><a href="/contact">Contact Us</a></li>
        </ul>
   @yield('main')
</body>
</html>

index.blade.php

@extends('layout')
@section('main')
<h1>Welcome to my First Blog with Laravel.</h1>
<p>Welcome to my First Blog with Laravel.Welcome to my First Blog with Laravel.Welcome to my First Blog wi</p>

@stop

about.blade.php

@extends('layout')
@section('main')
<h1>About This Blog.</h1>
<p>Welcome to my First Blog with Laravel.Welcome to my First Blog with Laravel.Welcome to my First Blog wi</p>
@stop

contact.blade.php

@extends('layout')
@section('main')
<h1>Contact Us</h1>
<p>Welcome to my First Blog with Laravel.Welcome to my First Blog with Laravel.Welcome to my First Blog wi</p>

@stop

routes.php

Route::get('/', function()
{
  return View::make('index');

});
Route::get('about', function()
{
  return View::make('about');

});
Route::get('contact', function()
{
  return View::make('contact');

});

there's my codes I'm newbies with Laravel i was tried to create a a simple layout with Laravel Blade but unfortunetly when I'm clicking on my 'Contact Us', 'About us' page's it's not redirecting on following urls and saying not found anythings ! I didn't understood what's the wrong with following codes, Please help me Sorry for bad English, and thanks in advance.

Upvotes: 1

Views: 1474

Answers (2)

MartaGom
MartaGom

Reputation: 501

Try it:

Route::get('/about', function()
{
  return View::make('about');

});
Route::get('/contact', function()
{
  return View::make('contact');

});

With thew "/" character.

Or better:

{{HTML::link('about', 'About me')}}

EDIT:

You can do as follow:

ROUTE:

Route::get('usuarios', array("before" => "inicio", function() {
    return View::make('usuarios/lista'); /*The file lista.blade.php must exist in the "usuarios" directory, the "usuarios" directory must exist in the "view" directory.*/
}));

HTML:

<a href="/usuarios">Usuarios</a>

Try it. That works for me.

If that doesn't work for you: maybe your error be in the Apache configuration.

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot /var/www/my_app/public
    <Directory /var/www/my_app/public>
        # This relaxes Apache security settings.
        AllowOverride all
        # MultiViews must be turned off.
        Options -MultiViews
        # Uncomment this if you're on Apache >= 2.4:
        #Require all granted
   </Directory>
</VirtualHost>

Upvotes: 0

Christian Giupponi
Christian Giupponi

Reputation: 7618

Use the url class to create urls:

<a href="{{ URL::to('about') }}">About</a>

URL will set the correct path from your document root.

Docs here

Upvotes: 1

Related Questions