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, 2020 in Laravel by kartik
• 37,520 points
16,609 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, 2020 by Niroj
• 82,840 points
hello niroj

Using Laravel to generate pages, and Angular to call REST, on Windows the call to api/branches worked, but on linux, I had to change this url like : index.php/api/branches Any way to resolve this to have the same urls ?

Hello @ Arpit

Place .htaccess file from public/ folder to the root of project, then you can access by http://localhost/mysite/user

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, 2020 in Laravel by Niroj
• 82,840 points
8,091 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, 2020 in Laravel by Niroj
• 82,840 points
1,173 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, 2020 in Laravel by Niroj
• 82,840 points
6,570 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, 2020 in Laravel by Niroj
• 82,840 points
1,238 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

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

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,068 views
0 votes
1 answer

What is redirection in Laravel?

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

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
3,016 views
0 votes
1 answer

How to install Laravel via composer?

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

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
2,944 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, 2020 in Laravel by Niroj
• 82,840 points
2,357 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, 2020 in Laravel by Niroj
• 82,840 points
2,460 views
+1 vote
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, 2020 in Laravel by Niroj
• 82,840 points
44,869 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP