I have an admin layout
I have a master layout contain my :
Each page is a view, I extend the master layout view, and update only the content section.
My goal is to refresh only a content page without refreshing master page.
Is there any laravel package for something like this ?
Short answer: use AJAX. There no real need to learn a JavaScript framework if it's that simple (unless you really want to). The below example uses jQuery and assumes you're clicking on the Users link in the navigation (all links there should have a nav-item
class so they can be easily identified via that selector) and the link has the attribute href="/admin/users"
. When clicked it loads the contents in the element with the class content
:
$('.item-nav').click(function (event) {
// Avoid the link click from loading a new page
event.preventDefault();
// Load the content from the link's href attribute
$('.content').load($(this).attr('href'));
});
If the route admin/users
would return the users table with it's contents:
get('admin/users', function () {
return view('users')->with('users', Users::all());
});
The above Laravel route example is of course simplified to showcase the idea that each item in your navigation should link to the contents that need to be displayed dynamically.
You can use renderSections().
In your main controller action ( say AdminUsersController@getIndex ) you can render a particular section of your view depending on the request. This way if you do an ajax request to the same page you are on you can return only the section you require.
if($request->ajax()) {
return view('admin.users',$users)->renderSections()['content'];
}
return view('admin.users',$users);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With