Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model table within a different model #310

Open
nickkecooper opened this issue Jun 20, 2019 · 1 comment
Open

Model table within a different model #310

nickkecooper opened this issue Jun 20, 2019 · 1 comment

Comments

@nickkecooper
Copy link

nickkecooper commented Jun 20, 2019

Hey guys I wanted to know if anyone could point me in the right direction to include a table from one model into another. So if I make a model that has a relationship to a customer and it has many I would like to phrase the table out with the ones that compare to that user. I was able to get that information into it by `
$equipment = DB::table('equipment')->where('customer', '=', $customer['id'])->get();

	<table id="example1" class="table table-bordered">
	<thead>
	<tr class="success">
		@foreach( $equipment as $col )
		<th>{{ $col->type }}</th>
		@endforeach
	
		<th>Actions</th>
	
	</tr>
	</thead>
	<tbody>
		
	</tbody>
	</table>

`

But this method seems to not work great. If the customer does not have a relation it will show blank rows in the table. The table also doesn't display the title of the rows of the table properly.

@leopinzon
Copy link

You can use the ORM relationships that's already built on Laravel: https://laravel.com/docs/5.3/eloquent-relationships

For your use case it will look something like:

@foreach( $customer->equipments as $e )
<th>{{ $e->type }}</th>
@endforeach

Hope it helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants