Reputation: 4895
What I want is basically this structure :
I started to build this folder structure which I think is pretty correct :
app/
Http/Controllers/
API/
Back/
Front/
resources/
assets/
js/
back/
front/
sass/
back/
front/
views/
back/
front/
Elixir: How can I avoid backend's libraries or assets to be included in frontend's code and vice versa after running gulp
?
Views: How to use namespaces in Laravel views ? For example, given pages1
in views/front/
, which is extending some page2
. I want Blade to automatically search page2
inside views/front
directory when compiling (and not in views/back
for example).
Routes: How to match routes with Controller's namespaces ? I know we can do
Route::group(['domain' => 'example.com'], function() {});
And also
Route::group(['namespace' => 'Admin'], function() {});
But how to combine them ?
Upvotes: 4
Views: 4269
Reputation: 14747
For Elixir, you can use Gulp
module and then use mix
variable to separate assets according to your needs. At this example, gulp will merge script.js
and script2.js
into a final file named public/backend/final.js
.
// backend assets
elixir(function(mix){
mix.scripts([
'js/back/script.js',
'js/back/script2.js',
], 'public/backend/final.js', 'resources/assets');
// here you can declare another group of assets using 'mix'
});
For controllers namespaces, you edit app/Providers/RouteServiceProvider
file and declare each namespace as:
public function map(Router $router)
{
// backend namespace
$router->group(['namespace' => 'App\Http\Controllers\BackEnd'], function ($router) {
require app_path('Http/routes-backend.php');
});
// frontend namespace
$router->group(['namespace' => 'App\Http\Controllers\FrontEnd'], function ($router) {
require app_path('Http/routes-frontend.php');
});
// api namespace
$router->group(['namespace' => 'App\Http\Controllers\API'], function ($router) {
require app_path('Http/routes-api.php');
});
}
Now, create three files:
For example, if you need to declare a new back end controller you detail it at app/Http/routes-backend.php
:
Route::get('dashboard', 'DashboardController@show');
Finally for views:
How to use namespaces in Laravel views ? For example, pages1 in views/front/ blade-extending page2 will automatically search page2 inside view/front directory.
That is not possible, there is not way to page1
autoloads page2
without an explicit reference. Using @extends
is enough, and personally I suggest this structure cause you can track your views with very more control.
Upvotes: 4