0
votes

I have installed laravel 5 and localhost/laravel/public showing landing page of laravel. once i created a controller hello using php artisan command and created htaccess file like below the hello controller showing page not found. Please help me to resolve this error

 RewriteEngine On
 RewriteRule ^(.*)$ public/$1 [L]

routes.php file

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


 Route::get('/hello', 'Hello@index');

hello.php controller file

 <?php

  namespace App\Http\Controllers;

 use Illuminate\Http\Request;

   use App\Http\Requests;

 class Hello extends Controller
{
public function index()
    {
    echo "test";
  }
}
2

2 Answers

1
votes

It is funny but true thing is controller does not depend on public folder. If you copy files of public folder into another directory and includes other files from index.php perfectly,surely it will work.

require __DIR__.'/../bootstrap/autoload.php';

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/

$app = require_once __DIR__.'/../bootstrap/app.php';

Change those two line directory so that index.php can include both file perfectly.

0
votes

solved myself

Easy way to remove public from laravel 5 url. You just need to cut index.php and .htaccess from public directory and paste it in the root directory,thats all and replace two lines in index.php as

  require __DIR__.'/bootstrap/autoload.php';
  $app = require_once __DIR__.'/bootstrap/app.php';