背包laravel如何在相同的视图表中显示相关

时间:2018-04-25 21:16:23

标签: laravel backpack-for-laravel

你好,你们好吗?我进入这里因为我没有在文档中找到回复,我在我的ddbb中有一个关系1-1,有没有办法在同一个视图中显示这个链接?然后使用一个按钮打开对话框中相关的雄辩模型。或者以这种方式没有加载的东西。新窗口重新加载,或者通过示例显示父级口才的详细信息并显示在行列表中的子表,有一些。示例如何做到这一点?

2 个答案:

答案 0 :(得分:1)

如果我理解正确,你会问这样的事情是否可行?

控制器:

$blogpost= Blogpost::where('id', '=', $id)
            ->with('comments')
            ->with('reactions')->first();

return view('blogpost_single','blogpost' => $blogpost);

然后在您的视图中,您可以访问blogpost变量:

Blog title: {{$blogpost->title}}

和孩子们

Blog comment 1: {{$blogpost->comments[0]->text}} 
Blog comment 2: {{$blogpost->comments[1]->text}} 

答案 1 :(得分:0)

实施例: 在用户模型中:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
/**
     * Get the phone record associated with the user.
     */
    public function phone()
    {
        return $this->hasOne('App\Phone');
    }
}

如果你想要一个用户,你可以尝试:

User::find(1)->phone

如果您希望获得此用户手机的所有用户,可以尝试

User::with('phone')->all();

看到结果对象后再看看

相关问题