Laravel 5 Breadcrumb group issue - php

I have issue with grouping breadcrumbs. Following is my code:
Breadcrumbs::register('front', function($breadcrumbs) {
$breadcrumbs->push('Home', URL::to('/'));
});
Breadcrumbs::group(['prefix' => 'front', 'parent' => 'front'], function($breadcrumbs)
{
Breadcrumbs::register('product', function($breadcrumbs) {
$breadcrumbs->push(trans('front.product'), route('product'));
});
});
And following error occurs:
FatalErrorException in
/project/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php
line 219: Call to undefined method
DaveJamesMiller\Breadcrumbs\Manager::group()
I am trying to use breadcrumb as per following example, but no luck:
https://github.com/davejamesmiller/laravel-breadcrumbs/issues/84

Fast Breadcrumbs, don't forget create layout for optimize code.
#include('page.breadcrumbs')
<nav class="breadcrumb" style="font-size: 18px;">
<?php $breadcrumb = ''?>
#for($i = 0; $i <= count(Request::segments()); $i++)
<?php $breadcrumb .= Request::segment($i).'/'; ?>
#if($i == 1)
<a class="breadcrumb-item" href="{{url($breadcrumb).'/inicio'}}">{{Request::segment($i).' / '}}</a>
#elseif($i == count(Request::segments()))
<a class="breadcrumb-item active" href="{{url($breadcrumb)}}">{{Request::segment($i)}}</a>
#else
<a class="breadcrumb-item" href="{{url($breadcrumb)}}">{{Request::segment($i).' / '}}</a>
#endif
#endfor
</nav>

Related

The $route.query.page returns a wrong value or it's problem of type casting in the v-if condition

im making a posts page and the thing in focus is pagination.
I've created a pagination component that looks like this:
<template>
<nav aria-label="Pagination">
<ul class="pagination justify-content-end">
<li class="page-item" v-if="currentPage !== 1">
<a #click="previous" class="page-link" href="javascript:void(0)" tabindex="-1">Previous</a>
</li>
<li v-for="page in getNumberOfPagesShow"
v-bind:class="{ disabled: page === currentPage }"
class="page-item">
<a #click="clickPage(page)" class="page-link" href="javascript:void(0)">
{{ page }}
</a>
</li>
<li class="page-item" v-if="currentPage !== totalPages">
<a #click="next" class="page-link" href="javascript:void(0)">Next</a>
</li>
</ul>
</nav>
</template>
<script>
export default {
name: "pagination",
props: ['app', 'onClickPage', 'totalPages', 'page'],
data()
{
return {
currentPage: this.page,
lastPage: 0
}
},
computed: {
getNumberOfPagesShow()
{
if (this.totalPages > 10)
{
return 10;
}
return this.totalPages;
}
},
methods: {
previous()
{
this.currentPage--;
this.clickPage(this.currentPage);
},
next()
{
this.currentPage++;
this.clickPage(this.currentPage);
},
clickPage(page)
{
this.currentPage = page;
this.onClickPage(page);
}
}
}
</script>
<style scoped>
</style>
and the component is called using
<!-- Pagination Top -->
<pagination :total-pages="thread.posts.last_page"
:page="app.$route.query.page"
style="margin-top: 20px;"
:on-click-page="clickPage">
</pagination>
Everything works, except the :page="app.$route.query.page" attribute, which sets the currentPage inside the pagination component.
Now, this code doesn't work:
<li class="page-item" v-if="currentPage !== 1">
<a #click="previous" class="page-link" href="javascript:void(0)" tabindex="-1">Previous</a>
</li>
It's supposed to hide the previous button if current page is 1. However, this doesn't work, suggesting that app.$route.query.page is not getting the value correctly.
When I debug inside the created() method, I write
console.log(this.app.$route.query.page)
it does return the correct value. So I don't know what the problem is.
Thank you in advance!
Great, the solution was to parse the prop page into int:
data()
{
return {
currentPage: parseInt(this.page),
lastPage: 0
}
},

Laravel Pagination "Three Dots" Separator customization

