Framework: [5.6] Public Controller Subdirectory Issue

Created on 19 Feb 2018  路  3Comments  路  Source: laravel/framework

  • Laravel Version: 5.6.0
  • PHP Version: 7.1.14
  • Database Driver & Version: mysql Ver 14.14 Distrib 5.7.21

Description:

When creating a new controller within a subdirectory, it appears that usage of the name Public causes an issue. If the namespace and directory are anything else, it works fine.

Steps To Reproduce:

Create Laravel Project
composer create-project --prefer-dist laravel/laravel laravel

Create a basic controller in a subdirectory

php artisan make:controller Public/ExampleController --resource

Add this to the index() method in the new controller

dd('This will not work');

Create the route in routes/web.php

Route::resource('example', 'Public\ExampleController');

Test it

php artisan route:list

Now, change thePublic directory name toExample and update its namespace in the controller and the route. Test it again and it will work.

Why would the usage of the word _Public_ make a difference?

Most helpful comment

All 3 comments

public is a reserved word in PHP

Thanks for the heads up @devcircus.

Was this page helpful?
0 / 5 - 0 ratings