Reputation: 409
I have laravel app.
It works locally, using php artisan serve
command.
After deployment to remote server it does not work.
Every artisan command returns:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'App\Models\User' not found
Excerpt from App\Models\User.php
(case-sensitive).
<?
namespace App\Models;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable {
// code here
}
composer dump-autoload does not fix it.
.gitignore
/vendor
.env
/public/css/
/public/js/
/public/img/
/public/fonts/
/node_modules/
composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.3.*",
"caouecs/laravel-lang": "~3.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.0",
"symfony/css-selector": "3.1.*",
"symfony/dom-crawler": "3.1.*"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Seeds\\": "database/seeds/"
},
"files": [
"app/Http/Helpers.php"
]
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist"
}
}
Local system: arch linux with php 7.0 Remote system: debian jessie with php 7.0
Upvotes: 1
Views: 13139
Reputation: 15545
I was using use App\Models\User;
in my controller when I copied my models from root of app folder to Models folder inside app folder.
An additional change was required which was using namespace App\Models;
Inside my models so now my User model looks like:
<?php
namespace App\Models;
use Illuminate\Auth\Authenticatable;
use Laravel\Lumen\Auth\Authorizable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
class User extends Model implements AuthenticatableContract, AuthorizableContract
Upvotes: 0
Reputation: 3390
Check the generated cached files, might still be referencing the old namespace.
rm -r bootrap/cache
should to the trick
Upvotes: 0
Reputation: 409
Finally, I found a solution.
In php.ini set short_open_tag = On
and voila - it works.
Upvotes: 0
Reputation: 163758
Add use
clause at the top of a controller where you're trying to use the model:
use App\Models\User;
Alternatively, you can use full namespace:
$user = App\Models\User::find(1);
Also, make sure User.php
is in the app\Models
directory and make sure you've changed model in config\auth.php
file:
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Model\User::class,
],
],
Upvotes: 3