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.
Route Parameters Laravel provides two ways of capturing the passed parameter: Required parameter. Optional Parameter.
Laravel currently supports two types of route model bindings. We have: Implicit model binding. explicit model binding.
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.
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.
Try http://localhost/photozoom/public/index.php/users
for now. And then enable pretty URLs.
The .htaccess file in the /public directory enables pretty URLs. In order for the .htaccess file to do its work:
For example:
<Directory /var/www/photozoom/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With