1
votes

I am a new learner of laravel. I face problem while running my code. Method App\Http\Controllers\CategoryController::manage_category does not exist.

Here is my code:


<?php

namespace App\Http\Controllers;

use App\Models\Category;
use Illuminate\Http\Request;

class CategoryController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('admin/category');
    }
    
    public function manage_category()
    {
        
        return view('admin/manage_category');
    }
}

Here is my web route code:

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\CategoryController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});
Route::get('admin',[AdminController::class,'index']);
Route::post('admin/auth',[AdminController::class,'auth'])->name('admin.auth');  

Route::group(['middleware'=>'admin_auth'],function(){
 
        Route::get('admin/dashboard',[AdminController::class,'dashboard']);
        Route::get('admin/category',[CategoryController::class,'index']);
        Route::get('admin/manage_category',[CategoryController::class,'manage_category']);
});
1
Do you have a public function manage_category() in your CategoryController.php file? There is literally nothing else we can do to help unless you show the code causing this error... - Tim Lewis
Yes I have <?php namespace App\Http\Controllers; use App\Models\Category; use Illuminate\Http\Request; class CategoryController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { return view('admin/category'); } function manage_category() { return view('admin/manage_category'); } } - ahmad bhatti
No, you do not. You have function manage_category(), not public function manage_category(). There's your error. Also, next time, please edit your question; don't post code in comments when you can edit your question and format it better. (I did this for you this time, but next time it's up to you :)) - Tim Lewis
Dear Tim Lewis i do it to public function but result is same, still showing same error. - ahmad bhatti
@Tim Lewis it working now i cleared routing caching and run it again . God bless you. Thank you for mentoring me. - ahmad bhatti

1 Answers

0
votes

Ahmad your code looks fine try below to clear the cache

php artisan cache:clear
php artisan route:clear
php artisan config:clear 
php artisan view:clear