How to solve logical issue with Laravel - Blade - php

I have $win->start, $article->from and $article->days
Now I want to create HTML like this:
if ($article->from) > (Carbon::now()->addDays($article->days)) {
$r = Carbon::now()->addDays($article->days)
if ($r > $win->start) {
<div>get VOUCHER</div>
}
else {
<div>ACTIVE</div>
}
else {
$r = $article->from
if ($r > $win-> start) {
<div>get VOUCHER</div>
}
else {
<div>ACTIVE</div>
}
}
Please help me to solve this logical problem with proper Blade - Carbon code... How to create two if into blade?

I think this should do the trick:
#foreach($wins as $win)
<div class="row">
<div class="col-md-4">
<p>{{ date('d M Y', strtotime($win->start)) }}</p>
</div>
<div class="col-md-4 text-right">
<p><strong>{{$win->price}} </strong>euros</p>
</div>
#if($article->from > \Carbon\Carbon::now()->addDays($article->days))
{{ $r = \Carbon\Carbon::now()->addDays($article->days) }}
#if($r > $win->start)
<div>get VOUCHER</div>
#else
<div>ACTIVE</div>
#endif
#else
{{ $r = $article->from }}
#if($r > $win-> start)
<div>get VOUCHER</div>
#else
<div>ACTIVE</div>
#endif
#endif
</div>
<hr style="margin:0px;">
#endforeach
UPDATED: With your full snippet
More info: https://laravel.com/docs/5.1/blade#control-structures

Related

How can a voyager link for downloading the file uploaded by voyager be defined in a cutome view?

I have tried to code a cutome view in which i would be able to code an html tag to directly download the file which was uploaded before with voyager admin panel. here is my route
Route::get('/download/{research}',[App\Http\Controllers\ResearchController::class, 'download'])->name('download');
here is the html tag:
Download
help me in the controller bellow
public function download(Research $research)
{
}
I've worked through this question all night long and found out this
helpful.
Then I solved it like this:
Controller
public function home()
{
$researches = Research::all();
foreach ($researches as $research){
$download_links[] = json_decode($research->attachment);
}
$departments = Department::all();
$role_id = \TCG\Voyager\Models\Role::all()->where('name','=','student')->first()->id;
$students = User::all()->where('role_id','=',$role_id);
return view('Research.home', compact('researches','departments','students','download_links'));
}
View
{{ $i=0 }}
#foreach($researches as $research)
<div class="row">
<div class="col-md-10">
<button data-toggle="collapse" data-target="#demo{{ $research->id }}" class="btn border text-start form-control" title="click to read abstract">[ {{ ucwords($research->title) }} ] By: {{ $research->user->name }} #if($research->user->student != null) {{ $research->user->student->last_name }} #else {{ $research->user->employee->last_name }}#endif</button>
</div>
<div class="col">
Download
</div>
</div>
<div id="demo{{ $research->id }}" class="collapse row border">
<div class="col-md-12 ">{!! $research->description !!}</div>
</div>
#endforeach
and now is working properly.
public function download($id) {
$research= Research::where('id', $id)->firstOrFail();
$pathToFile = storage_path('fileName' . $research->file);
return response()->download($pathToFile);
}

How to get two ids in one route using Laravel?

Here are my routes:
Route::get('/admin/job-seeker/search/employer/{employerId}', 'AdminJobSeekerSearchController#show')->name('admin.job-seeker.search.employer.show')->middleware('verified');
Route::get('/admin/job-seeker/search/employer/{employerId}/post-a-job/{jobPostId}', 'AdminEmployerJobPostsController#show')->name('admin.employer.post-a-job.show')->middleware('verified');
Controller for first Route:
public function show($employerId)
{
$user = Auth::user();
$jobSeekerProfile = JobSeekerProfile::all()->where('user_id', $user->id)->first();
$employerProfiles = EmployerProfile::limit(1)->where('id', $employerId)->get();
$jobPosts = JobPosts::all();
return view('admin.job-seeker.search.employer.show', compact('employerProfiles', 'id', 'jobSeekerProfile', 'jobPosts'));
}
Controller for second route:
public function show($employerId, $jobPostId)
{
$user = Auth::user();
$jobSeekerProfile = JobSeekerProfile::all()->where('user_id', $user->id)->first();
$employerProfiles = EmployerProfile::limit(1)->where('id', $employerId)->get();
$jobPosts = JobPosts::all();
$jobPost = JobPosts::findOrFail($jobPostId);
return view('admin.employer.post-a-job.show', compact('jobSeekerProfile', 'employerProfiles', 'jobPosts', 'jobPost'));
}
I have two tables employer_profiles and job_posts. After an Employer Registers and creates a profile, he can create job posts with 2 fields job_title and job_description. For example it could be Project Manager and then a description for this role.
I'm getting this error:
Missing required parameters for [Route:
admin.employer.post-a-job.show] [URI:
admin/job-seeker/search/employer/{employerId}/post-a-job/{jobPostId}].
(View:
C:\xampp\htdocs\highrjobs\resources\views\includes\job_seeker_search_employers.blade.php)
(View:
C:\xampp\htdocs\highrjobs\resources\views\includes\job_seeker_search_employers.blade.php)
job_seeker_search_employees.blade:
#if($employerProfiles)
#foreach($employerProfiles as $employerProfile)
<br><br>
<div class="col-md-6 offset-md-3">
<div class="card" style="width: 28rem;">
<img class="card-img-top" src="https://via.placeholder.com/400" alt="Card image cap" style="max-height:400px;">
<div class="card-body">
<h1 class="card-title text-uppercase" style="color: #5dad07;"><strong>{{ $employerProfile['immediate_contact'] }}</strong></h1>
<h3><strong>Positions Available:</strong><br>
#if($jobPosts->where('user_id', $employerProfile->user_id)->count() > 0)
#foreach($jobPosts->where('user_id', $employerProfile->user_id) as $jobPost)
<h5>{{ $jobPost['job_title'] }}</h5>
#endforeach
#else
<h5>No Positions Available</h5>
#endif
</h3>
<h3><strong>Contact Details:</strong></h3>
<p>
<strong>Company Name:</strong> {{ $employerProfile['company_name'] }}<br>
<strong>Contact Email:</strong> {{ $employerProfile['email'] }}<br>
<strong>Phone:</strong> {{ $employerProfile['company_phone'] }}
</p>
<strong>Address:</strong>
<address>{{ $employerProfile['company_address'] }}</address>
</div>
</div>
</div>
<br><br><br>
#endforeach
#endif
Just edit your foreach loop, you have to pass an array as options to rout using route param name as array key:
#foreach($jobPosts->where('user_id', $employerProfile->user_id) as $jobPost)
<h5>{{ $jobPost['job_title'] }}</h5>
#endforeach

Why Laravel pagination show same page?

I have a blog module in my laravel with multiple categories.In other categories pagination works just fine but with this category method links() always show the first page.This is my code:
$page = Categoriepage::where('identifiant', 'orientation')->first();
$idArticle = Articleliaison::select(array('idArticle'))->where('idPage',$page->id)->pluck('idArticle');
$articles = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->get()->take(6);
$links = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->paginate(6);
return View::make('pages.orientation')->with('articles',$articles)->with('links',$links);
and in my view:
<?php $i = 1 ?>
<div class="masonry ">
#foreach($articles as $article)
#include('components.article-or')
<?php $i++ ?>
#endforeach()
</div>
<div class="text-center" style="margin-top: 5%">
{{ $links->links() }}
</div>
You always select the first 6 articles because the articles displayed come from:
$articles = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->get()->take(6);
and not from a paginate request.
There is no need to separate the query for the links and the query for the actual articles. Instead of:
$articles = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->get()->take(6);
$links = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->paginate(6);
You can do:
$articles = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->paginate(6);
and in your view:
<div class="masonry ">
#foreach($articles as $article)
#include('components.article-or')
#endforeach
</div>
<div class="text-center" style="margin-top: 5%">
{{ $articles->links() }}
</div>
I think you got this one a bit mixed up.
You retrieve all articles (->get()) and take the first six (->take(6)). And then you retrieve $links using ->paginator(6).
This can and should all be done using just the ->paginator(6), this way Laravel retrieves the correct 6 articles for the ?page=X you are on and renders the links based on the total amount of articles found by the query.
Try it like this:
$page = Categoriepage::where('identifiant', 'orientation')->first();
$idArticle = Articleliaison::select(array('idArticle'))->where('idPage',$page->id)->pluck('idArticle');
$articles = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->paginate(6);
return View::make('pages.orientation')->with('articles',$articles)
<?php $i = 1 ?>
<div class="masonry ">
#foreach($articles as $article)
#include('components.article-or')
<?php $i++ ?>
#endforeach
</div>
<div class="text-center" style="margin-top: 5%">
{{ $articles->links() }}
</div>
you do not have to make two requests but only one
$page = Categoriepage::where('identifiant', 'orientation')->first();
$idArticle = Articleliaison::select(array('idArticle'))->where('idPage',$page->id)->pluck('idArticle');
$articles = Article::whereIn('id',$idArticle)->where('status','enable')->orderby('created_at','desc')->paginate(6);
return View::make('pages.orientation')->with('articles',$articles);
In your view.
<div class="masonry ">
#foreach($articles as $article)
#include('components.article-or')
<?php $i++ ?>
#endforeach()
</div>
<div class="text-center" style="margin-top: 5%">
{{ $articles->links() }}
</div>

(Undefined offset:0) can't generate more data to trouble shoot

This morning my web app was working. After a few posts were made I tried to login and get the Undefined offset:0 error.
The only information I'm getting from Laravel is that it's in the file path laravel\framework\src\Illuminate\Support\Collection.php
On this file it's saying the error is on line 1688:
public function offsetGet($key)
{
return $this->items[$key];
}
Based on what I found online the issue is related to a bad data call. Perhaps trying to pull data that doesn't exist. I have looked through my database and last 4 Posts and Comments did not have any file attachments so I am not sure where to start looking.
Additionally, the code was written a few years ago by a coworker which makes it more difficult for me to decipher.
Here is my blade file:
#if(app('request')->input('gid'))
<input type="hidden" class="groupid_SeeMore" value="{{app('request')->input('gid')}}"/>
#endif
#foreach($timeline as $post)
<?php
/** the Below Script will grab all Group Names that go with the post and combine into a single stirng **/
$groups= array();
if(strpos($post->grouppermissions,"|")===false){
foreach(explode(',',$post->grouppermissions) as $id){
if($id!=""){
$group = DB::table('groups')->where('groupid','=',$id)->get();
// $groups[] .= $group[0]->name;
$groups[].=explode('|',$group[0]->name)[0];
}
}
}elseif(strpos($post->grouppermissions,"|")!==false){
foreach(explode(',',$post->grouppermissions) as $group){
if($group!="")$groups[].=explode('|',$group)[0];
}
}
$groups=implode(',',$groups);
?>
#if($post->status==0)
<div id="{{$post->id}}" class="Post_Container {{$post->type}} {{$post->type}}{{$post->id}}">
#endif
#if($post->status==1)
<div id="{{$post->id}}" class="Post_Container_Two {{$post->type}} {{$post->type}}{{$post->id}}"><center><p id="cldpsttxt">This post has been closed</center>
#endif
#if($post->favorite==0)
<div class="Post_Header Post_CCthbckgrnd" id="Post_Header{{$post->id}}">
#endif
#if($post->favorite==1)
<div class="Post_Header Post_CCthbckgrnd_Two" id="Post_Header{{$post->id}}"><center><p id="fvrtpsttxt">This post has been Favorited</center>
#endif
<input type="hidden" class="lastid" value="{{$post->id}}"/>
<input type="hidden" class="recent_comment" value="{{$post->recent_comment}}"/>
<div class="Profile_Picture_Container">
<div class="Profile_Picture"><img style="width:100%; height:100%;" src="https://www.vqventure.com/{{$post->pinfo[0]->img}}"/></div>
</div>
#if($groups !="")
<div class="Ginfo">
<center>
<!-- Below the if statement looks for posts with only one group permission-->
#if(strpos($groups, ",") === false)
<b>{{$groups}}</b>
#endif
<!-- Below the if statement looks for posts with multiple group permissions-->
#if(strpos($groups, ",") !== false)
<?php
$key = -1;
$perm = explode(',',$post->grouppermissions);
?>
#foreach(explode(',',$groups) as $group)
<?php $key++;?>
#if($group!="")
<b>{{$group}}</b>
#endif
#endforeach
#endif
</center>
</div>
#endif
<div class="Username_Container">
<div class="Username_Location">
<!--This will be the owner of the post name, for a business it will be the employee name-->
<div class="Username"><b>{{$post->pinfo[0]->name}}</b></div>
</div>
</div>
#if($post->bid != 0 && $post->bid==$user->bid || $post->bid==0 && $post->owner == $user->email)
<div class="Favorite_Container">
<button id="favorite" class="favorite{{$post->id}}" type="{{$post->favorite}}" type2="Timeline"value="{{$post->id}}"></button>
<button id="openclose" class="status{{$post->id}}" type="{{$post->status}}" type2="Timeline" value="{{$post->id}}"></button>
#if($user->bid!=0)
<div class="keywordTypes">
<select class="keywordType" id="{{$post->id}}">
<?php
$cat=$post->category;
if($cat=="")$cat="No category";
?>
<option value="{{$post->category}}" selected>{{$cat}}</option>
#foreach(explode('#$#',$types) as $type)
#if($type!="")<option value="{{$type}}">{{$type}}</option>#endif
#endforeach
</select>
</div>
#endif
</div>
#endif
<b style="position:absolute; top:10%; right:22%;">#{{$post->id}}</b>
#if($post->bid != 0 && $user->admin==1 && $post->bid==$user->bid || $post->owner == $user->email )
<div class="Delete_Button_Container">
<button class="PostDeleteButton" value="{{$post->id}}" id="DeleteMainBTN"></button>
</div>
#endif
</div>
<center>
<!-- Video -->
#if($post->videos!="[]")
<div class="Post_ContentContainer">
<div class="Post_Thumbnail_Container" pid="{{$post->id}}">
<a class="watchVideo" type="" id="{{$post->videos[0]->url}}">
<center> <div class="Post_Thumbnail">
<?php
$vpic = substr($post->videos[0]->url,0,-3)."jpg";
$vpic2 = str_replace("_correted","",$vpic);
?>
<img style="width:100%; height:100%;"src="https://www.vqventure.com/{{$vpic}}" onerror="this.src='https://www.vqventure.com/{{$vpic2}}'" class="video_thumbnail"/>
</div></center>
</a>
</div>
</div>
#endif
<!-- PDF -->
#if($post->else!="[]")
#if($post->else[0]->pics!="" || $post->else[0]->pdf!="")
<div class="Post_ContentContainer">
<div class="Post_Thumbnail_Container" pid="{{$post->id}}">
#if($post->else[0]->pdf!="")
<center><div class="Post_Thumbnail"><a id="wtfPDF" href="https://www.vqventure.com/<?php echo explode('$!$',$post->else[0]->pdf)[0];?>"><img id="PDF_postview" src="https://www.vqventure.com/imgs/pdf.jpeg"/></a></div></center>
#endif
<!-- Images -->
#if($post->else[0]->pics!="")
<center>
<div>
<ul class="Post_Thumbnail" style="list-style-type: none;" id="IMAGES">
#foreach(explode("$!$",$post->else[0]->pics) as $file)
#if($file !="")
<li><img id="IMG_postview" pid="{{$post->id}}"src="https://www.vqventure.com/{{$file}}" class="IMG_postview{{$post->id}}"/></li>
#endif
#endforeach
</ul>
</div>
</center>
#endif
</div>
</div>
<!--This is the end of if pics and pdf-->
#endif
#endif
</center>
<div class="Post_Info_Container2 Post_CCthbckgrnd">
<div class="Post_Info_Header">
<div class="Date_Container">
<!--Input the Date here -->
<?php
$date= explode(' ',$post->timestamp)[0];
$time= explode(" ",$post->timestamp)[1];
?>
<div class="Date"><center><b>{{$date}}</b></center></div>
</div>
<div class="VidTime_Container">
<!--Input the length of the video here -->
<div class="VidTime"><center></center></div>
</div>
<div class="TimeStamp_Container">
<!--Input the TimeStamp here -->
<div class="TimeStamp"><center><b>{{$time}}</b></center></div>
</div>
</div>
#if($post->videos!="[]")
<div class="Post_Title_Container">
<div class="Post_Title_Name"><center><b>Title:</b></center></div>
<div class="Post_Title">{{$post->videos[0]->title}}</div>
</div>
#endif
<div class="Post_Description_Container">
<div class="Post_Description_Name"><center><b>Description:</b></center></div>
<div class="Post_Description">
#if($post->videos!="[]") {!!nl2br(e($post->videos[0]->description)) !!}
#else
<p>{!! nl2br(e($post->else[0]->post)) !!}</p>
#endif</div>
</div>
</div>
#if($showComments=="yes")
<div class="Post_CommentContainer" id="Make_Comment{{$post->id}}">
<textarea class="Post_Comment_TextContainer Post_Comment_TextContainer{{$post->id}}" placeholder="Comment" maxlength="300" rows="2" onkeydown="expandtext(this);" ></textarea>
<input type="hidden" class="gperms{{$post->id}}" value="{{$post->grouppermissions}}"/>
<button class="ChooseFile"><label id="CF" for="CFile{{$post->id}}"></label> <input type="file" name="imgs[]" class="CFile" id="CFile{{$post->id}}" multiple/></button>
<input type="hidden" value="{{ csrf_token() }}" class="CToken{{$post->id}}"/>
<div class="Post"><button id="Pst" pid="{{$post->id}}" ></button></div>
</div>
#if($post->comments!="[]")
<div class="Post_CommentFeedContainer Post_CommentFeedContainer{{$post->id}}">
#foreach($post->comments as $comment)
#if($comment->owner==$user->email)
<div class="Owner_CommentContainer" id="CommentId{{$comment->id}}">
<div class="OCC_Left">
<div class="C_Owner_Name"><center>{{$comment->info[0]->name}}</center></div>
</div>
<div class="OCC_Right">
<div class="C_TimeStamp"><center>{{$comment->timestamp}}</center></div>
#if($post->bid != 0 && $post->bid==$user->bid || $post->bid==0 && $comment->owner == $user->email)
<button class="Delete_Button" value="{{$comment->id}}" id="C_dltbtn" type="Timeline"></button>
#endif
</div>
<div id="CTwo">{!!nl2br(e($comment->comment)) !!}</div>
#if($comment->files!="")
<div class="Owner_Media_Container CommentImages" cid="{{$comment->id}}">
#foreach(explode('#%%#',$comment->files) as $file)
#if(strpos($file, '.pdf') === false && $file!="")<div class="Media_Thumbnail"><img style="width:100%; height:100%;" src="https://www.vqventure.com/{{$file}}" class="CImage{{$comment->id}}"/></div>
#elseif(strpos($file, '.pdf') !== false)<div class="Media_Thumbnail"><img style="width:100%; height:100%;" src="https://www.vqventure.com/imgs/pdf.jpeg"/></div>
#endif
#endforeach
</div>
#endif
</div>
#endif
#if($comment->owner!=$user->email)
<div class="Guest_CommentContainer CommentImages" id="CommentId{{$comment->id}}" cid="{{$comment->id}}">
<div class="GCC_Left">
#if($comment->files!="")
<div class="Guest_Media_Container">
#foreach(explode('#%%#',$comment->files) as $file)
#if(strpos($file, '.pdf') === false && $file!="")<div class="Media_Thumbnail" ><img style="width:100%; height:100%; " src="https://www.vqventure.com/{{$file}}" class="CImage{{$comment->id}}"/></div>
#elseif(strpos($file, '.pdf') !== false)<div class="Media_Thumbnail" ><img style="width:100%; height:100%; " src="https://www.vqventure.com/imgs/pdf.jpeg"/></div>
#endif
#endforeach
</div>
#endif
#if($comment->files!="")
<div class="C_TimeStamp_Guest_Two"><center>{{$comment->timestamp}}</center></div>
#endif
#if($comment->files=="")
<div class="C_TimeStamp_Guest"><center>{{$comment->timestamp}}</center></div>
#endif
</div>
<div class="GCC_Right">
<div class="C_Guest_Name"><center>{{$comment->info[0]->name}}</center></div>
#if($post->bid != 0 && $post->bid==$user->bid && $user->admin==1|| $post->bid==0 && $comment->owner == $user->email)
<button class="Delete_Button" value="{{$comment->id}}" id="C_dltbtn"></button>
#endif
</div>
<div id="COne">{!! nl2br(e($comment->comment)) !!}</div>
</div>
#endif
#endforeach
</div>#endif
#if($post->comments!="[]") <div class="ExpandComment_Container" ><center><div class="Display_AllComments"><button class="Show_All_Comments" id="{{$post->id}}" action=1>Expand Comments...</button></div></center></div> #endif
#endif
</div>
<div id="loading-image" style="display:none; top: 10px; position:relative;"><i>Uploading Comment Please wait....</i></div>
#endforeach
And here is my controller:
public function timeline(Request $request){
if(!isset($this->user->email)){
if(!$request->queryType)return redirect('/');
}
if(isset($this->user->email)){
$email = $this->user->email;
// This needs to query where permissions are equal to the email and the owner = email
$mygroups= groups::where('owner','=',$email)->orwhere('groupadmin','LIKE',"%$email%")->orwhere('members','LIKE',"%$email%")->get();
$groups= "";
foreach($mygroups as $group){
if($group!="")$groups.=','.$group->groupid."$!$".$group->name;
}
$groups=explode(',',$groups);
$timeline = timeline::with('else','videos','comments');
if(!$mygroups->isEmpty()){
$timeline = $timeline->where(function ($query) use($groups) {
for ($i = 0; $i < count($groups); $i++){
if($groups[$i]!=""){
$gid=explode('$!$',$groups[$i])[0];
$gname = explode('$!$',$groups[$i])[1];
$query->orWhere('grouppermissions', 'like', '%' . $gid .'%')
->orWhere('grouppermissions', 'like', '%' . $gname .'%');
}
}
});
$timeline=$timeline->orwhere('owner','=',$this->user->email);
}
if($mygroups->isEmpty()) $timeline=$timeline->where('owner','=',$this->user->email);
if($request->queryType=="Original")$timeline=$timeline->orderBy('id','desc');
if($request->queryType=="Recent" || !$request->queryType)$timeline = $timeline->orderBy('recent_comment','desc')->orderBy('timestamp','desc');
$timeline=$timeline->limit(15)->get();
foreach($timeline as $g){
//THis is for grab business or user info for a post , maynot need it
$pinfo = user::where('email','=',$g['owner']);
$pinfo = $pinfo->get();
$g['pinfo']=$pinfo;
if($g['pinfo'][0]['name']==null)$g['pinfo'][0]['name']=$g['pinfo'][0]['companyname'];
$g['type']="";
foreach($g['comments'] as $c){
$info = user::select("name","img","phone")->where('email','=',$c['owner']);
$info = $info->limit(1)->get();
$c['info']=$info;
$ctimestamp = strtotime($c['timestamp']);
$cdate = new DateTime("#".$ctimestamp); // will snap to UTC because of the
$cdate->setTimezone(new DateTimeZone('America/New_York'));
$c['timestamp']=$cdate->format('Y-m-d H:i:s');
}
$timestamp = strtotime($g['timestamp']);
$date = new DateTime("#".$timestamp); // will snap to UTC because of the
$date->setTimezone(new DateTimeZone('America/New_York'));
$g['timestamp']=$date->format('Y-m-d H:i:s');
}
//if($this->user->admin==1){
//the $list will need to be the businesses branches data exploded by ','
$branches = DB::table('users')
->wherein('email',explode(',',$this->user->branches))->select('bid','email','name')
->get();
// The next few lines are for invitessent
// }
$sess= $this->user->invitessent;
$emails = explode(",",$sess);
$info = array();
foreach($emails as $email){
$test =user::select("name","img")->where('email','=',$email)->limit(1)->get();
if(!$test->isEmpty())$info[]=$test;
}
$website = $this->user->website;
$posts = DB::table('inquiry')->select('*')->where('bid','=', $this->user->bid)->latest()->get();
$types="";
if($this->user->bid!=0){
$biz= user::select('keywords')->where(array(['bid','=',$this->user->bid],['admin','=',1]))->limit(1)->get();
$types = $biz[0]->keywords;
}
if(!$request->queryType)return view('layouts.Timeline',['timeline'=>$timeline,'types'=>$types,'branches'=>$branches, 'posts'=>$posts ,'showComments'=>'yes','user'=>$this->user,'gp_admins'=>'','gp_members'=>'','type'=>'timeline']);
if($request->queryType)return view('includes.Timeline_Posts',['timeline'=>$timeline,'types'=>$types,'user'=>$this->user,'showComments'=>'yes']);
}
}
In addition to fixing the issue and allowing users to access their data, I am hoping someone can help me understand what caused the issue in the first place.
The entire project is in the process of being re-built and I would like to avoid issues with the revamp from lessons learned on this structure. However, I need a quick fix to get it back online until we complete the revamp.
UPDATE:
I changed the code to use ->first instead of [0] but its still giving the same issue. I think the issue is related to the following line of code but not sure how....
<?php
$key = -1;
$perm = explode(',',$post->grouppermissions);
?>
#foreach(explode(',',$groups) as $group)
<?php $key++;?>
So far I have not been able to get any progress...

Is it possible to have 3 div elements and have your loop fill them in order?

Usually when I loop through a database table records, I put them in 1 div, however, I have been wondering whether it is possible to create 3 divs and then put one record in each div, then start from the first div again and rinse and repeat.
Example of how I've done it so far:
<div class="container">
#foreach($albumImages as $albumImage)
<div class="centeredImage stickyContainer" style="background-image: url('/storage/uploads/albums/{{$albumName}}/{{$albumImage->file_name}}')">
<a class='specialA' href=''></a>
</div>
#endforeach
</div>
As you can see in this case, all the records are in the container div.
Example of what I've been thinking about:
<div class="flex-grid">
<div class="col-l"></div>
<div class="col-c"></div>
<div class="col-r"></div>
</div>
and have the first record go in col-l, the second in col-c, the third in col-r and then start from col-l again.
Try this
<div class="flex-grid">
#php($count = 0)
#foreach($albumImages as $albumImage)
#if ($count % 3 == 0)
<div class="col-l"></div>
#elseif($count % 3 == 1)
<div class="col-c"></div>
#else
<div class="col-r"></div>
#endif
#php($count++)
#endforeach
</div>
You can use this code but I later will update my answer with more good solution
#php($count = 0)
#foreach($albumImages as $albumImage)
#if ($count % 3 == 0)
#php($albumImages1[] = $albumImage)
#elseif($count % 3 == 1)
#php($albumImages2[] = $albumImage)
#else
#php($albumImages3[] = $albumImage)
#endif
#php($count++)
#endforeach
#if (!empty($albumImages1))
#foreach($albumImages1 as $albumImage)
// your logic here
#endforeach
#endif
#if (!empty($albumImages2))
#foreach($albumImages2 as $albumImage)
// your logic here
#endforeach
#endif
#if (!empty($albumImages3))
#foreach($albumImages3 as $albumImage)
// your logic here
#endforeach
#endif
Also you can split three part your initial array make global helper functions.
define global function
function split_sequence_by_count ($array, $count) {
$result = [];
for ($i = 0; $i < $count; $i++) {
$result[$i] = [];
}
$_count = 0;
foreach ($array as $current) {
$index = $_count % 3;
$result[$index][] = $current;
$_count++;
}
return $result;
}
usage in blade
#php(list ($albumImages1, $albumImages2, $albumImages3) = split_sequence_by_count($albumImages, 3))
#foreach($albumImages1 as $albumImage)
// your logic here
#endforeach
#foreach($albumImages2 as $albumImage)
// your logic here
#endforeach
#foreach($albumImages3 as $albumImage)
// your logic here
#endforeach
Another way would be array_chunk then just run through the array with 2 nested loops. Should be self-explaining.
<?php
$people =
[
'John',
'Paul',
'Ringo',
'George'
];
$i=0;
$classes = ['col-a','col-b','col-c'];
foreach($people as $name) {
$class = $classes[$i++%3];
?>
<div class='<?=$class?>'>
<?=$name?>
</div>
<?php
}
Formatted output:
<div class='col-a'>
John
</div>
<div class='col-b'>
Paul
</div>
<div class='col-c'>
Ringo
</div>
<div class='col-a'>
George
</div>
Regarding placing each name in each column (as per your comment), we could wrangle the array format:
$classes = ['col-a','col-b','col-c'];
$i=0;
foreach($people as $name)
$columns[$classes[$i++%3]][] = $name;
?>
<?php foreach($columns as $class=>$column) { ?>
<div class='<?=$class?>'>
<?php foreach($column as $name) { ?>
<div class="name">
<?=$name?>
</div>
<?php } ?>
</div>
<?php } ?>
Formatted output:
<div class='col-a'>
<div class="name">
John
</div>
<div class="name">
George
</div>
</div>
<div class='col-b'>
<div class="name">
Paul
</div>
</div>
<div class='col-c'>
<div class="name">
Ringo
</div>
</div>

Categories