Support the ongoing development of Laravel.io →
Database Eloquent Views
Last updated 2 years ago.
0

Hi Omar,

I have been messing with a job board database Im porting over. I have opportunities with Client, Specialty, and Status fks. I think this works:

class OpportunitiesController extends Controller {

public function index() {
	
  
	$opportunities=Opportunity::with('client','specialty','jobStatus')->take(25)->paginate(15);
  
  return compact('opportunities');
}

class Opportunity extends Model

{

protected $table = 'opportunities';
protected $primaryKey = 'id';
public function client(){
    return $this->belongsTo('App\Client');
}

public function specialty() {
    return $this->belongsTo('App\Specialty');
}

public function jobStatus()
{
      return $this->belongsTo('App\JobStatus');

}

I am now stuck with a different version of this problem! :-)

Last updated 8 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

omaromp2 omaromp2 Joined 21 Jul 2016

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.