I already tried to search for this issue, but it's all different from mine, so I'm posting this here. I'm trying to create a webserver using nginx
to host multiple laravel projects in subfolders. It's my labs server. So I'd like to have my projects like this:
- domain.com/project1
- domain.com/project2
- domain.com/project3
I'm copying the following nginx location
block for each project (i don't know what's happening here, I just copied from the internet and it worked):
location ^~ /project1/ {
alias /home/web/project1/public;
try_files $uri $uri/ @project1;
location ~ \.php {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME "/home/web/project1/public/index.php";
}
}
location @project1 {
rewrite /avm/(.*)$ /project1/index.php?/$1 last;
}
And RESTful routes in my laravel app like this:
/*
|--------------------------------------------------------------------------
| 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::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');
});
});
Although it seems to work (the page appears, etc) when it goes into bussiness logic (save to database, etc.) it appears to have many bugs. For example when I try to create a new employee in url http://domain.com/project1/administracao/funcionarios
it gives me the error: SQLSTATE[42S22]: Column not found: 1054 Unknown column '/administracao/funcionarios' in
(it's kinda prepending some url routes)
And when I setup a subdomain like project1.domain.com
everything works fine. But I don't want to create a subdomain for each project, I want it to work in subfolders url. Is it possible?