mardi 20 juin 2023

Property ... does not exist on this collection instance [duplicate]

I have 3 table :

  • Table Grade :

    // MIGRATION
    Schema::create('grade', function (Blueprint $table) {
                $table->id();
                $table->string('grade');
                $table->timestamps();
            });
    
    // MODEL
    public function relationToBobot(){
    return $this->belongsToMany(Bobot::class, 'gradebobot', 'grade_id', 'bobot_id');
    }
    
  • Table Bobot :

    // MIGRATION
    Schema::create('bobot', function (Blueprint $table) {
                $table->id();
                $table->string('bobot');
                $table->integer('harga');
                $table->timestamps();
            });
    
    // MODEL
    public function relationToGrade(){
    return $this->belongsToMany(Grade::class, 'gradebobot', 'bobot_id', 'grade_id');
    }
    
  • Table Grade Bobot (Pivot)

    // MIGRATION
    Schema::create('gradebobot', function (Blueprint $table) {
                $table->id();
                $table->bigInteger('grade_id')->unsigned();
                $table->bigInteger('bobot_id')->unsigned();
                $table->timestamps();
                $table->foreign('grade_id')->references('id')->on('grade')->onDelete('cascade');
                $table->foreign('bobot_id')->references('id')->on('bobot')->onDelete('cascade');
            });
    

I want to show "grade" where have "bobot". This is my Controller :

public function test(){
        $grade = Grade::all();
    return view('welcome', compact('grade'));
    }

And this is my Blade View :

@foreach ($grade as $item)
    <h1></h1>
    @foreach ($grade->relationToBobot->where('grade_id', $item->id) as $item)
        <p></p>
    @endforeach
@endforeach

Can someone help me.. Thanks

Expectation :

A

100

200

300

400

B

500

600

700

800

C

900

1000

1100

1200



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/c9H4TK2
via IFTTT

Aucun commentaire:

Enregistrer un commentaire