Undefined variable and other problems

Posted 9 months ago by slickness

I would like to display the created posts of the user with type 4 and 5 on his profile. The newest posts should be displayed first. But I always get the same error message:

Undefined variable: posts

public function getpost()
        $postone = DB::table('posts')->get();

        return view('profiles.profile')
            ->with('posts', $postone);

@foreach ($posts as $postone)
                                  @if (($post->type) === 4)
                                      <a class="img-hover" href="#">
                                      <img class="br-3 img-fluid" src="{{ Storage::url($post->image) }}" alt="" />
                                  @else (($post->type) === 5)
                                      <a class="img-hover" href="#">
                                          <img class="br-3 img-fluid" src="{{ Storage::url($post->video) }}" alt="" />

Now I have three problems:

What am I doing wrong when displaying the data? How can I show the latest posts first? How can I just show the posts of the respective profile?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.