Im currently using Laravel 5.3 and was wondering if there is a option for the customization of the Three Dots deperator. (skips page 9-10, which is to late)
Example
Currently the Three dots initiate if there are more than 11 pages... Which isnt quiet useful if your site is responsive. if there are to many pages so it breaks into 2 lines.
Example2
I cannot find anything regarding there being options for $resource->links(). But if there is please tell me! Much appreciated.
Edit: it has to do with the following function:
vendor/laravel/framework/src/Illuminate/Pagination/LengthAwarePaginator.php (page: 128, render()). The current function does not support a second variable. So i guess i have to rebuild it?
This is a solution for Laravel 5.5+. Here is what it does:
Shows the first and the last page.
Shows previous and next two pages from the current page.
Three dots only appear on the left after the current page is greater than 4.
Three dots only appear on the right after the current page is less than the 4 - (count of pages).
<!-- Pagination Elements -->
#foreach ($elements as $element)
<!-- Array Of Links -->
#foreach ($element as $page => $url)
<!-- Use three dots when current page is greater than 4. -->
#if ($paginator->currentPage() > 4 && $page === 2)
<li class="page-item disabled"><span class="page-link">...</span></li>
#endif
<!-- Show active page else show the first and last two pages from current page. -->
#if ($page == $paginator->currentPage())
<li class="page-item active"><span class="page-link">{{ $page }}</span></li>
#elseif ($page === $paginator->currentPage() + 1 || $page === $paginator->currentPage() + 2 || $page === $paginator->currentPage() - 1 || $page === $paginator->currentPage() - 2 || $page === $paginator->lastPage() || $page === 1)
<li class="page-item"><a class="page-link" href="{{ $url }}">{{ $page }}</a></li>
#endif
<!-- Use three dots when current page is away from end. -->
#if ($paginator->currentPage() < $paginator->lastPage() - 3 && $page === $paginator->lastPage() - 1)
<li class="page-item disabled"><span class="page-link">...</span></li>
#endif
#endforeach
#endforeach
Output:
Page 1 (first page)
Page 3
Page 10 (last page)
Option 1 :
You can customize default files but don't change vendor files directly. Publish them and then add modifications to that.
php artisan vendor:publish --tag=laravel-pagination
This command will automatically create the folder /resources/views/vendor/pagination and you have your files for modification.
You can get more information here : laravel pagination
Option 2:
Maybe you want to get rid of the files that are generated by default. Or, perhaps you want to assign another file to be responsible for your default pagination view.
All of this is possible, but you will need to inform the AppServiceProvider for this action by calling the new pagination views in the boot() method:
use Illuminate\Pagination\Paginator;
public function boot(){
Paginator::defaultView('your-pagination-view-file-name');
Paginator::defaultSimpleView('your-pagination-view-file-name');
}
Get information for defaultView and defaultSimpleView here :laravel pagination
I have created new file for pagination and added in AppServiceProvider.
#if ($paginator->hasPages())
<ul class="blog-pagenation">
{{-- Previous Page Link --}}
#if ($paginator->onFirstPage())
<li class="disabled"><a>«</a></li>
#else
<li>«</li>
#endif
#if($paginator->currentPage() > 3)
<li class="hidden-xs">1</li>
#endif
#if($paginator->currentPage() > 4)
<li><a>...</a></li>
#endif
#foreach(range(1, $paginator->lastPage()) as $i)
#if($i >= $paginator->currentPage() - 2 && $i <= $paginator->currentPage() + 2)
#if ($i == $paginator->currentPage())
<li class="active"><a class="active">{{ $i }}</a></li>
#else
<li>{{ $i }}</li>
#endif
#endif
#endforeach
#if($paginator->currentPage() < $paginator->lastPage() - 3)
<li><a>...</a></li>
#endif
#if($paginator->currentPage() < $paginator->lastPage() - 2)
<li class="hidden-xs">{{ $paginator->lastPage() }}</li>
#endif
{{-- Next Page Link --}}
#if ($paginator->hasMorePages())
<li>»</li>
#else
<li class="disabled"><a>»</a></li>
#endif
</ul>
#endif
By using this i am able to get 3 dots in starting and ending you have to customize classes based on your themes.
Adding to the previous response, once you generate the vendor view files with the artisan command php artisan vendor:publish you can create a new one in that folder and call it for example custom.blade.php and put the following code:
#if ($paginator->hasPages())
<ul class="custom-pagination">
{{-- Previous Page Link --}}
#if ($paginator->onFirstPage())
<li class="disabled pageNumber"><span>« Prev</span></li>
#else
<li><a class="pageNumber" href="{{ $paginator->previousPageUrl() }}" rel="prev">«</a></li>
#endif
{{-- Pagination Elements --}}
#foreach ($elements as $element)
{{-- Array Of Links --}}
#if (is_array($element))
#foreach ($element as $page => $url)
#if ($page === $paginator->currentPage())
<li class="active pageNumber"><span>{{ $page }}</span></li>
#elseif (($page === $paginator->currentPage() + 1 || $page === $paginator->currentPage() + 2)
|| $page === $paginator->lastPage())
<li><a class="pageNumber" href="{{ $url }}">{{ $page }}</a></li>
#elseif ($page === $paginator->lastPage()-1)
<li class="disabled"><span>...</span></li>
#endif
#endforeach
#endif
#endforeach
{{-- Next Page Link --}}
#if ($paginator->hasMorePages())
<li><a class="pageNumber" href="{{ $paginator->nextPageUrl() }}" rel="next">Next »</a></li>
#else
<li class="disabled pageNumber"><span>Next »</span></li>
#endif
</ul>#endif
The important part of the code for the three dots is in the {{-- Array Of Links --}} portion. I think this more or less does what you need but may require additional tweaking.
then you can use it in your view like this:
<div class="pagination">
#if ($users instanceof \Illuminate\Pagination\LengthAwarePaginator)
{{ $users->links('vendor.pagination.custom') }}
#endif
</div>

