skip to Main Content

I installed Laravel latest version i.e v7 but when I try to change the route or create my own route that route is not working.

Here is the default route.

Route::get('/', function () {
    return view('welcome');
});

This is what I’m trying to hit URL in the browser:
http://localhost/mobileshop/public/

This is working fine but when I try to change it or write my own route it shows error 404 | not found

This is what I’m trying when I get this error

Route::get('/login', function () {
    return view('welcome');
});

Or

Route::get('/login', function () {
    dd("my own route");
    });

Both are not working what to do?

This is what I’m trying to hit URL in the browser:
http://localhost/mobileshop/public/login

I researched and found something here: https://laracasts.com/discuss/channels/laravel/order-of-routes-in-webphp?page=1

but whatever they tell I don’t think I’m doing that mistake, am I?

I’m using XAMPP.

I myself changed route, views, and many other things but still, I’m there at error 404.

When I stop XAMPP and run php artisan serve and use: http://127.0.0.1:8000/login URL in browser its working fine. So is there any issue in my XAMPP? If there is an issue in my XAMPP then why default route is working I’m not understanding.

Can anyone help me to issue and about how to use XAMPP rather than php artisan serve?

Thanks in advance.

2

Answers


  1. Route::get('/login', function () {
        return view('welcome');
    });
    
    1. This ‘/login’ is URL
    2. This is blade.php ‘welcome’
    3. Use php artisan serve in cmd

    After Then you try 127.0.0.1:8000/login in browser

    Login or Signup to reply.
  2. This is very likely because how you run your laravel, An easy way is that you may need to run this command at your root of your laravel and in the terminal you will get a url just use that and you should be fine.

    php artisan serve
    

    Working with xampp:

    1. Go to C:WindowsSystem32driversetchosts and add a new line like: 127.0.0.1 yoursite.local
    2. Go to where xampp is installed under xamppapacheconfextrahttpd-vhosts.conf Then add a virtual host in the bottom of the file like:
    <VirtualHost *:80>
    
    DocumentRoot "PATH_to_laravel_folder/public"  
    
    ServerName yoursite.local  
    </VirtualHost>
    

    Then you can access your route by typing: yoursite.local/login or yoursite.local:80/login

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search