1

I have a laravel project served by apache and located in the apache root folder and accessed at http://hostname/foo and I have troubles to map an url to a controller method. The following is the controller with the method (simplified for the purpose of illustration).

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ShowController extends Controller
{
    public function show($id)
    {
        return 'show: ' . $id;
    }
}

The following is the route mapping in routes/web.php

Route::get('show/{id}', 'ShowController@show');

The trouble is that the url like the following doesn't work.

http://hostname/foo/show/1

The above url got me to phpinfo(). But the following url gave the expected result.

http://hostname/foo/public/show/1

The following mappings don't work either.

Route::get('/show/{id}', 'ShowController@show'); // with a leading slash
Route::get('show/{id}', 'ShowController@show')->name('show');
Route::get('/show/{id}', 'ShowController@show')->name('show'); // with a leading slash

I appreciate any info or suggestion. Thanks. My php is 7.1.

3
  • 1
    It seems to me like you're serving the root folder of your Laravel project instead of the public folder? I may be wrong Commented Jul 27, 2020 at 20:24
  • Thanks. I have updated my post with the info that my project is served by apache and it's under the apache root folder. So my question is: is the mapping relative to the project root (i.e. /foo) or to the public folder (i.e. /foo/public)? Is there any difference with or without the leading slash? Commented Jul 27, 2020 at 21:35
  • 1
    It is relative to the public folder, no matter you use the leading slash or not. There's no difference on that from what I know. Commented Jul 27, 2020 at 21:42

3 Answers 3

1

This entry point of Laravel will always be /public.

You can find how configure Apache here :
How to configure apache web server to deploy laravel 5

Sign up to request clarification or add additional context in comments.

Comments

1

The project should be served from the public folder.

Comments

0

I believe you use something like xamp, wamp... I recommend not using theses but launch the server with php artisan serve. This way, you could access your website on localhost:8000 by default.

1 Comment

Actually I serve the project with apache. The project (foo) is under the apache root folder. I'll add the info in my post. thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.