I'll try to get question table value from answer table this time.
Code
CREATE TABLE `questions` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`content` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
);
CREATE TABLE `answers` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`question_id` int(11) NOT NULL,
`answer` int(11) NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
);
app/Models/Answer.php
public function question(){
return $this->belongsTo(Question::class);
}
app/Admin/Controllers/AnswerController.php
protected function grid()
{
$grid = new Grid(new Answer);
$grid->column('id', __('Id'))->filter();
$grid->column('question.content', __('question')); // Here is the point.
$grid->column('created_at', __('Created at'));
$grid->filter(function($filter){
$filter->equal('question.content');
});
return $grid;
}