So I am trying to paginate a set of results in Laravel 5.
$listings = $query->paginate(16);
Then on my view I'm using this to display the pagination links.
{!! $listings>appends(Request::except('page'))->render() !!}
I want to retain all the GET variables in the URL when changing pages.
When I try to load a page I get this error:
Call to undefined function appends()
I know pagination has been modified in L5 but can't seem to find out how to get it to work.
I don't see the logic for changing pagination from how it was in L4 but that's another story.
Any help would be appreciated!
Thanks!
You are missing the "-" in your method call $listings->appends
Related
I would like to create a pagination in Prestashop 1.7
I have a function with an array, which I assign to a .tpl template
$brands = $this->getBrands();
$this->context->smarty->assign($brands);
parent::initContent();
$this->setTemplate('brandschr.tpl');
I have not found much information how to use pagination.tpl or an example how to do it.
Please send me your idea if you have done it before or any example for me.
I would advice you to assign smarty variably only to the pages where it is needed. So let's say you want to add brands to your custom pagination you only assign this on the pages that actually contain a brand.
$brands = $this->getBrands();
$this->context->smarty->assign($customPagination);
And then create an override in the theme at /templates/_partials/pagination.tpl.
In this file just check if your "customPagination" isset and then display your custom-pagination.tpl (brandschr.tpl)
This will keep the original PS pagination intact.
I have a About Us portion in my Laravel website home page. I have uploaded a huge article for About Us from admin panel which is shown in about us page. But I want to show a specific number of word for about us in home page and add read more after that. while click on read more it goes to about us page.
But I can't show specific number of words from that article in my home page.
I have use echo word_teaser_end($about_us[0]->details, 10); function but it gives error
Call to undefined function word_teaser_end() (View: E:\xampp\htdocs\OFFICE\SEN_CARE\sencare.com.bd\resources\views\frontend\home\home.blade.php)
What should I do now ?
I don't know about the word_teaser_end() as it's define function,
Try str_limit() helper function which can help you to load the number of words from string
{{ str_limit($string,'10') }}
https://laravel.com/docs/5.6/helpers#method-str-limit
This should help.
{!! str_limit($string,'10') !!}
I'm building a navigation similar to wordpress basically what I want to do is add the navigation dynamically. my code in the header.blade.php looks something like:
#foreach($nav as $navs)
<li><a>$navs->title</a></li>
#endforeach
I will like the links to display in all my pages but I'm not sure how to set this in the route. Please any suggestion would be really helpful.
I'm still new to Laravel.
Sorry for not explaining properly, what I actually want is:
Once I add the navigation links and the details, it should display something like this
localhost/about-us
localhost/contact-us
So far I have got all the details and slug in the db.
e.g Controller to get all pages
class NavController extends Controller
{
public function nav()
{
$navs=Page::all();
return view('themes.first.header')->withNavs($navs);
}
}
e.g header.blade looks something like this
#foreach($navs as $nav)
<li>$nav->title</a></li>
#endforeach
The header is included on every page in master.blade so my issue is
for example I go localhost/blog
The links doesn't display but if I add route like this
Route::get('nav','NavController#nav');
Then go to /nav then it works fine. but I want something like this
localhost/about-us
and also for the links to display on every page. I hopefully I have explained properly now if not just let me know.
Please ignore suggesting code for the href="" because I've already done all that bit in my other pages etc so I know how to handle the code for the href, the part that I'm having issues is just with the navigation links not showing on all the pages.
Finally got the navigation working by using the suggestion from this thread
Proper way to make a dynamic navigation in Laravel 5
The blade syntax is wrong.
#foreach($nav as $navs)
<li><a>{{$navs->title}}</a></li>
#endforeach
Btw it's more likely that you wanted $navs as $nav and $nav->title.
If you have any problem with the routing part, share your code. Unless, I can only help with this.
In your route (example)
Route::get('page/{title}', 'PageController#details');
In PageController
public function details($title)
{
$page = Page::where('title', $title)->firstOrFail();
return view('your.page')->with(['page' => $page]);
}
In header.blade.php
#foreach($navs as $nav)
<li>{{ $nav->title }}</li>
#endforeach
Hi I use paginate() method for pagination it work fine, but a tag in blade file have problem my link like this:
http://localhost/blog/admin/news/?page=2
and when i click on them i'm redirect :
http://localhost/admin/news?page=2
and get 404 error and when click link like this:
http://localhost/blog/admin/news?page=2
it's work fine. what the problem ?
Why when use http://localhost/blog/admin/news/?page=2
redirect me an other page?
thanks.
I had the same problem. You can use the setPath() method to choose the right path. You can see the usage of that method here http://laravel.com/docs/5.1/pagination#displaying-results-in-a-view
I'm using the CodeIgniter pagination library for building my page's links.
I defined a config array variable for my pagination as follows:
$config['use_page_numbers'] = true;
All of my URLs look like http://domain.com/class/function/# (where # is the page number I'm on). However, the first page looks like http://domain.com/class/function and is missing the first page (#1).
Is there a build-in way in CodeIgniter of showing the first page if no page number is in the URL?
Yeah use a route. In your config/routes.php file add this:
$route['class/function'] = 'class/function/1';
This way if the page number is missing it will assume the number 1 is in the URL, so it will show page #1