laravel show only next and previous link in pagination - php

I ma trying to use Laravel Pagination and I only want to show the Previous and Next link with out the number 1 2 3 ...
how could I do that? I followed Laravel page :
"Simple Pagination"
If you are only showing "Next" and "Previous" links in your pagination view, you have the option of using the simplePaginate method to perform a more efficient query. This is useful for larger datasets when you do not require the display of exact page numbers on your view:
$someUsers = User::where('votes', '>', 100)->simplePaginate(15);
but this still shows the page number when I do this in my view:
<?php echo $someUsers->links(); ?>
can anyone help
Thanks

tldr; you want to use simplePaginate() method on the query AND links('some.view') on the paginator (in the view) in order to achieve what you ask for.
Here's what you need in order to show chosen links in given template:
// inline choose simple links (prev, next)
{{ $someUsers->links('pagination::simple') }}
// inline choose slider links
{{ $someUsers->links('pagination::slider') }}
// inline choose slider-3 (default)
{{ $someUsers->links('pagination::slider-3') }}
These are framework's templates, placed in laravels directory: Illuminate/Pagination/views/
You can always decide to use your custom templates, for this simply call:
// assuming you have it in app/views/pagination/my-links.blade.php
{{ $someUsers->links('pagination.my-links') }}
// or using views namespace (you need to define it first)
{{ $someUsers->links('myNamespace::my-links') }}
Of course you can define your links as default in app/config/view.php:
// instead of
'pagination' => 'pagination::slider-3',
// something like
'pagination' => 'pagination.my-links',

