Try to search your question here, if you can't find : Ask Any Question Now ?

Many to many relationship with different key in laravel

HomeCategory: stackoverflowMany to many relationship with different key in laravel
Avatarpragati asked 1 month ago

I’m building an application in Laravel 5.8 where I’m having two models Project and Year. I have a separate table name project_technical_details. My table look something like this

Projects table

id    name              created_at
 1    ABC Project     //Timestamps


id  project_id  construction_start   construction_end   floors   area
 1     1               2014              2019              10     200
 1     2               2017              2021              19     450


id    years
1     2011
2     2012
3     2013

So now I want to establish many to many relations between projects and year

so I made a model StartYear and defined like:

class StartYear extends Model {

    public function projects()
        return $this->belongsToMany('AppProject', 'project_technical_details', 'construction_start', 'project_id');


But the problem is construction_start is actual year it is not the year_id. How can we achieve desired relationship in such kind to situation?

1 Answers
Best Answer
AvatarMannu answered 1 month ago
Your Answer

18 + 6 =

Popular Tags

WP Facebook Auto Publish Powered By :