0
votes

I am new to the Laravel framework and I am stuck with routing.

Folder structure:

app  
     controllers\ 
                   admin\ authcontroller.php

Routes:

Route::get('admin/logout', array('as' =>'admin.logout', 'uses'=>'App\Controllers\Admin\AuthController@getLogout' ));
Route::get('admin/login', array('as' =>'admin.login' , 'uses'=>'App\Controllers\Admin\AuthController@getLogin' ));
Route::get('admin/login',array('as'=>'admin.login.post','uses'=>'App\Controllers\Admin\AuthController@postLogin'));

Route::group( array('prefix' =>'admin' ,'before'=>'auth.admin' ),function (){

    Route::any('/','App\Controllers\Admin\PagesController@index');

    Route::resource('articles','APP\Controllers\Admin\ArticlesController');
    Route::resource('pages','App\Controllers\Admin\PagesController');

});

authcontroller.php

<?php 
namespace App\Controllers\Admin

use Auth, BaseController, Form, Input, Redirect, Sentry, View;

class Authcontroller extends BaseController
{
    public function getLogin(){
      die('here');
        return  View::make('admin.auth.login');
    }
    public function postLogin(){
         $credentials= array(
            'email' =>Input::get('email') ,
            'password'=>Input::get('password'),
             );

         try{

            $user=Sentry::authenticate($credentials,FALSE);
            if($user){
                return  Redirect::route('admin.pages.index');
            }
         }

         catch (Exception $e){
            return  Redirect::route('admin.login')->withErrors(array('login' => $e->getMessage() ));

         }
    }
    /*
      logout function
    */

      public function  getLogout(){
         Sentry::logout();
         return  Redirect::route('admin.login');
      }
}

Error:

Class App\Controllers\Admin\AuthController does not exist

what is make that error appear

also when i run composer dump-autoload from the CMD i did not found the namespace loaded in autoload_namespaces.php file

1
Is that the correct namespace you put the controller? - Damien Pirsy
i use this in my controller namespace App\Controller\Admin use Auth, BaseController, Form, Input, Redirect, Sentry, View; - Mohammed AbdElrahman
did you do a composer dump-autoload? Also, you spelt "Controller", not "Controllers", so try with \App\Controller\Admin\AuthController@method - Damien Pirsy
when i make composer dump-autoload the namespace does not appear in the autoload_namespaces.php also i can not understand the second part of your solution more details please - Mohammed AbdElrahman

1 Answers

0
votes

You have a typing error. Your controllers name is "Authcontroller" and in your Route it is "AuthController". Or have you see this already?