Answer the question
In order to leave comments, you need to log in
What needs to be done in Laravel 5.6 so that the framework understands this construct?
Hello Everyone
Recently I found an interesting repository https://github.com/z-song/laravel-admin for the admin panel. I liked the fact that it does not "shit" its files into the application, that is, the admin panel is rigidly separated from the structure by the Admin daddy in the App \ Admin section. I decided to transfer all my admin controllers to the same folder on the test branch. But how to make laravelka see the controllers in this folder. The structure should be something like this:
App
-- Admin
------ Controllers
---------- DashboardController.php
------ Extensions
------ Middleware
------ e / t / c to taste ...
Registered in the file routes\web.php
use Illuminate\Routing\Router;
Route::group([
'prefix' => 'admin',
'namespace' => 'App\\Admin\\Controllers',
'middleware' => ['web'],
], function (Router $router) {
$router->get('/welcome', function () {
return view('welcome');
});
$router->get('/dashboard', '[email protected]');
});
namespace App\Admin\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class DashboardController extends Controller
{
public function index()
{
return view('welcome')
}
}
Answer the question
In order to leave comments, you need to log in
It seems to have found a solution, I don’t know if there will be pitfalls
In the App / Admin folder, put the routes.php file
use Illuminate\Routing\Router;
Route::group([
'prefix' => config('admin.route.prefix'), // 'admin'
'namespace' => 'App\\Admin\\Controllers',
'middleware' => config('admin.route.middleware'), // ['web']
], function (Router $router) {
$router->get('/welcome', function () {
return view('welcome');
});
$router->get('/dashboard', '[email protected]');
});
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class AdminServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot() // Собственно эта функция и есть мое решение (грузит роуты для админки)
{
if (file_exists($routes = config('admin.admin_dir').'/routes.php')) {
$this->loadRoutesFrom($routes);
}
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question