Support the ongoing development of Laravel.io →
Laravel Eloquent Database
Last updated 1 year ago.
0

First of all you would have to create the relationships between those tables in each class:

// Declare relationships in both models

    
    class Platform extends Model {

        public function priorities() {
            return $this->belongsToMany(Priorities::class);
        }

    }

    class Priority extends Model {

        public function platforms() {
            return $this->belongsToMany(Platform::class);
        }

    }

// Now in your controller you would have to retrieve the value:


    public function getPlatformName($platform_id) {

        $platforms = App\Platform::findOrFail($platform_id);

        foreach($platform->priorities as $priority) {
           echo $priority->name;
        }

    }

// otherExample


    $priorities = App\Platform::findOrFail($platform_id)->priorities()->orderBy('name')->get();

    foreach($priorities as $priority) {
       echo $priority->name;
    }


// Hope its clear enough, for better understanding go to:

Good Luck bro!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.

© 2024 Laravel.io - All rights reserved.