I am trying to use the with method for Eloquent, but I keep getting the error that Class 'App/Models/Assignments' not found. I have checked my namespaces, and it all is set up properly as best as I can see, and I have run composer dump-autoload and composer dump-autoload -o, along with php artisan cache:clear, to no avail.
Here is my "Assignments" model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Assignments extends Model
{
protected $table = 'assignments';
protected $fillable = ['*'];
public function questions() {
return $this->hasMany('App/Models/Questions');
}
}
And here is my "ProvidersAssignments" model that is trying to access the "Assignments" model.
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProvidersAssignments extends Model
{
protected $table = 'providers_assignments';
protected $fillable = [
'assignments_id',
'total',
'grade',
];
public function provider() {
return $this->belongsTo('App/Models/Provider', 'providers_id');
}
public function assignment() {
return $this->belongsTo('App/Models/Assignments');
}
}
And finally, here is the part of the controller that is using with to load ProvidersAssignments::with(['assignment'])->get();
<?php
namespace App\Http\Controllers;
/* core */
use Illuminate\Http\Request;
use Illuminate\Validation\Validator;
use Ixudra\Curl\Facades\Curl;
/* traits */
use App\Traits\Grader;
/* models */
use App\Models\Provider;
use App\Models\ProgressReport;
use App\Models\Assignments;
use App\Models\ProvidersAssignments;
class ProgressReportController extends Controller
{
use Grader;
public function show($id)
{
$provider = Provider::find($id);
$reportcard = $this->createReportcard($provider);
$assignments = ProvidersAssignments::with('assignment')->where('providers_id', $id)->get();
return view('view.name', [
'provider' => $provider,
'reportcard' => $reportcard,
'assignments' => $assignments,
]);
}
}
Like I said, I have triple checked the namespaces, and I have run php artisan cache:clear and composer dump-autoload and neither seems to fix the error.