ErrorException in Macroable.php line 81: Method lastPage does not exist. ---- laravel 5.2

Trying to achiveve the pagination of my user list (working fine), but on my filter page ( http://wasamar.dev/admin#users#filter?filter=new ) it give me this error,
ErrorException in Macroable.php line 81:
Method lastPage does not exist. (View: C:\laragon\www\wasamar\resources\views\pagination\limit_links.blade.php) (View: C:\laragon\www\wasamar\resources\views\pagination\limit_links.blade.php)
This is the paginator render
#include('pagination.limit_links', ['paginator' => $newestUsers])
THE CUSTOM PAGINATION VIEW
<!--
https://stackoverflow.com/questions/28240777/custom-pagination-view-in-laravel-5
Author: Mantas D
-->
<?php
// config
$link_limit = 7; // maximum number of links (a little bit inaccurate, but will be ok for now)
?>
#if ($paginator->lastPage() > 1)
<div class="pagination-centered">
<ul class="pagination">
<li class="montserrat-font {{ ($paginator->currentPage() == 1) ? ' unavailable' : '' }}">
First
</li>
#for ($i = 1; $i <= $paginator->lastPage(); $i++)
<?php
$half_total_links = floor($link_limit / 2);
$from = $paginator->currentPage() - $half_total_links;
$to = $paginator->currentPage() + $half_total_links;
if ($paginator->currentPage() < $half_total_links) {
$to += $half_total_links - $paginator->currentPage();
}
if ($paginator->lastPage() - $paginator->currentPage() < $half_total_links) {
$from -= $half_total_links - ($paginator->lastPage() - $paginator->currentPage()) - 1;
}
?>
#if ($from < $i && $i < $to)
<li class="montserrat-font {{ ($paginator->currentPage() == $i) ? ' current' : '' }}">
{{ $i }}
</li>
#endif
#endfor
<li class="montserrat-font {{ ($paginator->currentPage() == $paginator->lastPage()) ? ' unavailable' : '' }}">
Last
</li>
</ul>
</div>
#endif
based on this ( Reference Author: Mantas D ) Then i tried this
{{ $newestUsers->links() }} and i got this error too.
ErrorException in Macroable.php line 81:
Method links does not exist. (View: C:\laragon\www\wasamar\resources\views\main_app\admin\users#filter.blade.php)
so what did i do wrong?
The fix for this was easy: I had forgotten to add the paginate(30) method to the Users model. Adding that will solve the problem.

Dealing with breadcrumbs in Laravel 4

I have simple breadcrumbs on my page
<ul class="breadcrumb">
<li>
<i class="glyphicon glyphicon-home"></i>
Home
</li>
<?php $link = URL::to('/'); ?>
#for($i = 1; $i <= count(Request::segments()); $i++)
<li>
#if($i < count(Request::segments()) & $i > 0)
<?php $link .= "/" . Request::segment($i); ?>
{{Request::segment($i)}}
#else {{Request::segment($i)}}
#endif
</li>
#endfor
</ul>
This produce breadcrumbs like Home / Page / etc
The problem here is that I have views in my router is like this
Route::get('/users/profile', ['uses' => 'UsersController#viewProfile', 'before' => 'auth|csrf']);
Route::get ('/admin/pages/edit/{pageId}', ['uses' => 'AdminController#pageEdit', 'before' => 'admin']);
So for both routes breadcrumbs will be
Home / Users / Profile
Home / Admin / Pages / Edit / 1
Here middle path in breadcrumb is not existing in this case / Users / and / Edit / .. There are a lot pages like this. Is there a way to avoid this?
Edit:
I know I just can change routes in my router but I don't want. So need some other way to achieve this..
You can use this, and then add a condition (line 24) that:
#if ($title != 'Users' && $title != 'Edit')
<span>{{ $title }}</span>
#endif
Alternatively, if you have lots of these values that you would like to avoid, then you can write an array and check them with the same approach.

Laravel 4.2 Custom Pagination Button - Adding a ID with each button for AJAX call

I am using this tutorial for creating a custom pagination in Laravel 4.2.
I am getting this code-
<ul class="pagination">
<li class="disabled">
<span>«</span>
</li>
<li class="active">
<span>1</span>
</li>
<li>
2
</li>
<li>
»
</li>
</ul>
for pagination buttons.
But I need to add some AJAX and some JS call with ID's.
So, I want this kind of code for this buttons-
<ul class="pagination">
<li class="disabled" id="prev">
<span>«</span>
</li>
<li class="active" id="page[1]">
<span>1</span>
</li>
<li id="page[2]">
2
</li>
<li id="next">
<span>»</span>
</li>
</ul>
Is it possible?
Please help me.
Thanks in advance for helping.
i will give a simpler approach....
put this in anywhere in views folder. let's say you put it (and named it) as partials/pagination.blade.php
put the following code in pagination.blade.php (modify it to match your view)
#if ($paginator->getLastPage() > 1)
<ul class="pagination">
<li>Previous</li>
#for ($i = 1; $i <= $paginator->getLastPage(); $i++)
<li>{{ $i }}</li>
#endfor
<li>Next</li>
</ul>
#endif
Note: above code is a sample. change the layout to suit your need.
i prefer a tags while writing links.
while calling the paginator, use the following,
{{$paginator->links('partials.pagination')}}
No need to go through all those complicated process.
but more of a chance is, whatever you are trying to do, can be done purely with javascript.
You can extend the lluminate\Pagination\Presenter class and implement its abstract methods. For example (Put it in app/extension folder):
class CustomPresenter extends Illuminate\Pagination\Presenter {
public function getActivePageWrapper($text)
{
$url = $this->paginator->getUrl($this->paginator->getCurrentPage());
$query = parse_url($url, PHP_URL_QUERY);
parse_str($query, $params);
return '<li id="page['.$params['page'].']" class="active">'.$text.'</li>';
}
public function getDisabledTextWrapper($text)
{
return '<li class="disabled">'.$text.'</li>';
}
public function getPageLinkWrapper($url, $page, $rel = null)
{
$query = parse_url($url, PHP_URL_QUERY);
parse_str($query, $params);
$id = $params['page'];
return '<li id="page['.$id.']">'.$page.'</li>';
}
}
Add an entry in composer > autoload > classmap section like this:
//...
"app/tests/TestCase.php",
"app/extensions"
To use the Custom Presenter:
At first, create a view (custom-presenter.php) in app/views directory. Then, replace pagination option in the app/config/view.php configuration file with the new view's name, like this:
'pagination' => 'custom-presenter'
Finally, the following code would be placed in your custom presenter view:
<ul class="pagination">
<?php echo with(new CustomPresenter($paginator))->render(); ?>
</ul>
For prev and next use this JavaScript (I've used jQuery) and include this in you template:
<script>
$(function(){
$('ul.my-custom-pagination>li:first').attr('id', 'prev')
$('ul.my-custom-pagination>li:last').attr('id', 'next')
});
</script>
Above JS code will set the id=prev and id=next, otherwise there will be duplicate ids for first two lis and last two lis. At last, run composer dump from terminal. This an output of this implementation:
<ul class="pagination my-custom-pagination">
<li id="prev">«</li>
<li id="page[1]">1</li>
<li id="page[2]">2</li>
<li id="page[3]" class="active">
3</li><li class="disabled" id="next">»
</li>
</ul>
Read more on the manual.

Categories