saeed ahmed
saeed ahmed

Reputation: 185

The issue with Laravel Routing

Version of Apache: Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.19

Authors.php can be found in the Controllers folder.

<?php

class AuthorsController extends BaseController {

    public $restful = true;

    public function getIndex () {
        return View::make('authors.index');
    }
}

?>

within routes.php

<?php 

//Route::get('authors', 'AuthorsController@getIndex');
Route::get('authors', array('uses' => 'authors@index'));

?>

When I try to access the browser: localhost/laravel/public/, the first page displays: You have arrived.

However, when I try to pass the parameter authors in the browser: localhost/laravel/public/authors, it fails.

its display: Something appears to have gone wrong. What is the issue with the Laravel framework?

Upvotes: 2

Views: 911

Answers (4)

George G
George G

Reputation: 7705

Update:

the problem is file name in your controllers folder: rename authors.php to AuthorsController.php.

Remember: controller file name must match controller class name itself, this is crucial for auto loading. example: SomeController must reside in SomeController.php, this applies to any class no matter it's controller or other class file, for laravel, or any other framework (anyway this is the only right way doing it).

Old:

Try this:

Route::get('public/authors', 'AuthorsController@getIndex');

Also problem maybe resides in your url rewrites, if you can show it too.

I think you have just installed laravel now. Anyway make sure: you have .htaccess file included in the document root, and move index file from public folder to root and change pathes accordingly, in that case

Route::get('authors', 'AuthorsController@getIndex');

will work.

Upvotes: 2

Khan Shahrukh
Khan Shahrukh

Reputation: 6411

in routes.php

Route::get('/authors/', 'AuthorsController@index');

in AuthorsControllers

<?php

class AuthorsController extends BaseController
{    
public function index()
{
    return View::make('authors.index');
}
//some more function goes here 
}

make sure you have a folder named authors if you still find issues open app/storage/logs/laravel.log file clear it and save it and again visit localhost/laravel/public/authors in your browser and then post the result of laravel.log here

Upvotes: 2

Eugene
Eugene

Reputation: 3375

I think

composer dump-autoload

may help.

Upvotes: 2

DavidT
DavidT

Reputation: 2481

Modify

Route::get('authors', array('uses' => 'authors@index'));

to

Route::controller('/authors', 'AuthorsController');

Using the controller method is more powerful as it will allow you to use get and post requests in your controller whilst keeping your routes.php file clean.

Upvotes: 1

Related Questions