Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0
$tags = Tutorial::where('draft', '=', 0)->get()->tags()->get(); // Maybe ?
Last updated 2 years ago.
0

Nope, now i get another error:

 Call to undefined method Illuminate\Database\Eloquent\Collection::tags()

Here are all my models and my controller:

http://laravel.io/bin/avlMy

Maybe i'm doing something stupid there

Thanks for the help once again

Last updated 2 years ago.
0

So i have changed my controller to this:

 <?php

class HomeController extends BaseController {

public function index()
{
    $tutorials = Tutorial::where('draft', '=', 0)->get();
    $tags = $tutorials->first()->tags()->get();
	return View::make('home', array(
        'tags' => $tags,
        'tutorials' => $tutorials
    ));
}

}

Now this is the output:

PHP basics

This course will teach you the basic princeples of PHP

[{"id":"1","name":"php","pivot":{"tutorial_id":"1","tag_id":"1"}},{"id":"2","name":"laravel","pivot":{"tutorial_id":"1","tag_id":"2"}}]

As you can see, i get the title, and the body. But still having problems with the tags. Which i can only grab the first off..

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Dieter91 dieter91 Joined 9 Jun 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.