Why there is so much problems with this pagination from livewire? i have been see many topics of this.. and srsly i don't get it.. what wrong im doing? https://i.imgur.com/PENGFjf.gifv <- problem
if i go manualy and i write "?page=2" in url adress it is working, but i don't have any actions inside, clicking in pagination buttons
| "laravel/framework": "^8.54",
| "laravel/jetstream": "^2.3",
| "laravel/sanctum": "^2.6",
| "laravel/tinker": "^2.5",
| "livewire/livewire": "^2.5"
<?php
namespace App\Http\Livewire;
use App\Models\Product;
use Livewire\Component;
use Livewire\WithPagination;
class ShopComponent extends Component
{
use WithPagination;
public function render()
{
return view('livewire.shop-component', ['products' => Product::paginate(9)])->layout('layouts.base');
}
public function paginationView()
{
return 'livewire.custom-pagination';
}
}
Custom pagination is copy from vendor - bootstrap pagination
<div>
#if ($paginator->hasPages())
<nav class="pagination justify-content-center">
<ul class="pagination mt-30 mb-30">
{{-- Previous Page Link --}}
#if ($paginator->onFirstPage())
<li class="page-item disabled" aria-disabled="true" aria-label="#lang('pagination.previous')">
<span class="page-link" aria-hidden="true">‹</span>
</li>
#else
<li class="page-item">
<button type="button" dusk="previousPage" class="page-link" wire:click="previousPage" wire:loading.attr="disabled" rel="prev" aria-label="#lang('pagination.previous')">‹</button>
</li>
#endif
{{-- Pagination Elements --}}
#foreach ($elements as $element)
{{-- "Three Dots" Separator --}}
#if (is_string($element))
<li class="page-item disabled" aria-disabled="true"><span class="page-link">{{ $element }}</span></li>
#endif
{{-- Array Of Links --}}
#if (is_array($element))
#foreach ($element as $page => $url)
#if ($page == $paginator->currentPage())
<li class="page-item active" wire:key="paginator-page-{{ $page }}" aria-current="page"><span class="page-link">{{ $page }}</span></li>
#else
<li class="page-item" wire:key="paginator-page-{{ $page }}"><button type="button" class="page-link" wire:click="gotoPage({{ $page }})">{{ $page }}</button></li>
#endif
#endforeach
#endif
#endforeach
{{-- Next Page Link --}}
#if ($paginator->hasMorePages())
<li class="page-item">
<button type="button" dusk="nextPage" class="page-link" wire:click="nextPage" wire:loading.attr="disabled" rel="next" aria-label="#lang('pagination.next')">›</button>
</li>
#else
<li class="page-item disabled" aria-disabled="true" aria-label="#lang('pagination.next')">
<span class="page-link" aria-hidden="true">›</span>
</li>
#endif
</ul>
</nav>
#endif
</div>
shop-component
https://i.imgur.com/bob483q.png
<div>
#foreach ($products as $product)
<div class="col-sm-6 col-lg-4 mb-30">
<div class="card product-card">
<div class="card-body">
<div class="product-thumbnail position-relative">
<span class="badge badge-danger top-right">New</span>
<a href="single-product.html">
<img class="first-img" src="{{ asset('assets/img/product/1.png') }}" alt="thumbnail" />
</a>
<!-- product links -->
<ul class="actions d-flex justify-content-center">
<li>
<a class="action" href="wishlist.html">
<span data-toggle="tooltip" data-placement="bottom" title="add to wishlist" class="icon-heart">
</span>
</a>
</li>
<li>
<a class="action" href="#" data-toggle="modal" data-target="#compare">
<span data-toggle="tooltip" data-placement="bottom" title="Add to compare" class="icon-shuffle"></span>
</a>
</li>
<li>
<a class="action" href="#" data-toggle="modal" data-target="#quick-view" >
<span data-toggle="tooltip" data-placement="bottom" title="Quick view" class="icon-magnifier"></span>
</a>
</li>
</ul>
</div>
<div class="product-desc py-0 px-0">
<h3 class="title">
{{ $product->name }}
</h3>
<div class="star-rating">
<span class="ion-ios-star"></span>
<span class="ion-ios-star"></span>
<span class="ion-ios-star"></span>
<span class="ion-ios-star"></span>
<span class="ion-ios-star de-selected"></span>
</div>
<div class="d-flex align-items-center justify-content-between" >
<span class="product-price">{{ $product->regular_price }}</span>
<button class="pro-btn" data-toggle="modal" data-target="#add-to-cart" >
<i class="icon-basket"></i>
</button>
</div>
</div>
</div>
</div>
</div>
#endforeach
{{-- Paginacja produktów --}}
{{ $products->links() }}
</div>
php artisan livewire:publish --config
php artisan livewire:publish --assets
second , make sure to add this lines in the main template.
<head>
#livewireStyles
</head>
<body>
{{ $slot }}
#livewireScripts
</body>
Related
I am having two events in my component one is changing the layout and another one is sorting. Changing a layout basically it only replace a layout component inside a parent component. Now when i am calling a sorting then livewire giving me a error 'initialdata is null '.
I am looking for to create a sorting order with this same component. And my code is
<div class="dropdown px-2 d-none d-lg-block">
<div class=" text-dark fw-bold dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="px-1">
<img class="" src="{{ Vite::image('icons/classic.png') }}" alt="" />
</span>
<span>
<img class="" src="{{ Vite::image('icons/filter-down.png') }}" alt="" />
</span>
</div>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item text-primary #if($show == 1)text-primary #else text-dark #endif fw-bolder" href="javascript:void(0)" wire:click="$set('show', '1')">
<img src="{{ Vite::image('icons/compact.png') }}" alt="" class="ps-2" /> Card </a>
<a class="dropdown-item uni-border #if($show == 2)text-primary #else text-dark #endif fw-bolder " href="javascript:void(0)" wire:click="$set('show', '2')">
<img src="{{ Vite::image('icons/classic.png') }}" alt`your text`="" class="ps-2" />Classic </a>
<a class="dropdown-item uni-border #if($show == 3) text-primary #else text-dark #endif fw-bolder" href="javascript:void(0)" wire:click="$set('show', '3')">
<img src="{{ Vite::image('icons/com.png') }}" alt="" class="ps-2" />Compact </a>
</div>
</div>
{{-- sorting option --}}
<div class="d-flex justify-content-between pt-2 align-items-center d-none d-lg-block ">
<div class="d-flex align-items-center justify-content-between">
<div>
<span class="m-0">Selected Filters:</span>
<span class=" mx-3 boat-span2 align-items-center rounded-1">
<span>$500 </span>
<span>
<img src="{{ Vite::image('icons/cross.png') }}" alt="" class="" />
</span>
</span>
<span class=" boat-span2 align-items-center rounded-1">
<span> Skipper </span>
<span>
<img src="{{ Vite::image('icons/cross.png') }}" alt="" class="" />
</span>
</span>
</div>
<div class="">
<h6 class="m-0 text-secondary fw-500 ">
<u> Clear Filters</u>
</h6>
</div>
</div>
</div>
#if($show == 2)
{{-- classic layout --}}
#livewire('frontend.boat.listing.layout.classic',['product' => $product])
#elseif($show == 1)
{{-- card layout --}}
#livewire('frontend.boat.listing.layout.card',['product' => $product])
#elseif($show == 3)
{{-- compact layout --}}
#livewire('frontend.boat.listing.layout.compact',['product' => $product])
#endif
</div>
<?php
namespace App\Http\Livewire\Frontend\Boat\Listing;
use App\Models\Product;
use Livewire\Component;
class Listing extends Component
{
// Mount , boot , hydrate component
public $filter_option_recommend = "recommended";
public $show = "2";
// public $filter_option = "name";
// public $product;
public function detail($id, $title)
{
return redirect()->route('website.boat.detail', [$id, $title]);
}
public function render()
{
$product = Product::join('product_time_assign', 'product_time_assign.product_id', '=', 'products.id')
->where([
'products.type_id' => 1, // boat
'products.status' => 'Active',
])
->select(
'products.id as productid',
'product_time_assign.id as timeassignid',
'products.name',
'products.capacity',
'products.price_starts',
'product_time_assign.skipper',
'product_time_assign.product_time_assign_id',
'products.review_rating',
'products.image',
'products.description',
'products.discount_price'
)
->orderBy($this->filter_option_recommend, 'asc')->get();
return view('livewire.frontend.boat.listing.listing', ['product' => $product]);
}
}
MY SLIDER OF CATEGORY TEST IS DISPLAYED THIS WAY IN THE PICTURE i.e images appear below each other
enter image description here...I have tried change the category test with another category but i could not fix it.. i guess the issue mighty be how to display the active image slide first then the rest come after-wards
My view blade is
#foreach ($data['testSlider'] as $slide )
<div class="carousel slide" data-ride="carousel" id="carousel-1">
<div class="carousel-inner" role="listbox">
<div class="carousel-item active">
<img class="w-100 d-block" id="imgslide" src= "{{asset('images/' . $slide->image)}}" alt="Slide Image">
</div>
</div>
<div>
<a class="carousel-control-prev" href="#carousel-1" role="button" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carousel-1" role="button" data-slide="next">
<span class="carousel-control-next-icon"></span>
<span class="sr-only">Next</span>
</a>
</div>
<ol class="carousel-indicators">
<li data-target="#carousel-1" data-slide-to="0" class=""></li>
<li data-target="#carousel-1" data-slide-to="1"></li>
<li data-target="#carousel-1" data-slide-to="2"></li>
</ol>
</div>
#endforeach
MY SLIDER CONTROLLER HAS
use Illuminate\Http\Request;
use App\Models\website\backend\Slider;
use App\Models\website\backend\SliderCategory;
public function test()
{
$data['slider'] = Slider::all();
$data['slidercategory'] = SliderCategory::all();
$data['testSlider'] = Slider::with([
'SliderCategory' => function ($attachmentQuery) {
$attachmentQuery->where('title', 'test Slider');
}
])->get();
return view('testboot', compact('data'));
}
Your images are repeating because you are making an entire carousel for each image instead of adding the images to the first carousel.
<div class="carousel slide" data-ride="carousel" id="carousel-1">
<div class="carousel-inner" role="listbox">
#foreach ($data['testSlider'] as $slide )
<div class="carousel-item {{ $loop->first ? 'active' : '' }}">
<img class="w-100 d-block" id="imgslide-{{$loop->index}}" src= "{{asset('images/' . $slide->image)}}" alt="Slide Image">
</div>
#endforeach
</div>
<div>
<a class="carousel-control-prev" href="#carousel-1" role="button" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carousel-1" role="button" data-slide="next">
<span class="carousel-control-next-icon"></span>
<span class="sr-only">Next</span>
</a>
</div>
<ol class="carousel-indicators">
#foreach ($data['testSlider'] as $slide )
<li data-target="#carousel-1" data-slide-to="{{ $loop->index }}" class="{{ $loop->first ? 'active' : '' }}"></li>
#endforeach
</ol>
</div>
I am trying to display images in bootstrap carousel but am not able to loop. Only one image is shown but not sliding.Am using laravel in the back end. Please assist if you can this is the code.
This is the code:
<div class="container">
<div class="row">
<div id="imageCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
#foreach($images as $value)
<li data-target="#imageCarouselIndicator" data-slide-to="{{ $loop->index }}" class="{{ $loop->first ? 'active' : '' }}"></li>
#endforeach
</ol>
<div class="carousel-inner">
<h3>{{$product->title}}</h3>
#foreach($images as $image )
<div class="item image {{ $loop->first ? 'active' : '' }}">
<div class="carousel-item active">
<img src="/images2/{{$image->filename}}" alt="{{$image->title}}">
</div>
</div>
#endforeach
</div>
<a class="carousel-control-prev" href="#imageCarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#imageCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
Try this:
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
#foreach($images as $image )
<div class="carousel-item {{ $loop->first ? 'active' : '' }}">
<img src="/images2/{{$image->filename}}"/>
</div>
#endforeach
</div>
</div>
I ran the command to generate the customization files for my blog's pagination.
I was able to customize the appearance of the buttons but the issue I now have is that when the page number gets to say 8, the pagination link shows up to 8 links. I would like to implement the '...' separator within the link. My bootstrap-4.blade.php is as follows
<div class="row">
<div class="col-12">
<ul class="pagination justify-content-center">
{{-- Previous Page Link --}}
#if ($paginator->onFirstPage())
<li>
<a aria-label="Next">
<i class="fas fa-arrow-left"></i>
</a>
</li>
#else
<li class="px-1">
<span><i class="fas fa-arrow-left"></i></span>
</li>
#endif
{{-- Pagination Elements --}}
#foreach ($elements as $element)
{{-- "Three Dots" Separator --}}
#if ($paginator->currentPage() > 4 && $page === 2)
<li class="px-1"><span class="page-link">...</span></li>
#endif
{{-- Array Of Links --}}
#if (is_array($element))
#foreach ($element as $page => $url)
#if ($page == $paginator->currentPage())
<li class="px-1"><a style="background:#56107c; color:white; cursor:not-allowed;" href="{{ $url }}">{{ $page }}</a></li>
#else
<li class="px-1">{{ $page }}</li>
#endif
#endforeach
#endif
#endforeach
{{-- Next Page Link --}}
#if ($paginator->hasMorePages())
<li class="px-1">
<span><i class="fas fa-arrow-right"></i></span>
</li>
#else
<li>
<a aria-label="Next">
<i class="fas fa-arrow-right"></i>
</a>
</li>
#endif
</ul>
</div>
</div>
#endif
You can use a built in function $posts->links(), it will auto create everything - links, numbers and next.
I have two tables , categories and articles.Each category has id and name. Each articles has id, name and category id. Now I want to load the data on each tab when a user click on specific category_id.so related product will be shown on each category tab. I have tried but couldn't get the solution.
Category Model
public function articles()
{
return $this->belongsToMany('App\Article')->withTimestamps();
}
Article Model
public function categories()
{
return $this->belongsToMany('App\Category')->withTimestamps();
}
Controller
public function index(){
$categories = Category::with('articles')->whereIn('id', [1, 2, 3])->get();
return view('welcome',compact( 'categories'));
}
Here is the view :
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
#foreach($categories as $category)
<a class="nav-item nav-link " id="nav-home-tab-{{$category->id}}" data-toggle="tab" href="#nav-home-{{$category->id}}" role="tab" aria-controls="nav-home" aria-selected="true">{{$category->title}}</a>
#endforeach
</div>
</nav>
#foreach($categories as $category)
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="nav-home-{{$category->id}}" role="tabpanel" aria-labelledby="nav-home-tab-{{$category->id}}">
<div class="row clearfix">
#foreach($category->articles as $article)
<div class="col-md-3">
<div class="box mt-2 mb-2">
<img src="{{ $article->images ['thumb'] }}">
</div>
</div>
#endforeach
</div>
</div>
</div>
#endforeach
<nav>
<div class="nav nav-tabs" id="nav-tab" role="tablist">
#foreach($categories as $count => $category)
<a id="nav-home-tab-{{$category->id}}" data-toggle="tab" href="#nav-home-{{$category->id}}" role="tab" aria-controls="nav-home" aria-selected="true"
#if($count == 0) class="nav-item nav-link active" #else()class="nav-item nav-link "#endif>{{$category->title}}</a>
#endforeach
</div>
</nav>
<div class="tab-content" id="nav-tabContent">
#foreach($categories as $count => $category)
<div #if($count == 0) class="tab-pane fade show active" #else class="tab-pane fade" #endif id="nav-home-{{$category->id}}"
role="tabpanel" aria-labelledby="nav-home-tab-{{$category->id}}">
<div class="row ">
#foreach($category->articles as $article)
<div class="col-md-3">
<div class="box mt-2 mb-2">
<img src="{{ $article->images ['thumb'] }}">
<h2>قالب بوتسراپ شرکتی</h2>
<p>قالب بوت استراپ شرکتی کاملا فارسی سازی شده و رایگان میتوانید دانلود کنید</p>
<div class=" download-btn">
<i class="fa fa-download"></i> دانلود قالب
<i class="fa fa-laptop"></i> دموی قالب
</div>
</div>
</div>
#endforeach
</div>
</div>
#endforeach
</div>