Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New to Laravel PHP framework. Routes other than "/" doesn't work

I'm a beginner at Lavarel framework. I know about MVC structure, Since I've used it before inside ASP.net, But using Laravel is quite confusing to me.

I've installed Laravel inside photozoom directory using:

composer create-project laravel/laravel photozoom --prefer-dist

Here's my app/routes.php :

<?php

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

Route::get('users', function()
{
    return 'users route is working!';
});

When i run http://localhost/photozoom/public/users, I get 404 Not Found error.

But when i try http://localhost/photozoom/public/, The route for / is invoked and the corresponding view is called.

I even tried to create a view for the users route. Using Laravel documentation. I've created two files :

layout.blade.php :

<html>
    <head>
        <title>Laravel Quickstart</title>
    </head>
    <body>
        <h1>Laravel Quickstart</h1>

        @yield('content')
    </body>
</html>

users.blade.php :

@extends('layout')

@section('content')
    Users!!!
@stop

But still, When i call http://localhost/photozoom/public/users I get 404 Not Found error.

Here's my public/.htaccess file:

<IfModule mod_rewrite.c>
    Options -MultiViews
    RewriteEngine On

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

I'm using PHP 5.5, Apache 2.4.6 .

Any help would be appreciated.


SOLVED After enabling mod_rewrite, I had to enable AllowOverride too.

like image 215
Rafael Adel Avatar asked Aug 28 '13 15:08

Rafael Adel


People also ask

How many types of routes are there in Laravel?

Route Parameters Laravel provides two ways of capturing the passed parameter: Required parameter. Optional Parameter.

Which types of route model binding are supported in Laravel?

Laravel currently supports two types of route model bindings. We have: Implicit model binding. explicit model binding.

Which of the following is used to define a global constraint in Laravel?

Global Constraints You always want a route parameter to be constrained by a regular expression; then you can use the pattern method. You can define these patterns in the boot method of your RouteServiceProvider.

Where is the routing file located in Laravel?

All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by your application's App\Providers\RouteServiceProvider . The routes/web.php file defines routes that are for your web interface.


2 Answers

Try http://localhost/photozoom/public/index.php/users for now. And then enable pretty URLs.

like image 98
Franz Avatar answered Oct 21 '22 10:10

Franz


The .htaccess file in the /public directory enables pretty URLs. In order for the .htaccess file to do its work:

  • Apache2 must have mod_rewrite enabled (a2enmod rewrite)
  • In your Apache configuration you must use the AllowOverride option to allow the .htaccess file to 'override' your default Apache2 configuration.

For example:

<Directory /var/www/photozoom/> 
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
like image 20
Z00tj3 Avatar answered Oct 21 '22 10:10

Z00tj3