Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

I'm trying to pass two sets of variables into my View and failing miserably...

I need to pass two entities into my view. Both of which work fine when I retrieve them one at at time, but I'm blowing it somewhere when I try to do both.

Here's the function I'm wrestling with in my Controller and my attempt to pass both sets of data into my route simultaneously:

	public function professionals($id) {
		$pages = Page::findOrFail($id);
		$pros = Professional::sortable()->orderBy('lname', 'asc')->paginate(25);
		return view('pros', compact('pros'))->with('pages', compact('pages'));
	}

Open in new window


Here's my view:

@extends('layouts.satellite')
@section('content')
<!-- Section: intro -->
<section id="intro" class="intro">
	<div class="satellite-content">
		<div class="container">
			<div class="row">
				<div class="col-xs-12 satellite_row">
					<?php echo $pages->body; ?>
					<table class="table table-bordered">
						<tr>
						<td style=" background-color:#ea7fea; color:#fff; text-align:center; font-weight:bold;">#</td>
							<td style=" background-color:#ea7fea; color:#fff; text-align:center; font-weight:bold;">@sortablelink('lname', 'Name') </td>
							<td style=" background-color:#ea7fea; color:#fff; text-align:center; font-weight:bold;">@sortablelink('discipline', 'Discipline')</td>
							<td style=" background-color:#ea7fea; color:#fff; text-align:center; font-weight:bold;">@sortablelink('country', 'Country')</td>
							<td style=" background-color:#ea7fea; color:#fff; text-align:center; font-weight:bold;">@sortablelink('cert_year', 'Certified')</td>
						</tr>
						<?php $count=1;?>
						@foreach($pros as $pro)
							<tr>
								<td>{{ $count }}</td>
								<td>{{ $pro->lname }}, {{ $pro->fname }}</td>
								<td>{{ $pro->discipline }}</td>
								<td>{{ $pro->country }}</td>
								<td>{{ $pro->cert_year }}</td>
							</tr>
						<?php $count=$count+1;?>
						@endforeach		
						<tr>
							<td colspan="5" style="text-align:center;">{{ $pros->links() }}</td>
						</tr>
					</table>	
				</div>
			</div>
		</div>
	</div>
</section>
@endsection

Open in new window


This is the error I'm getting:

Trying to get property 'body' of non-object (View: C:\wamp64\www\new_nomas\resources\views\pros.blade.php)

What am I missing?
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

$pros = Professional::sortable()->orderBy('lname', 'asc')->paginate(25);

Open in new window

Why compact() - are you sure that does what you  think it does?

Why not  jus
return view('pro', $pros)->with('pages', compact('pages'));

Open in new window


NB
Just focusing on the $pros data for now - not sure that the compact('pages') is right either.
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you really want to use compact, then this the correct way to do it:

return view('pros', compact('pages', 'pros'));
Avatar of Bruce Gust

ASKER

Thanks, guys!

I got it!