I've created a list of items that have an icon next to them where I'm trying to click the icon and have it populate a modal that contains the information, and this will be used to delete/edit things as I add to them.
The issue is that now when I click the icon it doesn't seem to pop up any modal at all. Before I added the $key it at least triggered a modal but each one had the info for the first item in the array. Now I"m simply trying to add a key to the necessary item so that if I click the icon I get a modal with only the info for that item.
What am I doing wrong here?
#foreach($nodes as $key => $node)
<div class="uk-width-1-1">
<div class="uk-grid ">
<div class="uk-width-2-6">
{{$node->id}} - {{$node->name}}
</div>
<div class="uk-width-2-6 ">
<span>{{ $node->comment }}</span>
</span>
</div>
</div>
</div>
#endforeach
#foreach($nodes as $key => $node)
<div id="edit-edit-modal{{ $key }}" class="uk-modal">
<div class="uk-modal-dialog">
<div class="uk-width-1-1">
<div class="uk-grid uk-grid-small">
<div class="uk-width-2-10">
{{$node->id}} - {{$node->name}}
</div>
<div class="uk-width-2-10 testComment">
<span>{{ $node->comment }}</span>
</div>
</div>
</div>
</div>
</div>
#endforeach
Put both divs in one foreach
#foreach($nodes as $key => $node)
<div class="uk-width-1-1">
<div class="uk-grid ">
<div class="uk-width-2-6">
{{$node->id}} - {{$node->name}}
</div>
<div class="uk-width-2-6 ">
<span>{{ $node->comment }}</span>
</span>
</div>
</div>
</div>
<div id="edit-edit-modal{{ $key }}" class="uk-modal">
<div class="uk-modal-dialog">
<div class="uk-width-1-1">
<div class="uk-grid uk-grid-small">
<div class="uk-width-2-10">
{{$node->id}} - {{$node->name}}
</div>
<div class="uk-width-2-10 testComment">
<span>{{ $node->comment }}</span>
</div>
</div>
</div>
</div>
</div>
#endforeach
Related
i would have the class "opacity" inserted only at the first "carousel-cell".
For the rest in the loop, they should not be there.
<div class="main-carousel">
#foreach($projects as $p)
#if($p->getMedia('teaser')->first() ?? "")
<div class="carousel-cell">
<div class="row">
<div id="project-info" class="col-lg-3 text-md-right pr-md-5 project-info">
<div class="project opacity">
<h2 class="project-title mb-0">{{$p->name}}</h2>
<h3 class="project-category">Foto / Video Produktion</h3>
</div>
</div>
<div class="col-lg-9 project-img opacity">
<a href="{{url('projects')}}/{{$p->slug}}">
<div class="start-teaser">
<img src="{{asset('storage')}}/{{$p->getMedia('teaser')->first()->id}}/{{$p->getMedia('teaser')->first()->file_name}}" alt="Land Rover">
</div>
</a>
</div>
</div>
</div>
#endif
#endforeach
</div>
You could use the $loop->first variable to add a class only on the first iteration of the loop.
Like this: <div class="carousel-cell {{ $loop->first ? 'opacity' : '' }}">
See more here:
https://laravel.com/docs/9.x/blade#the-loop-variable
I was trying to use #php....#endphp to code some data in a Laravel blade file as follows
<div class="row">
#php
$count =count($doc_list);
if(!empty($chk_doc_list)){
$arrColumns = array_column($chk_doc_list,'docType');
}
#endphp
#for($i=0;$i<$count;$i+=2)
#php
$c1=$i;$c2=$c1+1;
$n1=$c1+1;
$n2=$c2+1;
#endphp
<div class="col-md-6">
<div class="row listview">
<div class="col-md-11">
{{$n1}}. {{$doc_list[$c1]->TDM_Doc_Name}}
</div>
<div class="col-md-1 listicon">
#if(!empty($arrColumns))
#if(in_array($doc_list[$c1]->TDM_Doc,$arrColumns))
<i class="fa fa-check text-success"></i>
#endif
#endif
<!-- <label><input type="checkbox" class="minimal"></label> -->
</div>
</div>
</div>
#if($c2<$count)
<div class="col-md-6">
<div class="row listview">
<div class="col-md-11">
{{$n2}}. {{$doc_list[$c2]->TDM_Doc_Name}}
</div>
<div class="col-md-1 listicon">
#if(!empty($arrColumns))
#if(in_array($doc_list[$c2]->TDM_Doc,$arrColumns))
<i class="fa fa-check text-success"></i>
#endif
#endif
<!-- <label><input type="checkbox" class="minimal"></label> -->
</div>
</div>
</div>
#endif
#endfor
</div>
However, the code didnt work. The browser (I tried with 4 of them) was unable to identify $count in #for($i=0;$i<$count;$i+=2) line.
But, when I changed #php to <?php and #endphp to ?> ,it worked.
So, what was the problem with the first one?
I have this:
#foreach($portfolios as $portfolio)
<div id="item-portfolio-expand{{$portfolio->id}}" class="item-portfolio-expand expand">
<div class="container">
<div class="row">
<div class="col-md-8">
col-md-8
</div>
<div class="col-md-4">
{{ __('Name')}}: {{ $portfolio->name }}
</div>
</div>
</div>
</div>
#endforeach
And this:
#foreach ($portfolios as $portfolio)
<div class="portfolio-item {{ $portfolio->tag }} " data-category="transition">
<img src="{{ $portfolio->image_show }}">
<a href="#item-portfolio-expand{{$portfolio->id}}" data-toggle="collapse" data-target="#item-portfolio-expand{{$portfolio->id}}" data-parent="#item-portfolio-expand{{$portfolio->id}}">
<div class="portfolio-item-overlay">
<p class="name-item-overlay">{{ $portfolio->name }}</p>
</div>
</a>
</div>
#endforeach
And when I press the in the first foreach, I want to toggle the second foreach at <div id = "item-portfolio-expand {{$ portfolio-> id}}" class = "item- portfolio-expand expand "> I just don't succeed at anything, I use bootstrap and jquery in the project. .item-portfolio-expand has display: none;
And at the same time when one is open and another is selected, to close the one already open and to appear the one selected with toggle.
here i'm trying to click on any tabs to retrieve it's own data i did it well and it really retrieves the data of one raw only ?! any help?
<div class="col-lg-12">
<div class="tabs-container">
<ul class="nav nav-tabs">
#foreach($departments as $department)
<li class=""><a data-toggle="tab" href="#tab-{{ $department->id }}" aria-expanded="false">{{ $department->name }}</a></li>
#endforeach
</ul>
<div class="tab-content">
#foreach($works as $work)
<div id="tab-{{ $work->department_id }}" class="tab-pane">
<div class="panel-body">
<div class="row employees">
<div class="col-md-3">
<div class="thumbnail">
<div class="image view view-first"> <img class="img-responsive" src="" name="imaged" alt="image"> </div>
<div class="caption">
<h4>{{ $work->address }} </h4>
<p>{{ $work->body }}</p>
</div>
</div>
<a class="btn btn-primary" href="edit-portfolio.html"> تعديل</a>
<button class="btn btn-danger demo4"> حذف
</button>
</div>
</div>
</div>
</div>
#endforeach
</div>
</div>
</div>
<!-- -->
</div>
i don't need to make it ajax if anyone have a good reason for why it give me only one record for each department?
The reason why you get one record for department is that your loop create one tab panel per work, for example if you have 2 works (1,2) belongs to one department (1) the result would be 2 tabs with the same id set to 1:
departments:
id
-----
1
works:
id department_id
---------------------
1 1
2 1
Html result:
<div id="tab-1" class="tab-pane">
...
</div>
<div id="tab-1" class="tab-pane">
...
</div>
note that both tabs have the same id tab-1.
Solution
group works by department_id, something like this:
$works = Work::all()->groupBy('department_id');
and then in your view:
<div class="tab-content">
#foreach($works as $department_id => $department_works)
<div id="tab-{{ $department_id }}" class="tab-pane">
<div class="panel-body">
<div class="row employees">
#foreach($department_works as $work)
<div class="col-md-3">
<div class="thumbnail">
<div class="image view view-first"> <img class="img-responsive" src="" name="imaged" alt="image"> </div>
<div class="caption">
<h4>{{ $work->address }} </h4>
<p>{{ $work->body }}</p>
</div>
</div>
<a class="btn btn-primary" href="edit-portfolio.html"> تعديل</a>
<button class="btn btn-danger demo4"> حذف </button>
</div>
#endforeach
</div>
</div>
</div>
#endforeach
</div>
Hope this helps
I have these models:
ForumCategory
Forum
Topic
Reply
In the main forum page, I want to count and display the number of replies that associated to this forum.
All the models have relationships.
This is the view:
#foreach ($categories as $category)
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default striped">
<div class="panel-heading">
<div class="row">
<div class="col-md-11">{{ $category->name }}</div>
<div class="col-md-1 text-right"><a><span class="fa fa-arrow-down"></span></a></div>
</div>
</div>
#foreach ($category->forums as $forum)
<div class="panel-body">
<div class="row">
<div class="col-md-1 text-right"><span class="fa fa-envelope fa-4x"></span></div>
<div class="col-md-7">
<h4>
{{ $forum->name }}
<br>
<small>{{ $forum->description }}</small>
</h4>
</div>
<div class="col-md-1 post-num">
<h5>{{ $forum->topics->count() }}<br>
<small>Topics</small></h5>
<h5>{{ $forum->topics->replies->count() }}<br>
<small>Replies</small></h5>
</div>
<div class="col-md-3">
<img src="" class="img-circle last-comnt-img">
Last comment<br>
By Username<br>
<span class="text-muted">12:31</span>
</div>
</div>
</div>
#endforeach
</div>
</div>
</div>
</div>
#endforeach
This line won't work:
$forum->topics->replies->count()