menu

Laravel - Menghilangkan URL /public pada laravel 4.2


Kembali lagi menulis blog,
Oke pada posting sebelumnya kita sudah menginstall laravel..
untuk mengakses laravel yang sudah kita install kita harus membuka pada browser kita dengan
URL: localhost/(nama project)/public
sangat panjang bukan,, untuk itu kita akan mempersingkat url nya menjadi localhost/(nama project) saja ada 2 cara untuk melakukannya.
1. Dengan mengganti hosts nya jika kita menggunakan ubuntu
2. Dengan merapikan file laravelnya sehingga halaman utama atau index kita letakkan diluar

Cara pertama:
cara ini biasa digunakan untuk pengguna ubuntu. cara ini hanya mengkonfigur file hosts saja tanpa merubah isi folder project laravel.
caranya ada disini poin nomer 8.

Cara kedua:
cara ini sangat dianjurkan karena selain menghilangkan path /public cara ini juga membuat folder project laravel menjadi lebih rapi. Caranya:
1. Buat folder bernama protected
2. Masukkan seluruh file/folder yang ada pada project kecuali folder public kedalam folder protected sehingga akan tampak seperti ini

3. Keluarkan seluruh isi folder public sehingga setara dengan folder protected terlihat seperti ini

4. Tidak perlu menghapus folder public yang sudah kosong karena bisa kita gunakan sebagai tempat
    untuk menyimpan file css, font, js, dan lain-lain
5. Edit file paths.php di folder protected/bootstrap/paths.php menjadi:
<?php

return array(

 /*
 |--------------------------------------------------------------------------
 | Application Path
 |--------------------------------------------------------------------------
 |
 | Here we just defined the path to the application directory. Most likely
 | you will never need to change this value as the default setup should
 | work perfectly fine for the vast majority of all our applications.
 |
 */

 'app' => __DIR__.'/../app',

 /*
 |--------------------------------------------------------------------------
 | Public Path
 |--------------------------------------------------------------------------
 |
 | The public path contains the assets for your web application, such as
 | your JavaScript and CSS files, and also contains the primary entry
 | point for web requests into these applications from the outside.
 |
 */

 'public' => __DIR__.'/../..',

 /*
 |--------------------------------------------------------------------------
 | Base Path
 |--------------------------------------------------------------------------
 |
 | The base path is the root of the Laravel installation. Most likely you
 | will not need to change this value. But, if for some wild reason it
 | is necessary you will do so here, just proceed with some caution.
 |
 */

 'base' => __DIR__.'/..',

 /*
 |--------------------------------------------------------------------------
 | Storage Path
 |--------------------------------------------------------------------------
 |
 | The storage path is used by Laravel to store cached Blade views, logs
 | and other pieces of information. You may modify the path here when
 | you want to change the location of this directory for your apps.
 |
 */

 'storage' => __DIR__.'/../app/storage',

);
6. Edit file index.php menjadi
<?php

/**
 * Laravel - A PHP Framework For Web Artisans
 *
 * @package  Laravel
 * @author   Taylor Otwell 
 */

/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader
| for our application. We just need to utilize it! We'll require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/

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

/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let's 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 these users.
|
*/

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

/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can simply call the run method,
| which will execute the request and send the response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have whipped up for them.
|
*/

$app->run();
7. Buka kembali URL localhost/(nama project) 


===DONE!!!===