You need to use:
$someUsers = User::where('votes', '>', 100)->simplePaginate(15);
as you used
and in app/config/view.php you need to set pagination to pagination::simple (by default it's set to pagination::slider-3). Then you'll have by default pagination as in the image:
You can also set custom text for previous and next items editing file lang/en/pagination.php (for other language of course you need to change it in other lang directory). By default it's set to:
'previous' => '« Previous',
'next' => 'Next »',
but you can change it to:
'previous' => '«',
'next' => '»',
and then it will look like as in the image:

I tried this and it's working with me :
{{$someUsers->links('pagination::bootstrap-4')}}

In config/view.php:
/*
|--------------------------------------------------------------------------
| Pagination View
|--------------------------------------------------------------------------
|
| This view will be used to render the pagination link output, and can
| be easily customized here to show any view you like. A clean view
| compatible with Twitter's Bootstrap is given to you by default.
|
*/
'pagination' => 'pagination::slider-3',
Set this to simple.
Source: http://youtu.be/lIEcyOUcNQk?t=8m00s

See the very bottom of this manual page to see how to implement a custom view for the pagination. Summarizing, you need to follow these steps:
Create a view for the paginator somewhere in app/views.
Replace the pagination option in app/config/views.php with the path Laravel will use to locate your new view.
Display your custom paginatation view in your view like this:
<?php echo with(new ZurbPresenter($paginator))->render(); ?>
Where ZurbPresenter is the class name of your pagination presenter.

Related

Dynamically grab latest post OctoberCMS Blog plugin

I asked this question in the October forums but 12 hours later the post still says "unapproved" and I don't believe it's visible. Here's a copy-paste:
What I want to do is grab the latest blog post and display it on the homepage of the website. I can do it currently with my own post partial and the posts variable injected by the blogPosts component like so:
[blogPosts]
pageNumber = "{{ :page }}"
postsPerPage = 10
noPostsMessage = "No posts found"
sortOrder = "published_at desc"
categoryPage = "blog/category"
postPage = "blog/post"
==
{% partial 'site/blogpost' post=posts|last %}
However, I'd like to do this with the default blogpost component that comes with the plugin, but the only way to pass the post to the component seems to be by using the slug in the url, which doesn't really work for the homepage. How can I achieve this?
It is possible to use blogPost component but fetching last post slug and pass to it seems not good practice
what you do is you can use [blogPosts] component and set proper setting there to get latest/last blog
to make it possible
Posts per page : 1 [ as we need only last latest post ]
Post Order : Published(desc) [ you can change as you need ]
now just use proper markup to render it use default or just override to customise it.
Note : It will return list of post but in list there will be only 1 post as demanded so for custom markup just take care of that.
if any doubt please comment.
So, as with most things when it comes to development... RTFM.
All the info I needed was in the Components section of the October CMS docs, and of course I was only looking in the plugin docs. What I ended up doing was overriding the default component partial with my own and then passing the slug to the component. My original reason for wanting to use the default partial was that my custom partial wasn't rendering images, but the default would. I just needed to steal the line <p>{{ post.content_html|raw }}</p> to get that to work.
[blogPost]
==
...
{% component 'blogPost' slug=posts|last.slug %}
Additional info: With the above solution your template pulls all blog posts in the database, which means if you have a lot of posts this could (and most likely will) affect performance. Turns out October templates have a PHP section. The proper thing to do is to remove the blogPosts component and grab the latest post Model like so:
[blogPost]
==
<?
use RainLab\Blog\Models\Post;
function onStart()
{
$this['latestPost'] = Post::latest()->first();
}
?>
==
{% component 'blogPost' slug=latestPost.slug %}
Note: The blogPost component injects a post variable which will override a post variable defined in the PHP section. This is way the variable is labeled latestPost.

add links for blade php pages

I have developed several pages for my applications. Now I need to add link for these pages. Till now I was opening these pages via url browsing.
My web.php page
// for books
Route::get('/book','BookController#create');
Route::post('/book','BookController#store');
Route::get('/book/{id}','BookController#edit');
Route::patch('/book/{id}', 'BookController#update');
// for ordered books
Route::get('/order','OrderedBookController#create');
Route::post('/order','OrderedBookController#store');
Route::get('/billSearch','OrderedBookController#searchBill');
Route::post('/billSearch','OrderedBookController#billPay');
Route::post('/billSearch/{id}', 'OrderedBookController#pay');
// for Books Out
Route::get('/booksout','BooksOutController#create');
Route::post('/booksout','BooksOutController#store');
List of pages corresponding to the routes
book.blade.php
edit.blade.php
booksin.blade.php
booksout.blade.php
local host url to browse these pages are ::
http://127.0.0.1:8000/book
http://127.0.0.1:8000/order
http://127.0.0.1:8000/billSearch // for Route::get('/billSearch','OrderedBookController#searchBill');
http://127.0.0.1:8000/booksout
How can I create link in my web apps since I am browsing my pages via routes, not by pages ?
Use route() or url() functions.
e.g. in blade view:
More in laravel docs
You may links different pages in laravel by using one of the two ways
1: By including url which you define in your route in the blade href
Route::post('/billSearch', 'OrderedBookController#pay');
therefore in your blade link
2:By using the name of the route
Route::post('/billSearch', 'OrderedBookController#pay')->name('bill);
Therefore in your blade view
just insert your routes like this:
Book --> http://127.0.0.1:8000/book
Bill Search --> http://127.0.0.1:8000/billSearch

In Laravel, should I make different view files or add switch case in view file?

I have to show list of posts in a view. Functions in controller query posts and send them to view. Functions like drafts(), pending(), published() etc will query posts for related status.
All view layout would almost be same other than page title and buttons that appear alongside each post.
So my confusion is, should I make individual view file like drafts.blade.php, pending.blade.php, published.blade.php, etc and have logic less static buttons & page title
OR
instead use one single view like posts-list.blade.php and use switch case or something to bring up buttons and title based on status of the post.
Thank you,
=======
UPDATE
I added a serviceprovider to extend blade functionality. Now I can use #switch($var), #case(1), #break etc in view.
actually there's nothing completely true or wrong. in case like yours I'd ask myself about how different is these required views if there's alot of differences I'll separate them and if No I'll just make one view with parameters to bass. like:
posts-list.blade.php
<h1>{{ $title }}</h1>
#if( $pageType == 'draft' )
// show button1
#elseif( $pageType == 'pending')
// show button2
#elseif( $pageType == 'published')
// show button3
#else
// default
#endif
and in calling it I'll just use return view('posts-list.blade.php', ['title ' => 'Awesome page', 'pageType' => 'pending']);
again it depends on how complex the differences are.

How to get the title of a page in Laravel

I set my title of the page like this in the blade view template:
#section('title', 'Example.com - Welcome to Example.com for all your needs')
This is working well. Now I want to know how can I access/print the current page title in the body part?
I mean for getting the current URL, we can use Request::url(). Is there a way that I can get the current page title?
I don't know of a way to do this in Laravel, but this is easily accomplished in Javascript/JQuery:
$(document).ready(function(){
console.log($("title").text());
});
Will print the title of the current page to the console. You can assign this value to an element by targeting it's id $("#id_of_element") or class $(".class_of_elemnt") and setting the text to the title's text:
$("#id_of_element").text($("title").text());
Hope that helps!
I think it's not a good idea to set the page title with hard code in layout file.
one of the best ways is to have a default page title in layout and override it in every view page.
just like below :
layout title :: {{ isset($title) ? $title : 'page title' }}
You can print your page title using
#yield('title)
wherever you want.

Generic Pagination in ZF2

EDIT My question is how to make pagination on View generic, currently what i have to do is some what like this on every page where i need pagination variables set
<?php echo ( count($this->paginator) > 0 ) ? $this->paginationControl($this->paginator, 'Sliding', 'administration/pager.phtml', array('url' => $this->url('company'))) : ""; ?>
Dear which you want to do is clearly mentioned in zf2 documentation:
http://framework.zend.com/manual/2.1/en/tutorials/tutorial.pagination.html
"Let’s create the partail in the module/Application/view/partial/ folder, so that we can use the control in all our modules:"
Above mention line shows that if we want to make pagination generic which will be available for all module, then make it partial in Application module.

Categories