I have website vokzo.com. I add apps block and one is advertisment block But Advertisement block only show one time on whole homepage at the top of apps block's.I want Advertisement block insert automatically after 4 apps blocks .Like when I add apps block's from admin panel after complete 4 blocks website should insert advertisement block automatically.I hope everyone will understand .Below is my index.blade.php file code please someone see and help me.Thank's
#extends( "layouts.master")
#section('content')
<div class="row">
<div class="navigation"> #include('web.home.partials.slider')
<ul>
<li>
<a href="/category/games">
<div class="icon" style="background: #F2B258;"><img src="https://static.apkpure.com/mobile/static/imgs/games.png" width="20"></div>
<div class="text">Hot Games</div>
</a>
</li>
<li>
<a href="/category/apps">
<div class="icon" style="background: #FA8484;"><img src="https://static.apkpure.com/mobile/static/imgs/apps.png" width="20"></div>
<div class="text">Hot Apps</div>
</a>
</li>
<li>
<a href="/category">
<div class="icon" style="background: #5EC9F3"><img src="https://static.apkpure.com/mobile/static/imgs/category.png" width="20"></div>
<div class="text">Category</div>
</a>
</li>
</ul>
</div>
{{-- Advertisement And Apps Block's Start --}}
{{-- ads start --}}
#include('common.ads-placement',[ 'identifier' => 'homepage-leaderboard'])
{{-- ads end --}}
{{-- Apps Block Start --}}
#include('web.home.partials.featured-apps')
{{-- Apps Block End --}}
{{-- Advertisement And Apps Block's END --}}
</div>
#endsection
#push('javascript')
#endpush
As far as I understand your question, you have a set of main blocks ($mainBlocks array) and a set of ad blocks ($adBlocks array) and in the view, you want to repeatedly show 4 main blocks and then, one ad block. Right?
That would be easy: just use a for loop for the main blocks and after each 4 main block, show one ad block. Some thing like this:
$adIndex = 0;
for ($i = 0; $i < count($mainBlocks); $i++)
{
//show a main block: inlcude('SHOW_MAIN_BLOCK', ['block' => $mainBlocks[$i]])
if ($i > 0 && $i % 4 == 0 && $adIndex < count($adBlocks))
{
//show an ad block: inlcude('SHOW_AD_BLOCK', ['block' => $adBlocks[$adIndex]])
$adIndex++;
}
}
Related
I need your help. Lets say I have array with 10 elements and every record to be shown on every iteration and I want to be done with Livewire, let me share with you some code and will tell you what I have tried till now.
public $content;
public $array = ['first', 'second', 'third' ,'fourth'];
foreach ($array as $item) {
sleep(1);
$this->content[] = "Element ${item}";
}
<div class="modal-body">
#if ($content)
<ul class="listree">
#foreach ($content as $element)
<li>
<div class="listree-submenu-heading">
{!! $element['title'] !!}
</div>
<ul class="listree-submenu-items">
#foreach ($element['elements'] as $sub)
<li>
<div class="listree-submenu-heading">
{!! $sub['title'] !!}
</div>
</li>
#endforeach
</ul>
</li>
#endforeach
</ul>
#endif
</div>
My idea is display first record, wait 1 second, display first and second record, wait 1 second, display first, second and third records and so on... How I can do this with livewire. The problem is that $content is filled with the information after all iteration and then the component is refreshed.
I tried on every iteration to send custom event which will call refresh method, but without succes. I will appreaciate any advice, and if you need more information, I will provide it.
Assumming you're also using alpinejs, this can be done pretty easily.
<x-app-layout>
<div class="text-gray-800 ml-10">
<ul class="bg-green-200">
<!-- The main foreach loop. -->
#foreach (range('a', 'z') as $element)
<!-- render al <li> tags with display:none. -->
<!-- Show the 1st after 0s, the 2nd after 1s, the 3rd after 2s, ... -->
<li class="bg-blue-200 m-5"
x-data="{show: false, index: {{ $loop->index }} }"
x-init="setTimeout(() => show = true, index * 1000)">
<div x-show="show">
{{ $element }}
...
</div>
</li>
#endforeach
</ul>
</div>
</x-app-layout>
$loop is a special object you can access within a #foreach block.
I have a datatable for social links. a user can edit the link whenever he wants.
Just link any other crud it is very simple. I am trying to load all the links in blade view with icons in header of my app. I created as function and added a for each loop in the snippets.
here's my controller:
public function socials()
{
$socials = Social::all();
return view('inc.subheader')->with('socials', $socials);
}
Here's blade snippent:
<div class="col-md-3 justify-content-center social-links">
<ul class="nav d-flex justify-content-center">
#foreach ($socials as $social)
<li class="">
<i class="{{ $social->icon }} fa-2x"></i>
</li>
#endforeach
</ul>
</div>
The error I'm getting is "$socials is undefined" and when I go on localhost/inc/social I only see three dots and no icons with links.
Change this line:
return view('inc.subheader')->with('socials', $socials);
to this:
return view('inc.subheader', compact('socials'));
You can try all combination :
return view('inc.subheader', compact('socials'));
return view('inc.subheader', [ 'socials'=> $socials]);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
my controller function is. I passed data through bidder array but array data can't print
public function bidders()
{
$payments = \App\Models\Payment::all();
$posts = Post::all()->where('user_id','=',Auth::user()->id);
foreach ($posts as $post) {
$postid = $post->id;
$bidder[] = Bid::all()->where('post_id','=',$postid);
}
return view('user.student.student-post-bidders',compact('bidder','posts','payments'));
}
Here is my blade in this blade my data print from DB.
How can I print array? indexes of array print in a blade
#php
dd($bidder);
$index = 0;
#endphp
#foreach($bidder as $bid)
#foreach($posts as $post)
#if($post->id == $bid[$index]['post_id'])
<div class="row" >
<!-- Dashboard Box -->
<div class="col-xl-12" >
<div class="dashboard-box margin-top-0">
<!-- Headline -->
<div class="headline">
<h4><strong><span class="bg-danger text-center" style="margin-left: 46px">Your Post Title:</span>{{$bid[$index]->Post->title}}</strong></h4>
</div>
<div class="content">
<ul class="dashboard-box-list">
<li>
<!-- Overview -->
<div class="freelancer-overview manage-candidates">
<div class="freelancer-overview-inner">
<!-- Avatar -->
<div class="freelancer-avatar">
<div class="verified-badge"></div>
#if($bid[$index]->Tutor->profile_Image=='')
<img data-cfsrc="{{asset('asset/images/user-avatar-placeholder.png')}}" alt="" style="display:none;visibility:hidden;">
#else
{{-- {{asset('storage/app/public/profileImages/' . $pic->profile_Image)}}--}}
<img data-cfsrc="{{asset('storage/app/public/profileImages/' . $bid[$index]->Tutor->profile_Image)}}" alt="" style="display:none;visibility:hidden;">
#endif
</div>
<!-- Name -->
<div class="freelancer-name">
<h4>{{$bid[$index]->Tutor->name}}</h4>
<!-- Details -->
<strong><span>Subject:</span></strong>
#foreach($bid[$index]->Tutor->subject as $sub)
<strong><span>{{\App\Models\Subject::find($sub->pivot->subject_id)->subject}}</span></strong>
#endforeach
<!-- Rating -->
<div class="freelancer-rating">
<div class="star-rating" data-rating="{{$bid[$index]->Tutor->rating}}"></div>
</div>
<!-- Bid Details -->
<ul class="dashboard-task-info bid-info">
<li><strong id="{{ $bid[$index]->id}}">PKR:{{$bid[$index]->bid_price}}</strong><span>Fixed Price</span></li>
<li><strong>Days:{{$bid[$index]->days}}</strong><span>Delivery Time</span></li>
</ul>
<!-- Buttons -->
<div class="buttons-to-right always-visible margin-top-25 margin-bottom-0" onclick=" indexID({{$i}})">
<a href="#small-dialog-1"
onclick="moveprice({{ $bid[$index]->id}}), payment({{ $bid[$index]->id}})" class="popup-with-zoom-anim button ripple-effect"
#foreach($payments as $pay) #if($bid[$index]->post_id == $pay->post_id) id="hide" #endif #endforeach><i class="icon-material-outline-check "></i> Accept Bid</a>
{{-- #dd($bid->id)--}}
<i class="icon-feather-mail"></i> Send Message
<a id="btn" class="button gray ripple-effect ico" onclick="removeBid({{$bid[$index]->id}})" title="Remove Bid" data-tippy-placement="top"><i class="icon-feather-trash-2"></i></a>
</div>
</div>
</div>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
<span style="visibility: hidden">{{$i++}}</span>
#endif
#endforeach
#php
$index++;
#endphp
#endforeach
When I run code error will be occur
offset 1 I need all data print in a blade
How to print array index wise
you should use relations,
if you want to show the list of bidders then in bidders model
app/bidders.php
public function post()
{
return $this->belongsTo('App\Post');
}
Assuming that you have proper standards in table structure for mapping eloquent.
then you need to change your bidders function as below
public function bidders()
{
$payments = \App\Models\Payment::get();
$bidders = Bidder::whereHas('post', function($post) {
return $post->where('user_id','=',Auth::user()->id);
//Provides a filter for bidders, post which are related to user
})->with('post')->get();
return view('user.student.student-post-bidders',compact('bidders', 'payments'));
}
And there should be only one loop for bidders on blade as below.
Here is your answer why array is not appearing in blade check in comments for json_encode
#foreach($bidders as $bid)
{{$bid->id}} //gives you bid parameters
{{json_encode($bid->post)}} //this will get all the post details array/object is not printable on blade so encoded to json just for display purpose
//suppose you need only name from post then
{{$bid->post->name}};
#endforeach
This will lower your code length, as well as improve performance due to eager loading and less looping. Also removes stuff like creating array and maintain index and if condition on blade for id check.
That's it.
Happy Coding!!
I think you just need to refactoring your code ),
first of all use $bid->{$index} instead of this $bid[$index]. you have collection but you can use it as array
do you want to group your bidder by post_id ?
There are two type of packages that a customer can choose from: Phone packages or Broadband & Phone Packages.
When user ready to place an order, it will show a summary view with package name information and the cost. Some Summary information does not need to show if they select Phone package or Broadband & Phone Package.
Is there a better way to improve the readability and maintainable? For example
order-sidebar.blade.php
Note: This is small example of block of code. In the real application it is quite large with a lot of if statement broadbandphone or phone
#if ($summary['service'] == "phone" || $summary['service'] == "broadbandphone")
<div class="x5">
<h4>Phone Line x <span class="summary-lines">{{$summary['lines']}}</span></h4>
<ul class="clearfix">
#if ($summary['service'] == "phone")
<li>
<p class="x5-details">
#if ($summary['line_type'] == "newline")
New Line(s)
#endif
#if ($summary['line_type'] == "switch")
Switch line(s)
#endif
</p>
</li>
#endif
#if ($summary['service'] == "phone" && $summary['lines'] > 1)
<li>
<p class="x5-details">{{$summary['linesWithMulitpleNumbers']}}</p>
</li>
#endif
<li>
<p class="x5-details">{{$summary['package']->name}}</p>
<p class="x5-price">£{{$summary['monthlyLinesCost']}}</p>
</li>
</ul>
</div>
#endif
Or should I do two separate files for summary view like order-sidebar-phone.blade.php and order-sidebar-broadbandphone.blade.php
So it would be something like this:
#if ($summary['service'] == "phone")
#include('sections.order-sidebar-phone')
#end
#if ($summary['service'] == "broadbandphone")
#include('sections.order-sidebar-broadbandphone')
#end
You code looks okay to me. However here are some tips that might help reducing if's or making your code more readable.
Shorthand ternary if
Sometimes a shorthand if looks cleaner and more readable:
#if($summary['service'] == "phone")
Foo
#else
Bar
#endif
Can be written as:
{{ ($summary['service'] == "phone" ? "Foo" : "Bar") }}
It's especially useful for just little pieces of text that change depending on a condition.
Indentation
I shouldn't even need to say that. Indent your code right (not saying you didn't in your question...) And your if statements will be less confusing ;)
Partials
While it is an option to split it up completely like you suggested, this can cause a lot of duplicate code...
But you can also split your files so they are not as big and don't contain so many if statements (even if the total is still the same it's better structured and clearer)
For example instead of:
{{-- ... --}
</div>
#if ($summary['newSetup'] == false)
<div class="installation">
<h4>Phone Line x <span class="summary-lines">{{$summary['lines']}}</span></h4>
<ul class="clearfix">
<li>
<p class="installation-details">Installation</p>
<p class="installation-price">£{{$summary['installationCharge']}}</p>
</li>
</ul>
</div>
#endif
<div class="off-costs bg-gray">
<div class="off-costs-header clearfix">
{{-- ... --}}
Put the installation part in it's own file and include it:
{{-- ... --}
</div>
#if ($summary['newSetup'] == false)
#include('installation')
#endif
<div class="off-costs bg-gray">
<div class="off-costs-header clearfix">
{{-- ... --}}
I have an array with 38 records.
After iterating over the first 10 I want it to start on a new column.
This is very simple and an example is below, however, I need to add in HTML which makes it difficult:
#for($i = 0; $i < count($records); $i++)
#if($i % 10 == 0)
//start new column
#endif
<li>{{ $records[$i]['name'] }}</li>
#endfor
What the HTML looks like without looping and what it should look like after looping properly:
<li class="col-sm-3">
<li class="dropdown-header">
Record Set
</li>
<li>Record Name</li>
<li>Record Name</li>
<li>Record Name</li>
</li>
Problem is, after 10 records I need it to break out of col-sm-3 and start a new col-sm-3 without the dropdown-header but with each iteration's record name.
How can this be done? Please ask questions if clarification is needed.
If it's an array then you may use array_chunk:
#foreach(array_chunk($records, 10) as $ten_arrays)
<li class="col-sm-3">
#foreach($ten_arrays as $record)
{{ $record['field_name'] }}
#endforeach
</li>
#endforeach
This will output lis like this:
<li class="col-sm-3">
<!-- Ten Items -->
</li>
<li class="col-sm-3">
<!-- Ten Items -->
</li>