简体   繁体   中英

how to access admin controller in Laravel 5?

I want to access admin controller from admin folder ,but I'm having some trouble getting this to work.

routes.php

Route::group(array('namespace' => 'admin', 'prefix' => 'admin'), function() {
  Route::resource('ideas', 'AdminIdeaController');
});

AdminIdeaController.php

<?php namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Session;
use DB;
use Route;
use User;
use Hash;
use Auth;
use Input;
use Logout;
use Validator;
use Authenticatable;
use Redirect;
use Illuminate\Http\Request;

class AdminIdeaController extends BaseController
{

    public function index()
    {

        $data['idas'] = DB::table('ideas')
            ->get();


        return View('/admin/ideas.view',$data);
    }
}

folder path:

Http
    Controllers
        Admin
            AdminIdeaController .php

error:

ReflectionException in Container.php line 736:
Class App\Http\Controllers\AdminIdeaController does not exist

i done everything according laravel:5.

Please help how can i route this folder file.

Thanks.

You don't have AdminIdeaController , but Admin\\AdminIdeaController (note the admin subfolder). So, I think your route should be

Route::resource('ideas', 'Admin\AdminIdeaController');

According to your folder structure your namespace in route is mistake. It should be Admin not admin like this

Route::group(array('namespace' => 'Admin', 'prefix' => 'admin'), function() {
  Route::resource('ideas', 'AdminIdeaController');
});

By this routes your controller should be inside the Admin folder and you can access this controller by /admin/ideas routes

You can make the controller inside folder by using command like this

php artisan make:controller foldername/controllername

If you want to create new folder and make the controller inside that folder you can use this command

php artisan make:controller foldername\\controllername 

You just need to add the name of folder to namespace like this

namespace App\Http\Controllers\name of folder

and then run:

composer dump-autoload

If does not work try to make a new controller with command:

php artisan make:controller nameOfFolder/nameOfController

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM