Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent

Hi

I’ve followed all the Laravel documentation on relationships but am still having a problem.

I have two tables:

Qualifications id code title level details

Components id name qualification_id

Every qualification has many components and every component has one qualification.

This is my Qualification Model:

<?php namespace App; use Illuminate\Database\Eloquent\Model; class Qualification extends Model { protected $fillable = [ 'code', 'title', 'type', 'level', 'details', ]; protected $table = 'qualifications'; public $timestamps = true; public function component() { return $this->hasMany('App/Component'); } } Component Model: <?php namespace App; use Illuminate\Database\Eloquent\Model; class Component extends Model { protected $fillable = [ 'name', 'qualification_id', ]; protected $table = 'components'; public $timestamps = true; public function qualification() { return $this->belongsTo('App\Qualification'); } } I want to show the related units when I view a qualification. Qualification controller: <?php namespace App\Http\Controllers; use App\Http\Requests; use App\Component; use App\Qualification; use App\Http\Requests\QualificationRequest; class QualificationController extends Controller { public function show($id) { $qualification = Qualification::find($id); $component = Qualification::find(1)->component; return view('qualifications.show', compact('qualification','component')); } Here is the view 'qualifications.show’ @extends('app') @section('content') <h1>{{ $qualification->title }} </h1> <div class="body">{{ $qualification->code }}</div> <h2> Units </h2> @foreach ($component as $component) <div class="body"> {{ $component->name }} </div> @endforeach @stop But I keep getting an error: FatalErrorException in Model.php line 893: Class 'App/Component' not found Please can someone help? I’ve been at this for a few days and read everything I could find but to no avail and I’m losing hope. Thanks, Jenny.
Last updated 2 years ago.
0

App/Component should be App\Component (backslash).

0

Sign in to participate in this thread!

Eventy

Your banner here too?

0w3n86 0w3n86 Joined 8 Nov 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.