I am trying to get a side menu from db using user permission. I successfully get the data but if it is empty i would like to delete the dropmenu:
#foreach ($t as $key=>$item)
#if($ci)
<li class="dropdown">
<a href="javascript:;" class="dropdown-toggle">
<span class="fa fa-dashboard"></span><span class="mtext">{{$item->designation}}</span>
</a>
#foreach ($item->links as $link)
#foreach($link->profil as $p)
#if(Auth::user()->name == $p->login)
#php $ci = 1; #endphp
<ul class="submenu">
<li>
{{$link->titre}}
</li>
</ul>
#else
#php $ci = 0; #endphp
#endif
#endforeach
#endforeach
</li>
#endif
#endforeach
details :
the variable item get all main dropmenus
the variable link get all link for each dropmenu
the variable p for checking permission
Please could help me to fix this issue which is delete the empty dropmenu where if statement condition not applied
I think your mean is :
#foreach ($t as $key=>$item)
#if($ci)
<li class="dropdown">
<a href="javascript:;" class="dropdown-toggle">
<span class="fa fa-dashboard"></span><span class="mtext">{{$item->designation}}
</span>
</a>
#foreach ($item->links as $link)
#if($item->links->count())
#foreach($link->profil as $p)
#if(Auth::user()->name == $p->login)
#php $ci = 1; #endphp
<ul class="submenu">
<li>
<a href="{{asset('/')}}{{$link->url}}">{{$link->titre}}
</a>
</li>
</ul>
#else
#php $ci = 0; #endphp
#endif
#endforeach
#endif
#endforeach
</li>
#endif
#endforeach
add a #if($links->count() for if count of links bigger of zero continue process
Related
Guys
I'm using Laravel's default pagination with bootstrap as its styling framework.
I want to direct my page to certain html section after I click the pagination link, so far I only know how to paginate like the following codes:
Controller:
$data = Products::paginate(9);
return view('index', ['data' => $data]);
Blade:
{{ $data->links() }}
So, I want to direct my page to a certain section in html everytime I clicked the pagination link button. how can I achieve that?
I'm sorry for my poor explanation, hit me up if you need more detail.
Thank You
you should make a blade file like this:
pagination.blade.php
#if ($paginator->hasPages())
<ul class="pagination justify-content-center">
#if ($paginator->onFirstPage())
<li class="paginate_button page-item previous disabled">
قبلی
</li>
#else
<li class="paginate_button page-item previous">
pre
</li>
#endif
#foreach ($elements as $element)
#if (is_string($element))
<li class="paginate_button page-item active">
<a href="javascript:void(0)" class="page-link" >{{ $element }}</a>
</li>
#endif
#if (is_array($element))
#foreach ($element as $page => $url)
#if ($page == $paginator->currentPage())
<li class="paginate_button page-item active">{{ $page }}</li>
#else
<li class="paginate_button page-item ">{{ $page }}</li>
#endif
#endforeach
#endif
#endforeach
{{-- next page --}}
#if ($paginator->hasMorePages())
<li class="paginate_button page-item next ">
next
</li>
#else
<li class="paginate_button page-item next disabled">
بعدی
</li>
#endif
</ul>
#endif
then create a blade file like this:
table.blade.php
#if(isset($permissions))
#php
$paginator=$permissions;
#endphp
<table class="table table-striped">
<thead>
<tr>
heaers tags
</tr>
</thead>
<tbody id="table-data">
#foreach ($permissions as $permission)
tr tags
#endforeach
</tbody>
</table>
#endif
<div class="col-md-12">
{{ $paginator->links('sections.pagination') }}
</div>
then in controller method:
public function index(Request $request)
{
$permissions=Permission::paginate(5);
if($request->ajax()){
return view('sections.table',compact('permissions'));
}
return view('permission.index',compact('permissions'));
}
I ran the command to generate the customization files for my blog's pagination.
I was able to customize the appearance of the buttons but the issue I now have is that when the page number gets to say 8, the pagination link shows up to 8 links. I would like to implement the '...' separator within the link. My bootstrap-4.blade.php is as follows
<div class="row">
<div class="col-12">
<ul class="pagination justify-content-center">
{{-- Previous Page Link --}}
#if ($paginator->onFirstPage())
<li>
<a aria-label="Next">
<i class="fas fa-arrow-left"></i>
</a>
</li>
#else
<li class="px-1">
<span><i class="fas fa-arrow-left"></i></span>
</li>
#endif
{{-- Pagination Elements --}}
#foreach ($elements as $element)
{{-- "Three Dots" Separator --}}
#if ($paginator->currentPage() > 4 && $page === 2)
<li class="px-1"><span class="page-link">...</span></li>
#endif
{{-- Array Of Links --}}
#if (is_array($element))
#foreach ($element as $page => $url)
#if ($page == $paginator->currentPage())
<li class="px-1"><a style="background:#56107c; color:white; cursor:not-allowed;" href="{{ $url }}">{{ $page }}</a></li>
#else
<li class="px-1">{{ $page }}</li>
#endif
#endforeach
#endif
#endforeach
{{-- Next Page Link --}}
#if ($paginator->hasMorePages())
<li class="px-1">
<span><i class="fas fa-arrow-right"></i></span>
</li>
#else
<li>
<a aria-label="Next">
<i class="fas fa-arrow-right"></i>
</a>
</li>
#endif
</ul>
</div>
</div>
#endif
You can use a built in function $posts->links(), it will auto create everything - links, numbers and next.
Controller:
public function shopfront(){
$products=Product::all();
$categories=Category::all();
return view('shop.index',compact('products','categories'));
}
index.blade.php:
<div class="sidebar-widget">
<h4 class="pro-sidebar-title">Categories</h4>
<div class="sidebar-widget-list mt-30">
<ul>
#foreach ($categories as $category)
#foreach ($products as $product)
#if ($category->id==$product->category->id)
<li>
<div class="sidebar-widget-list-left">
<input type="checkbox"> <a href="">{{ $category->name }}
{{-- <span>4</span> --}}
</a>
<span class="checkmark"></span>
</div>
</li>
#endif
#endforeach
#endforeach
</ul>
</div>
</div>
I do not know how to achieve this, will highly appreciate some help or i sample that i can work with
Image
i don't know how you want to achieve it but let me give you an idea if you want it in this way:
when click on a category then it should show all products of that category:
in your blade file
#foreach($categories as $category)
<li class="nav-item">
<a class="nav-link" href="{{route('category.products',$category->name)}}"> {{$category->name}}</a>
</li>
#endforeach
you should create a route named category.products as below in web.php
Route::get('category/{name}','YourController#yourmethod')->name('category.products');
controller
public function CategoryProducts($name){
$category = Category::where('name',$name)->first();
$products = $category->products;
return view('front-end.categoryWise-products',compact('products'));
}
you can customize it according to your requirements.
i have a question. How can i return view with variable who is null if there is no record in DB.
i know return $variable ?? null;
but i need this in a view.
public function shop_items($shelf)
{
$shop_shelf = $this->getTreeItems(0);
$shop_items = DB::table("shop_items")->where('shelf_id', $shelf)->get();
return view('shop',compact('shop_items','shop_shelf'));
}
if there is record i get the valeu of $shop_items but if there is no such record got Undefined offset: 0
edite:
add shop.blade
#if(isset($shop_shelf))
#foreach($shop_shelf as $ss)
<ul>
<li>{{$ss["title"]}}
#if(is_array($ss["children"]))
<ul>
#foreach($ss["children"] as $sc)
<li>
<a href="/shop/shelf/{{$sc["id"]}}">
{{$sc["title"]}}
</a>
</li>
#endforeach
</ul>
#endif
</li>
</ul>
#endforeach
enter image description here
could not post all code so i put an image of shop.blade
You may use
#forelse($shop_shelf as $ss)
<ul>
<li>{{$ss["title"]}}
#if(is_array($ss["children"]))
<ul>
#foreach($ss["children"] as $sc)
<li>
<a href="/shop/shelf/{{$sc["id"]}}">
{{$sc["title"]}}
</a>
</li>
#endforeach
</ul>
#endif
</li>
</ul>
#empty
<p>No data to display</p>
#endforelse
PS : apply the #forelse loop structure wherever you have an array in
your blade
See docs
I have a dynamic menu and sub menu in my website and want to make not clickable menu to only those menu that have sub menu.
here is code
#foreach($levels as $category)
<li class="text-black-50">
<a href="/category/{{ $category->slug }}" title="">
{{ $category->name }}
</a>
</li>
#if($category->children->count() > 0 )
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
#foreach($category->children as $child)
<li>
{{ $child->name }}
</li>
#endforeach
</ul>
</li>
#else
#endif
#endforeach
I quick solution over your code is don't use href att when the menu has a submenu. Using your code:
#foreach($levels as $category)
<li class="text-black-50">
#if($category->children->count() > 0 )
<a href="/category/{{ $category->slug }}" title="">
{{ $category->name }}
</a>
#else
<a style="pointer-events: none; cursor: default;">
{{ $category->name }}
</a>
#endif
</li>
#if($category->children->count() > 0 )
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
#foreach($category->children as $child)
<li>
{{ $child->name }}
</li>
#endforeach
</ul>
</li>
#else
#endif
#endforeach
I hope It's helps!