我所有的apis在localhost中运行正常,我把它放在实时服务器上(ubuntu 16.04)我收到此错误当我请求GET获取项目的特定细节时我收到此错误。
Symfony\Component\Debug\Exception\FatalThrowableError: Class 'App\Rewards' not found in file /var/www/html/projectsfundingandsharing/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php on line 506
Stack trace:
1. Symfony\Component\Debug\Exception\FatalThrowableError->() /var/www/html/projectsfundingandsharing/api/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Concerns/HasRelationships.php:506
获得特定项目我有很多班级模型(我使用laravel elequonet techniq)
这是我的路线/ api.php文件
use Illuminate\Http\Request;
Use App\Article;
Use App\Projects;
Use App\User;
Use App\Rewards;
Use App\Comments;
Use App\User_address;
Use App\Shipping_location;
Use App\ProjectController;
Use App\rewardsController;
Use App\storyController;
Use App\CommentsController;
use App\ActivationService;
//everything works fine when i call this api.
Route::get('projects', 'ProjectController@index');
//errors is occurring here when i trying get all relational models class.
Route::get('projects/{id}', function($id) {
$project = Projects::with('rewardsProject.shippings','projectImage', 'projectFaqs','projectStory','userdetails', 'user.user_address')
->where('id', $id)
->get();
return $project;
//return Projects::find($id)->user->user_address;
});
这是我的项目模型类
namespace App;
use App\Project_images;
use App\Comments;
use App\Rewards;
use Illuminate\Database\Eloquent\Model;
use Eloquent;
use Illuminate\Support\Facades\DB;
class Projects extends Model
{
protected $fillable = ['title', 'video_url', 'pledged_amount', 'currency', 'end_date', 'funded_amount', 'percent_funded', 'funding_model', 'start_date', 'duration', 'category_id', 'category_name', 'user_name','user_id', 'total_backers', 'picture', 'links'];
public function projectUser(){
return $this->hasOne('App\User');
}
public function projectStory(){
return $this->hasOne('App\Story');
}
public function projectFaqs(){
return $this->hasMany('App\Faqs');
}
public function projectRewd()
{
return $this->belongsToMany('App\Rewards','rewards', 'projects_id');
// return $this->hasMany('App\Rewards');
}
public function projectShip()
{
return $this->belongsToMany('App\Shipping_location', 'shipping_locations','reward_id','project_id');
//return $this->belongsToMany('App\Role', 'role_user', 'user_id', 'role_id');
}
public function projectImage()
{
return $this->hasMany('App\Project_images');
}
public function rewardsProject(){
return $this->hasMany('App\Rewards');
}
public function userdetails(){
return $this->hasOne('App\User','id', 'user_id');
}
public function user(){
return $this->belongsTo('App\User');
//return $this->hasManyThrough('App\User', 'App\User_address');
}
}
这是我的rewards.php模型类
namespace App;
use Illuminate\Database\Eloquent\Model;
class rewards extends Model
{
protected $fillable = ['amount', 'delivery_date', 'projects_id', 'quantity', 'backers_count', 'currency', 'contain_shipping_locations', 'title', 'description'];
/*----*/
public function projects() {
return $this->belongsTo('App\Projects');
}
public function shippings(){
return $this->belongsToMany('App\Shipping_location','rewards_shipping_location', 'reward_id', 'shipping_location_id');
}
}
就像这样,我把所有正确的模型类。
请帮助我为什么我得到这个错误,我在所有类文件中放置App\Rewards
路径,当我删除routes / api.php文件中的rewardsProject.shippings
时,我得到{{1 }}
答案 0 :(得分:0)
您的课程未命名为App\Rewards
您将其命名为App\rewards
。
Linux区分大小写。自动装带器根据类名查找文件。自动加载器现在正在寻找Rewards.php
而不是rewards.php
。它不能自动加载你的课程。
在引用类时始终使用正确的大小写,即使PHP不关心,自动装带器也必须加载文件,文件系统可以区分大小写。总是假装区分大小写是一个问题。