在子文件夹中使用Laravel时如何写路由

时间:2016-05-02 00:23:40

标签: php .htaccess laravel routes

我想在我的域mydomain.com/project1的子文件夹中提供我的Laravel应用程序。我该怎么写我的routes.php?我使用的是这样的东西:

<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

Route::get('/', ['middleware' => 'auth','uses' => 'HomeController@index'])->name('home');

// Authentication
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@authenticate');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

// Administração
Route::group(['prefix' => 'administracao', 'middleware' => 'auth'], function() {
    Route::resource('filiais', 'FiliaisController');
    Route::resource('precos', 'PrecosController');
    Route::resource('funcionarios', 'FuncionariosController');
    Route::resource('cargos', 'CargosController');
    Route::resource('vendedores', 'VendedoresController');
});

// Comercial
Route::group(['prefix' => 'comercial', 'middleware' => 'auth'], function() {
    Route::resource('clientes', 'ClientesController');
    Route::resource('fichas', 'FichasController');
});

// Operacional
Route::group(['prefix' => 'operacional', 'middleware' => 'auth'], function() {
    Route::resource('agenda', 'AgendaController');
    Route::resource('os', 'OsController');
    Route::resource('ambientes', 'AmbientesController');
    Route::resource('processos', 'ProcessosController');

    Route::get('relatorios', 'RelatoriosController@index');
    Route::get('relatorios/word/{os}', 'RelatoriosController@word');
    Route::get('relatorios/excel/{os}', 'RelatoriosController@excel');
    Route::get('relatorios/create', 'RelatoriosController@create');

    Route::group(['prefix' => 'processo', 'middleware' => 'auth'], function() {
        Route::get('create', 'ProcessoController@create');
        Route::get('index', 'ProcessoController@index');

        Route::post('{os}/parse', 'ProcessoController@parse');

        Route::get('{os}', 'ProcessoController@principal');
        Route::match(['get', 'post'], '{os}/detalhe', 'ProcessoController@detalhe');
        Route::get('{os}/duplicidades', 'ProcessoController@duplicidades');
        Route::get('{os}/restantes', 'ProcessoController@restantes');
        Route::match(['get', 'post'], '{os}/auditoria', 'ProcessoController@auditoria');
        Route::match(['get', 'post'], '{os}/operadores', 'ProcessoController@operadores');
        Route::match(['get', 'post'], '{os}/divergencia', 'ProcessoController@divergencia');
        Route::match(['get', 'post'], '{os}/finalizar', 'ProcessoController@finalizar');
        Route::get('{os}/excluir/{setor}', 'ProcessoController@destroy');
    });
});

我得到NotFoundHttpException in RouteCollection任何网址。我还尝试添加路由前缀Route::group(['prefix' => 'subfolder'], function () {...},但它仍然无法识别

修改

我没有编辑我的htaccess,它是:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

1 个答案:

答案 0 :(得分:1)

转到index.php并更改

#From this
require __DIR__.'/../bootstrap/autoload.php';
#To this
require __DIR__.'/../[framework-folder]/bootstrap/autoload.php';


#From this 
$app = require_once __DIR__.'/../bootstrap/app.php';
#To this
$app = require_once __DIR__.'/../[framework-folder]/pulcro/bootstrap/app.php'

.htacces

RewriteEngine On
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_URI} !^
RewriteRule ^(.*)$ /$1 [L]