Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Shane McC
Shane McC
3,005 Points

Can't pass data information to the associated view

Hi Everyone

I'm attempting to pass whats only needed to a view on my website. Instead of using the all() method I'm trying to figure out a more efficient way to pass information. I've built one scope and created a query that selects multiple columns from my database (The syntax is below). My question is, when I try and pass the information from the view, literally nothing is appearing in my view and I'm not sure why. What am I doing wrong? How do I fix this problem?

$products = new Product;
$products = $products
        ->select('name', 'description', 'rating_count', 'rating_cache')
    ->ApprovedNames();


Scope

public function scopeApprovedNames($query){
    return $query->where('published', '=', '1');
}

View

 @foreach($products as $product)
        <h4><a href="{{url('/names/'.createMyExpression($product->name))}}">{{myOwnSlug(e($product->name))}}</a></h4>
        <p>{{ !empty($product->description) ? $product->description : 'No Description Given' }}</p>
        <p>{{ $product->rating_count }} {{ Str::plural('review', $product->rating_count) }}</p>
        <p>
            @for ($i=1; $i <= 5 ; $i++)
                <span{{ ($i <= $product->rating_cache) ? '' : '-empty'}}"></span>
            @endfor
        </p>
    @endforeach