skip to Main Content

I’m using Laravel 11 and the latest bootstrap version to create a button and also Google Project Idx as my code editor. I got 127.0.0.1 error message when I click the button which is linking to a route as follows:

<a class="btn btn-primary btn-sm" href="{{ route('iku.create') }}" role="button">Tambah IKU</a>

when I hover the button it shows the url "127.0.0.1:9002/iku/create". It shows correct route/folder & file but the server port is 9002 instead of the default port which is 8000. I don’t know if this is the problem.

this is my Controller code:

<?php

namespace AppHttpControllers;

use AppModelsIku;
use IlluminateHttpRedirectResponse;
use IlluminateHttpRequest;
use IlluminateViewView;

class ikucontroller extends Controller
{

    public function create() : View {
            return view('iku.create');
        }
}

and this is inside the Routing web.php

<?php

use IlluminateSupportFacadesRoute;


//route resource for iku-iku
Route::resource('/iku', AppHttpControllersikucontroller::class);

I also run php artisan serve.

I’ve been searching for the solution on the internet but unfortunately, I didn’t find anything yet.

2

Answers


  1. To change the default host and port for the Laravel development server (php artisan serve), you have a couple of options:

    1. Create a Custom Script in Composer
      You can create a custom script in your composer.json file to set the desired host and port:

    Open the composer.json file in the root of your Laravel project.
    Add a new script under the "scripts" section:

    "scripts": {
        "serve": "php artisan serve --host=127.0.0.1 --port=9002"
    }
    

    Run the following command to start the server with the new settings:
    bash
    Copy code
    composer run serve
    This command will start the Laravel server on 192.168.1.10 and port 8080.

    1. Use the .env File
      If you want these settings to be applied automatically every time you run php artisan serve, you can use the .env file:

    Open the .env file in the root of your Laravel project.
    Add or modify the following lines:

    APP_URL=http://127.0.0.1:9002
    

    This will change the default URL of your application, but note that it won’t affect the artisan serve command directly. You still need to use the custom script method to change the host and port.

    Combining Both Methods
    If you want to combine both methods, you could configure your custom scripts to read environment variables from the .env file. However, for most use cases, the first method (custom script) should be sufficient.

    Login or Signup to reply.
    1. Check the Port Number:

    If Laravel is running on port 9002, make sure you’re aware of it by checking the terminal where you ran php artisan serve. If it’s running on a different port, that’s what Laravel is using to serve the application.

    1. If you want to run Laravel on port 8000 or whatever, you can stop the current server and start a new one with(on terminal):

      php artisan serve –port=8000

    Ensure that your .env file is correctly configured, especially the APP_URL. If your application runs on a specific port (e.g. 8000), update APP_URL to reflect this

    APP_URL=http://127.0.0.1:8000
    

    you can put any port just change all places

    1. Try clear browser Cache:

    Sometimes, the browser might cache the URL. Clear the cache or try accessing the route in an incognito window.

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