Hi,
I'm new to this community and programming so I hope I'm posting this question in the right section. If not, please move it to the appropriate one.
I'm modifying a laravel script and i'm trying to pull posts from a certain category id and the developer is making it very hard for me to understand how to do it.
I want to list posts with thumbnail, description, date, etc. It's for my home page. I want to get posts only from a certain category number from my db.
Here's my blade.php:
@if($lastFeatures)
@include('pages.indexpostloadpage')
@endif
My indexpostloadpage:
@foreach($lastFeatures as $k => $item)
@if( $item->type=='quiz')
<div class="badge quiz"><div class="badge-img"></div></div>
@elseif($item->featured_at !== null)
<div class="badge featured"><div class="badge-img"></div></div>
@else
{{ reaction_icon_get($item) }}
@endif
<div class="content-timeline--right">
<div class="content-timeline__link clearfix">
<div class="content-timeline__media">
<figure class="content-timeline__media__image">
<a class="clearfix" style="display:block" href="{{ makeposturl($item) }}" title="{!! $item->title !!}">
<img data-original="{{ makepreview($item->thumb, 's', 'posts') }}" class="lazy" alt="{!! $item->title !!}" width="262" height="147" style="display: inline;">
</a>
</figure>
</div>
<div class="content-timeline__detail">
<div class="content-timeline__detail__container">
<a href="{{ makeposturl($item) }}" title="{!! $item->title !!}">
<h3 class="content-timeline__detail__title" style="margin-right:10px">{!! $item->title !!}</h3>
</a>
<div class="content-timeline__detail--top hide-mobile">
<p class="content-timeline__detail__desc">{{ str_limit($item->body, 75) }}</p>
</div>
<div class="content-timeline__detail--bottom">
<div class="content-timeline__detail__date share_counts " >{{ $DB_USER_LANG=="en" ? $item->created_at->format('F d, Y') : $item->created_at->diffForHumans() }}</div>
</div>
</div>
</div>
</div>
</div>
</div>
My IndexController:
public function index()
{
if(getenvcong('Siteactive')=='no'){
return view('errors.maintenance');
}
$homepagebuilder=getenvcong('p-homepagebuilder');
$HomeColSec1Tit1=null; $HomeColSec2Tit1=null; $HomeColSec3Tit1=null;$HomeColSec1Type1=null; $HomeColSec2Type1=null; $HomeColSec3Type1=null;
if($homepagebuilder=="on"){
$HomeColSec1Tit1=getenvcong('HomeColSec1Tit1');
$HomeColSec2Tit1=getenvcong('HomeColSec2Tit1');
$HomeColSec3Tit1=getenvcong('HomeColSec3Tit1');
$HomeColSec1Type1=getenvcong('HomeColSec1Type1');
$HomeColSec2Type1=getenvcong('HomeColSec2Type1');
$HomeColSec3Type1=getenvcong('HomeColSec3Type1');
}
//set default
if($HomeColSec1Type1==null){ $HomeColSec1Type1=config('buzzytheme_'.getenvcong('CurrentTheme').'.HomeColSec1Type1') !== null ? config('buzzytheme_'.getenvcong('CurrentTheme').'.HomeColSec1Type1') : '["list", "quiz"]';}
if($HomeColSec2Type1==null){ $HomeColSec2Type1=config('buzzytheme_'.getenvcong('CurrentTheme').'.HomeColSec2Type1') !== null ? config('buzzytheme_'.getenvcong('CurrentTheme').'.HomeColSec2Type1') : '["news"]';}
if($HomeColSec3Type1==null){ $HomeColSec3Type1=config('buzzytheme_'.getenvcong('CurrentTheme').'.HomeColSec3Type1') !== null ? config('buzzytheme_'.getenvcong('CurrentTheme').'.HomeColSec3Type1') : '["video"]';}
//colums 1
$lastFeatures= Posts::forhome()->typesAccepted($HomeColSec1Type1)->typesActivete()->approve('yes')->latest("published_at")->paginate(10);
//colums 2
$lastNews = Posts::forhome()->typesAccepted($HomeColSec1Type1)->typesActivete()->approve('yes')->latest("published_at")->paginate(config('buzzytheme_'.getenvcong('CurrentTheme').'.homepage_news_limit'));
//colums 3
$lastTrendingVideos = Posts::forhome()->typesAccepted($HomeColSec1Type1)->typesActivete()->approve('yes')->latest("published_at")->take(10)->get();
$lastFeaturestop = Posts::forhome('Features')->typesActivete()->approve('yes')->where("featured_at", '>', '')->latest("featured_at")->take(10)->get();
$lastvideoscol1 = Posts::forhome()->byType('video')->typesActivete()->approve('yes')->getStats('one_day_stats', 'DESC')->paginate(3);
$lastpoll = Posts::forhome()->byType('poll')->typesActivete()->approve('yes')->latest("published_at")->paginate(2);
$lastTrending = Posts::forhome()->typesActivete()->approve('yes')->getStats('one_day_stats', 'DESC', 10)->get();
if(\Request::query('page')){
if(\Request::ajax()){
if(\Request::query("timeline")=="right"){
return view('pages.indexrightpostloadpage', compact('lastNews'));
}else{
return view('pages.indexpostloadpage', compact('lastFeatures', 'lastvideoscol1', 'lastpoll'));
}
}else{
return redirect('/');
}
}else{
if(Posts::count() < 1){
return view('errors.starting');
}
}
return view('pages.index', compact('lastFeaturestop', 'lastFeatures', 'lastvideoscol1', 'lastpoll', 'lastNews','lastNewsVideos', 'lastTrending', 'lastTrendingVideos', 'HomeColSec1Tit1', 'HomeColSec2Tit1', 'HomeColSec3Tit1'));
}
My DB tables look something like this:
posts -> categories -> ["2,13,"]
The 2 being the parent category and the 13 being the sub-category.
I'm not sure if I need to add anything else but that's the only pages I think needed to me modified to obtain my query. I've been playing around with the queries in IndexController.php and could not get anything to work.
Any help would be appreciated.
Thank you!