【发布时间】:2017-04-02 15:50:04
【问题描述】:
我目前正在将一个使用 laravel 4.1 的旧站点移植到 laravel 5.4。已经实现了很多小改动(错误日志有帮助),但我坚持使用以下模型:
namespace App;
class navire extends Eloquent
{
protected $table = 'navire';
public function user()
{
return $this->belongsTo('user');
}
public function getId()
{
return $this->id;
}
}
我正在尝试从控制器调用它:
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Input;
use App\navire;
class UserController extends Controller
{
public function somefunc()
{
// ....
$navire = \navire::where('user_id',$user->id)->get()->take(1);
}
}
尝试了很多使用“use ...”或在开头使用 \ 调用它的东西,到目前为止没有任何效果
错误示例:
local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'App\Http\Controllers\navire' not found' in /home/user/www/app/Http/Controllers/UserController.php:30
local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'App\Http\Controllers\navire' not found' in /home/user/www/app/Http/Controllers/UserController.php:30
local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'App\navire' not found' in /home/user/www/app/Http/Controllers/UserController.php:32
local.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class 'navire' not found' in /home/user/www/app/Http/Controllers/UserController.php:32
我已经调用了 dumpautoload。
【问题讨论】:
-
调用时从类中删除 \
-
@LeaTano 不使用 App\navire : 'Class 'App\Http\Controllers\navire' not found , with : 'Class 'App\Eloquent' not found'
-
class navire extends \Eloquent 解决了这个问题。谢谢 :)
标签: php laravel-4 laravel-5.4