pagination in laravel freamwork - php

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

Related

Dynamic nav laravel 5.3

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

Laravel how to prevent href link gets appended with current url

Let's say my project root is http://localhost/laravel-project
In the project I have navigation menu, the sample format of the link is
home"
So when I click the link the url on my browser is http://localhost/laravel-project/home
I do not know why if I have another link
home" and the route is Route::get('/invoice/show/{id}', 'Frontend\CommonController#show');
when I click the link, the previous home link will become
http://localhost/laravel-project/invoice/show/member it's supposed to be http://localhost/laravel-project/home.
The inside show method :
public function show(){
return view('frontend.invoice', ['subaccounts' => $this->subaccounts, 'menus' => $this->menus]);
}
I have tested it, the cause of the problem is the segments on the link invoice/show/1 if the link is only invoice then everything is fine.
Anyone knows what is wrong and how to solve this issue ?
Note : I am using a blade template
I managed to solve the problem by using the function {{url('linkName')}} in the link.

How to call one controller(function) view with multiple url in codeigniter via routes.

I create a controller function home/index .
calling vai url it is showing me html design.
I want to call the view of home/index via custom urls.
If I type
www.example.com/home_new // it will open view of home/index
www.example.com/home_new1 // it will open view of home/index
Also i want to save the custum urls in database so that admin can change.
Please advise how to do this via routes or another method.
Add this code to inside route.php file:
$route['home_new'] = 'home/index';
$route['home_new1'] = 'home/index';
This will solve your problem. For database it will not help you.
You can take reference from this link.

L5 Pagination keeping current url variables when changing pages

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

joomla template on view=category

I make my own template , and its work well on www.90km2.com/index.php
But when I want to see com_content&view=category page on this link : http://www.90km2.com/index.php?option=com_content&view=category&id=23&Itemid=102
It doesn't work. Do you know why joomla didn't show my view?
I try another templates to see this page , all of them was worked well , but this view is not work with my own teplate :(
I would try copying the template which works then modify bit by bit to get your custom template then see when problem shows up. Or create a template which has the minimum stuff in there and see if it works. Just have jdoc:include type="component"/> in the body

Categories