@kieranheadley did you also check the controller file name?
Class App\Http\Controllers\App\Http\Controllers\*** does not exist
I have created a new project (having created many before) working through different functionality and have come across this issue;
ReflectionException in Route.php line 280: Class App\Http\Controllers\UserController does not exist
Now the UserController does exist in App\Http\Controllers so I am unsure as to what is causing this?
UserController
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\User;
use App\UserTypes;
use Auth;
use Hashids;
use Redirect;
use Request;
use Hash;
class UserController extends Controller
{
public function index(){
$users = User::get();
return view('users.index', compact('users'));
}
public function getAdd(){
$user_type = UserTypes::pluck('user_type', 'id');
return view('users.add', compact('user_type'));
}
public function postAdd(){
$input = Request::all();
$password = str_random(8);
$user = User::create(
'email' => $input['email'],
'password' => Hash::make($password),
'first_name' => $input['first_name'],
'surname' => $input['surname'],
'phone_number' => $input['phone_number'],
'user_type' => $input['user_type'],
);
return Redirect::action('UserController@index');
}
public function getEdit($id){
}
public function postEdit($id){
}
public function delete($id){
User::find(current(Hashids::decode($id)))->delete();
return Redirect::action('UserController@index');
}
}
Routes
<?php
Route::get('/', 'PagesController@getLogin');
Route::post('/', 'PagesController@postLogin');
Route::get('/logout', 'PagesController@logout');
Route::get('/unauthenticated', 'PagesController@unauthenticated');
Route::get('/recover-password', 'PagesController@recoverPW');
Route::post('/recover-password', 'PagesController@postRecoverPW');
Route::group(['middleware' => 'auth'], function(){
Route::get('/route/selector', 'PagesController@selectRoute');
// Admin Only //
Route::group(['middleware' => 'isAdmin'], function(){
Route::get('/admin', 'AdminController@index');
Route::get('/users', 'UserController@index');
Route::get('/user/add', 'UserController@getAdd');
Route::post('/user/add', 'UserController@postAdd');
Route::get('/user/edit/{id}', 'UserController@getEdit');
Route::post('/user/edit/{id}', 'UserController@postEdit');
Route::get('/user/delete/{id}', 'UserController@delete');
});
});
User
<?php
namespace App;
use Auth;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'first_name', 'surname', 'email', 'password', 'phone_number', 'usertype', 'active_status'
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function isAdmin(){
if(Auth::user()->user_type == 1){
return true;
}else{
return false;
}
}
}
It seems to show after the following code is added;
$user = User::create(
'email' => $input['email'],
'password' => Hash::make($password),
'first_name' => $input['first_name'],
'surname' => $input['surname'],
'phone_number' => $input['phone_number'],
'user_type' => $input['user_type'],
);
I hope that someone can help.
You are probably actually getting 2 errors, only that the last one gets shown on the top of the page, and that error is that the controller does not exist.
The reason why you are seeing that error is because the Model::create() method expects an array of attributes, whilst you are calling it with separate arguments instead.
Try to do:
$user = User::create([
'email' => $input['email'],
'password' => Hash::make($password),
'first_name' => $input['first_name'],
'surname' => $input['surname'],
'phone_number' => $input['phone_number'],
'user_type' => $input['user_type'],
]);
Instead and tell us if the errors disappear.
Please or to participate in this conversation.