Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
138 views
in Technique[技术] by (71.8m points)

php - Laravel datatable service using with relationship different name

I tried using 2 words method relationship. How i can implement the relationship in datatable service using ->with? In the query method looks like this :

public function query(Pihak $model)
    {
        $model = Pihak::query()
            ->with(['categoryStatus'])
            ->where('client_id', $this->clientid);
        return $this->applyScopes($model);
    }

Which is has different name with database table (database table name for categoryStatus is master_category_status) and then i called it in column like this :

Column::make('categoryStatus')->data('categoryStatus.name')
->name('categoryStatus.name')

Here is it Pihak model

class Pihak extends Model
{

    public $table = 'pihaks';
public function categoryStatus()
    {
        return $this->belongsTo(AppModelsMasterCategoryStatus::class, 'category_status_id', 'id');
    }
}

I got an error Requested unknown parameter 'categoryStatus.name'

question from:https://stackoverflow.com/questions/65935649/laravel-datatable-service-using-with-relationship-different-name

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've found the solution. I don't know why it should be snake case method but i'm trying using the method with snake case method (category_status) and it works


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...