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!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community