Felipe Mora
Felipe Mora

Reputation: 42

Backpack laravel how show in the same view tables related

Hello how are you all? i enter here because i not found the reply in the documentation, i have a relation 1-1 in my ddbb, is there some way to show this linked in the same view crud? Then with a button that open the eloquent model related in a dialog. Or something in this way without load in. New windows reload, or by example show the details of the parent eloquent and show just in the line down tabulated the children table, there are some. Example that how to do this?

Upvotes: 1

Views: 654

Answers (2)

Tân Nguyễn
Tân Nguyễn

Reputation: 171

Example: In Users Model:

<?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');
    }
}

If you want get one user you can try:

User::find(1)->phone

If you want get all users with phone of this user you can try

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

After you see result object and let see it

Upvotes: 0

Bill Souvas
Bill Souvas

Reputation: 46

If I understood correctly you ask if something like this is possible?

Controller:

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

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

Then in your view you can access the blogpost variable itself:

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

and the children

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

Upvotes: 1

Related Questions