pratikthepatil's avatar

Class App\Http\Controllers\Admin\AdminController does not exist does not exist

Hello All,

I am getting the following error:

Class App\Http\Controllers\Admin\AdminController does not exist

I have tried doing composer dump-autoload,

Here is my controller:

<?php

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

use App\model\Admin;
use Auth;


class AdminController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */

     public function __construct()
    {
      $this->middleware('auth');
      $this->adm = new Admin();   

    }


    public function index()
    {
        //echo $request->user()->type;
        $user   = Auth::user();
        $role   = $user->role;

        $total_user = $this->adm->getTotalUser();
        $total_comment = $this->adm->getTotalComment();
        $total_blog = $this->adm->getTotalBlog();
  
        return view('admin.dashboard', array('total_cmt' => $total_comment, 'total_user' => $total_user, 'total_blog' => $total_blog,'role' => $role));

    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }

    public function settings(){

        $setting = $this->adm->getsetting();
        return view('admin.settings', array('setting' => $setting));
    }

    public function savesettings(Request $request){

         
        if($request->file('logo_img')){


        $path = public_path().'/images/'.$request->old_img;

        @unlink($path);

        $imageName = time().'_'. $request->file('logo_img')->getClientOriginalName();
        $request->file('logo_img')->move(base_path() . '/public/images/', $imageName);

        }

        $this->adm->updatesetting($request);
       
       return redirect('admin/settings')->with('message','Data has been saved.');

    }

    public function listcomment(){

        $role   = Auth::user()->role;

        if($role == 'admin' || $role == 'moderator'){
            $rows = $this->adm->getallcomment();
        }elseif ($role == 'editor') {
            $userid = Auth::user()->id;
            $rows = $this->adm->getallcommentbyUser($userid);
        }

       return view('admin.list_comment',array('comm' => $rows));
    }

    public function deletecomment($id){
        $rows = $this->adm->deletecomment($id);
        return redirect('admin/comments')->with('message','Data has been deleted.');

    }

    public function editcomment($id){
       $row = $this->adm->getcomment($id);
       $blog = $this->adm->getblog($row[0]->blog_id);
       return view('admin.edit_comment', array('com' => $row, 'blog' => $blog));
    }
    public function updatecomment(Request $request){
        $this->adm->updatecomment($request);
        return redirect('admin/comments')->with('message','Data has been updated.');
    }
}

What could be the reason? Just for informing, The code works completely fine on XAMPP. This error comes to me only in live server running PHP 7.1 in Cpanel through WHM

0 likes
8 replies
fwdmo's avatar

change namespace App\Http\Controllers\admin; to namespace App\Http\Controllers\Admin;

2 likes
jsonkenyon's avatar
Level 19

Check your folder, and your name space. You have

namespace App\Http\Controllers\admin;

On a windows machine, if you have Admin or admin it is the same. However, you are running cPanel/WHM which is a CentOS box; so if your folder is Admin that isn't the same as admin. They would be treated as two different folders/directories.

Update your namespace to

namespace App\Http\Controllers\Admin;
1 like
pratikthepatil's avatar

@jkenyon @fwdmo Thanks, Your solution was actually correct, I had the folder named in small caps also that was the reason your solution did not work, Renaming the folder's first letter in caps and namespace worked out!

1 like
Cronix's avatar

All namespaces (and the actual dirs they refer to) really should start with a capital letter. Be consistent. In addition to the above, you're doing it here too.

use App\model\Admin;

both the dir and namespace "model" should be "Model" there.

1 like
jsonkenyon's avatar

Okay, having a look you also have this in your construct:

      $this->adm = new Admin();   

Which you have

use App\model\Admin;

Is model lower case or is it App\Model?

Please or to participate in this conversation.