Support the ongoing development of Laravel.io →
Eloquent Blade

Hi there, =)

I'd like to keep this short and sweet. Just having some issues with the best way to tackle this with blade.

Task: Building the main forum page.

On this page, I need to display the following:

  • Section Title (All things cars)

  • Section Intro Text (Talk about cars and learn more)

  • Post count for a given section

  • Subject Title (Supercars)

  • Subject Intro Text (All things about super cars)

  • Subject view count

  • Post count for a given subject

  • Most recent Thread Title (Check this car out)

Any pointers would be fine, I'm not asking for anyone to do my work.

In my head I'm thinking the following:

However formatting and getting things laid out correctly is beyond me.

public function viewMain()
{
	$data = [
	// Section Title  (All things cars)
	'section_title', 		'===', section::title()->get();

	// Section Intro Text   (Talk about cars and learn more)
	'section_intro', 		'===', section::intro()->get();

    // Post count for a given section
	'post_count_section', 	'===', section::countPost()->get();

	// Subject Title (Supercars)
	'subject_title', 		'===', subject::title()->take('2')->get();

	// Subject Intro Text  (All things about super cars)
	'subject_intro', 		'===', subject::intro()->take('2')->get();

	// Subject view count
	'subject_view_count', 	'===', subject::count()->get();

	// Post count for a given subject
	'post_count_subject', 	'===', post::count()->get();
	];

	return view('forum.main')->withData($data);
}

// View Blade

	@foreach ($data as $data)
	    @if ($data = > 1)
			{{ $data->section_title }}
			{{ $data->section_intro }}
			{{ $data->post_count_section }}
			{{ $data->subject_title }}
			{{ $data->subject_intro }}	
			{{ $data->subject_view_count }}                            
			{{ $data->post_count_subject }}
	    @endif
	@endforeach
Last updated 3 years ago.
0

Just a heads up.

The following is VERY helpful and has meant I can complete this:

https://laracasts.com/discuss/channels/general-discussion/laravel-5-for-loop-wmultiple-relations?page=2

0

what does the '===' do ?

0

astroanu said:

what does the '===' do ?

Is absolutely equal to.

Disregard the rubbish code I wrote above. Refer to the link if you I posted if you want to do as I initially asked. :)

Last updated 8 years ago.
0

i've been using riari's forum package and used the following for the views. Maybe it is helpfull for you:

Show categories/Forumboards

@foreach ($categories as $category)

    <ul>
      <li class="cell-icon">
        <i class="fa fa-folder-open-o"></i>
    </li>
    <li class="cell-info">
        <a href="{{ Forum::route('category.show', $category) }}" class="title h4">{{ $category->title }}</a>
        <div class="description">{{ $category->description }}</div>
        <ul class="forums-list">
            @if (!$category->children->isEmpty())
            @foreach ($category->children as $subcategory)
            <li><a href="{{ Forum::route('category.show', $subcategory) }}"><i class="fa fa-folder-open-o"></i> {{ $subcategory->title }}</a></li>
            @endforeach
            @endif
        </ul>
    </li>
    @if ($category->threadsEnabled)
    <li class="cell-topic-count">{{ $category->threadCount }}</li>
    <li class="cell-reply-count">{{ $category->postCount }}</li>
    <li class="cell-freshness">
      @if ($category->newestThread)
      <a href="{{ Forum::route('thread.show', $category->latestActiveThread->lastPost) }}">{{ $category->newestThread->title }}</a><br>
      @else
      No Topics
      @endif
      @if ($category->latestActiveThread)
      {{ $category->latestActiveThread->created_at->diffForHumans() }}
      <p>by: {{ $category->latestActiveThread->lastPost->authorName }}

      </p>
      @endif
  </li>
  @endif
</ul>

@endforeach
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ausdev86 ausdev86 Joined 22 Aug 2016

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.

© 2025 Laravel.io - All rights reserved.