0
votes

i am new to laravel so i create a model using this below: php artisan make:model tasks -a

So it create ( controller, interface , factory, and model )

(in my code every task is related to project )

in the task model i found this line : use phpDocumentor\Reflection\Project;

i didn't now what is this line exactly so i leave it since it is added by the framework.

then i try to create a function belongsTo in the task model to get the project of the task , so it gives me the below error: "Cannot instantiate interface phpDocumentor\Reflection\Project

the solution to this error is to 1- remove the line : use phpDocumentor\Reflection\Project; 2- replace it by use App/Project

but i want to know 1- what is phpDocumentor\Reflection\Project , and why the frame work add it and not add use App/Project ? 2- if i want to keep it how can i solve my problem )Cannot instantiate interface phpDocumentor\Reflection\Project)

TaskModel code below:

namespace App;

use phpDocumentor\Reflection\Project;
use Illuminate\Database\Eloquent\Model;

class Task extends Model
{
    protected $guarded = ['id'];


    public function project()
    {
        return $this->belongsTo(Project::class);
    }
}
1

1 Answers

0
votes

Try explicitly stating where the model is coming from by namespace

public function project()
{
    return $this->belongsTo(App\Project::class);
}