Define the Laravel 5 route inside the subfolder and display it through the controller

I have a Laravel 5.2.45 application. I have a controller structure like this:

App
    Http
        Controllers
            Admin
                AdminController.php

inside AdminController.php I have

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Requests;

class AdminController extends Controller 
{

/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct() 
{
    $this->middleware('auth');
    $this->middleware('is.admin');
}

public function index()
{
    return view('admin.home');
}

}

I have a folder structure of views like this:

views
    admin
        home.blade.php

And inside my routes.php I have

Route::get('/admin/home', 'Admin\AdminController@index');

So, I'm trying to get this when I type ... / admin / home browser displays home.blade.php inside the admin folder.

My .php routes:

Route::auth();

Route::get('/', 'FrontController@index');

Route::get('/home', 'FrontController@index');

Route::get('/add_user', 'FrontController@user');

Route::group(['prefix', 'admin', 'namespace' => 'Admin'], function() {
    Route::get('home', 'AdminController@index');
});
+4
source share
3 answers

The prefix is ​​missing in the route definition . Correct it to look like this:

<?php
   Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function() {
       Route::get('/home', 'AdminController@index');
   });

base_url/admin/home , .

+1

.

Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function() {
    Route::get('home', 'AdminController@index');
});

prefix URL-, . , , admin.

/ , . App\Http\Controllers\Admin app/Http/Controllers/Admin.

+1

, :

Route::get('admin/home', 'Admin\AdminController@index');

0

Source: https://habr.com/ru/post/1653884/


All Articles