Error:My Routes are Returning a 404 in Laravel?

0 votes

How to fix this error?

I've created a new controller called kartik:

class User_Controller extends Base_Controller {

    public $restful = true;

    public function get_index() 
    {
        return View::make('kartik.index');
    }
}

I've created a view file in application/views/user/ called index.php with some basic HTML code, and in routes.php I've added the following:

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

Route::get('kartik', function () {
    return View::make('kartik.index');
});

The first route works fine when visiting the root (http://localhost/mysite/public) in my web browser, but when I try to go to my second route with http://localhost/mysite/public/kartik I get a 404 Not Found error. 

How to solve? Thank you!!

Mar 30 in Laravel by kartik
• 10,990 points
145 views

1 answer to this question.

0 votes

Hii @kartik

Routes

Use them to define specific routes that aren't managed by controllers.

Controllers

Use them when you want to use traditional MVC architecture

I think Solution to your problem

You don't register controllers as routes unless you want a specific 'named' route for a controller action.

Rather than create a route for your controllers actions, just register your controller:

Route::controller('user');

Now your controller is registered, you can navigate to http://localhost/mysite/public/user and your get_index will be run.

You can also register all controllers in one go:

Route::controller(Controller::detect());

Hope this works fine

Thank You!

answered Mar 30 by Niroj
• 22,110 points

Related Questions In Laravel

0 votes
1 answer

Error: “No scheduled commands are ready to run.” in Laravel?

Hello @kartik, Run php artisan and see if your commands ...READ MORE

answered Apr 6 in Laravel by Niroj
• 22,110 points
228 views
0 votes
1 answer

What are the query builder in Laravel?

Hey, Laravel's database query builder provides a convenient, ...READ MORE

answered Mar 19 in Laravel by Niroj
• 22,110 points
35 views
0 votes
1 answer

How to mock a static facade methods in Laravel?

Hey, Facades provide a "static" interface to classes ...READ MORE

answered Mar 19 in Laravel by Niroj
• 22,110 points
108 views
0 votes
1 answer

How can we create a record in Laravel using eloquent?

We need to create a new model ...READ MORE

answered Mar 20 in Laravel by Niroj
• 22,110 points
38 views
0 votes
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 22,110 points
417 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 22,110 points
62 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 22,110 points
64 views
0 votes
1 answer

What is database migration and How to create database migration in Laravel?

Hii, Migrations are like version control for your database, ...READ MORE

answered Mar 23 in Laravel by Niroj
• 22,110 points
52 views
0 votes
1 answer

What are the important directories used in a common Laravel application

Hey @Kartik. Directories used in a common Laravel ...READ MORE

answered Mar 17 in Laravel by Niroj
• 22,110 points
33 views
0 votes
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 22,110 points
139 views