I am very new to Laravel. I tried using one example in my code, but as a result I got an error - FatalErrorException in Model.php line 827: Class Category not found
.
Subsequently, I changed one line of code and fixed the error. However, I really do not understand the cause of the error and how I fixed it.
This is my code (as a result, when I try to build a query using category
- I get an error):
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\Category;
class Translation extends Model
{
protected $fillable = array('lang1', 'lang2', 'lang1_code', 'lang2_code', 'category_id', 'created_at', 'updated_at');
public function category() {
return $this->belongsTo('Category', 'category_id');
}
}
However, when I change one line, I do not get the above error:
old line (error): return $this->belongsTo('Category', 'category_id');
new line (no error): return $this->belongsTo('App\Category', 'category_id');
source
share