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
To change the default host and port for the Laravel development server (php artisan serve), you have a couple of options:
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:
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.
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:
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.
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.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
you can put any port just change all places
Sometimes, the browser might cache the URL. Clear the cache or try accessing the route in an incognito window.