Try importing the User model in your controller.
use App\User;
Or you can change your namespace to match the application
artisan app:name Larabook
then
use Larabook\User;
or reference directly
Larabook\User::create(Input::all())
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Class 'App\Http\Controllers\User' not found
larabook Scratch when I write User::create(Input::all( ) );
Try importing the User model in your controller.
use App\User;
Or you can change your namespace to match the application
artisan app:name Larabook
then
use Larabook\User;
or reference directly
Larabook\User::create(Input::all())
@clevonnoel it works. Is it change from version 7.
@Joy Das it's a six year old thread. An by the way laravel 7 is no longer in support
I used but show same error Class 'Larabook\Http\Controllers\User' not found
Check that composer.json updated and that it has the namespace PSR-4 in there
Could try a composer dumpautoload
Should work, unless you have User class in some other directory in your application.
Try the suggest by @bashy
I think that class is stored in app/Larabook/Users/User.
By importing that class like:
use Users/User;
You will be able to use it, if not, maybe you need to look at composer.json o how psr-0 or psr-4 is configured.
it should be:
psr-4: { 'Larabook\': 'app/Larabook' }
and of course, run php artisan dump-autoload to regenerate the autoload file and configuration.
And remember the Larabook series is written for Laravel 4.* and not based on Laravel 5s new namespaced app directory and new folder structure, so more modifications are required
Exactly, @mthomas. Hit this issue square today converting my app from L4.2 to L5.
In the new app/Providers/RouteServiceProvider.php, the map method forces the use of App\Http\Controllers:
public function map()
{
// Once the application has booted, we will include the default routes
// file. This "namespace" helper will load the routes file within a
// route group which automatically sets the controller namespace.
$this->app->booted(function()
{
$this->namespaced('App\Http\Controllers', function(Router $router)
{
require app_path().'/Http/routes.php';
});
});
}
Actually, in my confusion, I ran "php artisan route:list" (new L5 artisan command) and that's when the light bulb went off.
I found this article but not dive into it due to pressing client work, but here it is in case it does prove useful. I do appreciate all who write these articles!
I experienced a similar problem (i think) a couple of days ago. I tried to add the controller routes for the Laravel Translations Manager package.
In order to access the UI you have to add Route::controller('translations', 'Barryvdh\TranslationManager\Controller'); to your routes file but since all routes are namespaced this will add your own namespaces in front of it.
I tried to add the namespace property to the route group but that did not fix it. It still concatenated the namespaces.
I ended up with removing the namespace from the RouteServiceProvider and adding a route group with my app's namespace and an route group for the translation manager. But I'm not sure if this is the way to go or if it is a bug.
public function map()
{
// Once the application has booted, we will include the default routes
// file. This "namespace" helper will load the routes file within a
// route group which automatically sets the controller namespace.
$this->app->booted(function()
{
$this->namespaced('', function(Router $router)
{
require app_path().'/Http/routes.php';
});
});
}
/**
* Application specific routes
*/
$router->group([
'namespace' => 'Acme\Http\Controllers'
], function ($router)
{
// Front-end
$router->get('/', [
'uses' => 'HomeController@index',
'as' => 'home'
]);
//
//
});
/**
* Local/Development only routes
*/
if (App::environment('local'))
{
$router->group(['namespace' => ''], function ($router)
{
$router->controller('admin/translations', 'Barryvdh\TranslationManager\Controller');
});
}
User.php <?php namespace Larabook; use Larabook\User; use Illuminate\Auth\UserTrait; use Illuminate\Database\Eloquent\Model; use Illuminate\Auth\Reminders\RemindableTrait; use Illuminate\Contracts\Auth\User as UserContract; use Illuminate\Contracts\Auth\Remindable as RemindableContract;
class User extends Model implements UserContract, RemindableContract {
use UserTrait, RemindableTrait;
/** * The database table used by the model. * * @var string */ protected $table = 'users';
/** * The attributes excluded from the model's JSON form. * * @var array */ protected $hidden = ['password', 'remember_token']; protected $fillable = ['email','password','phone','current_location','dob'];
}
RegisterController.php ----- <?php namespace Larabook\Http\Controllers;
use Illuminate\Routing\Controller;
class RegisterController extends Controller {
/** * Display a listing of the resource. * GET /register * * @return Response */ public function index() { return 'that a great'; }
/** * Show the form for creating a new resource. * GET /register/create * * @return Response */ public function create() { return view('register.create'); }
public function store(){
// enter a code here
$user = User::create(
Input::only('email','password','phone','current_location','dob')
);
Auth::login($user);
return redirect('/thanksyou');
}
}
RouteserviceProvider.php <?php namespace Larabook\Providers;
use Illuminate\Routing\Router; use Illuminate\Contracts\Routing\UrlGenerator; use Illuminate\Routing\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider {
/** * Called before routes are registered. * * Register any model bindings or pattern based filters. * * @param Router $router * @param UrlGenerator $url * @return void */ public function before(Router $router, UrlGenerator $url) { $url->setRootControllerNamespace('Larabook\Http\Controllers'); }
/** * Define the routes for the application. * * @return void */ public function map() { // Once the application has booted, we will include the default routes // file. This "namespace" helper will load the routes file within a // route group which automatically sets the controller namespace. $this->app->booted(function() { $this->namespaced('Larabook\Http\Controllers', function(Router $router) { require app_path().'/Http/routes.php'; }); }); }
}
BUT NOT SOLVE THE PROBLEM SAME ERROR
Please put your code in code blocks (3x ` or ~ at start and end). Or you can use something like http://laravel.io/bin
all 3 file in this link http://laravel.io/bin/48wBd
You need the use Larabook\User; line in your controller file, not your user file. You might want to brush up on namespacing basics: https://laracasts.com/lessons/namespacing-primer
ok thanks but still different error:- FATAL ERROR. TESTS NOT FINISHED. Class 'Larabook\Http\Controllers\Input' not found in /Users/unobab/Desktop/sites/online-shopping/app/Http/Controllers/RegisterController.php:33
use Input;
// or
\Input::get();
The answer of @bashy works for me..
Please or to participate in this conversation.