Reputation: 671
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.
Upvotes: 1
Views: 3430
Reputation: 2284
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
Upvotes: 1
Reputation: 4023
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
Upvotes: 0
Reputation: 15549
You don't have AdminIdeaController
, but Admin\AdminIdeaController
(note the admin
subfolder). So, I think your route should be
Route::resource('ideas', 'Admin\AdminIdeaController');
Upvotes: 2