Reputation: 4028
This answer doesn't solve my problem Route::controllers - Method [index] does not exist on [App\Http\Controllers
In web.php
Route::prefix('admin')->group(function () {
Route::resource('post', 'admin\PostsController');
});
in app/Http/Controllers/admin
I have PostsController.php
which contains
<?php
namespace App\Http\Controllers\admin;
use App\Model\Post;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class PostsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
$posts = \App\Post::all();
return view('admin.posts',['posts'=>$posts]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create(Request $request)
{
//
$post = new Post;
$post->content = $request->input('descr');
$post->save();
}
When I go to this url http://127.0.0.1:8000/admin/post
I get the following error
BadMethodCallException Method [index] does not exist on [App\Http\Controllers\admin\PostsController].
call_user_func_array
…
/vendor/laravel/framework/src/Illuminate/Routing/Controller.php 56
public function callAction($method, $parameters)
{
print_r($this);
echo $method;die();
return call_user_func_array([$this, $method], $parameters);
}
//prints
App\Http\Controllers\admin\PostsController Object ( [middleware:protected] => Array ( ) ) index
php artisan prints the following
php artisan route:list
| | GET|HEAD | admin/post | post.index | App\Http\Controllers\admin\PostsController@index | web
Upvotes: 0
Views: 8716
Reputation: 592
Maybe you have Ambiguous class in your controllers, that means you may have same class name in different controllers. To solve that problem, run these commands
1. composer update
2. composer dumpautoload
3. php artisan config:cache
4. php artisan view:clear
Make sure that composer update runs successfully without errors. If errors are mentioned in the console, correct all of them where they occur in your codebase.
Upvotes: 2
Reputation: 633
Using laravel version 5.4 , i ran this commands
php artisan make:controller admin/PostsController --resource
in web.php routes file added this
Route::prefix('admin')->group(function () {
Route::resource('post', 'admin\PostsController');
});
controller file
namespace App\Http\Controllers\admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class PostsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
echo "call to index";
}
........
other functions
}
works fine for me
Upvotes: 1