Different paginations in different tabs directs to the same tab - laravel

Sorry for this noob question.
I have:
• different tabs in one webpage and
• each tab has a pagination
The problem is that when clicking a page in different pagination it would:
• lead to the same tab
Like i clicked page 2 in tab_2 pagination and I get redirected to tab_1 page 1
In my InventoryController:
public function index() {
return view('employee.inventory', [
'ingredients' => Ingredient::with('supplier')->paginate(10),
'products' => $products = Product::paginate(10, ['*'], 'products_page'),
'orders' => Order::paginate(10, ['*'], 'orders_page'),
'users' => User::paginate(10, ['*'], 'users_page'),
'suppliers' => Supplier::paginate(10, ['*'], 'suppliers_page')
]);
}
What should I do? I thought making each page in paginations behave like anchor tag that will jump to an id but I'm using {!! $object->links() !!} but I don't know how to implement it.
<div class="col-md-6">
<!-- Custom Tabs -->
<div class="nav-tabs-custom">
<ul class="nav nav-tabs table-tabs" style="display: flex; flex-directed: row-reverse;">
<li class="active"><a href="#tab_1" data-toggle="tab" aria-expanded="true">
<button style="background-color: #C6B877; width:100px; color: white;" type="button" class="btn btn-default">
Ingredients
</button>
</a></li>
<li class=""><a href="#tab_2" data-toggle="tab" aria-expanded="false">
<button style="background-color: #C6B877; width:100px; color: white;" type="button" class="btn btn-default">
Products
</button>
</a>
</li>
<li class=""><a href="#tab_3" data-toggle="tab" aria-expanded="false">
<button style="background-color: #C6B877; width:100px; color: white;" type="button" class="btn btn-default">
Orders
</button>
</a></li>
<li class=""><a href="#tab_4" data-toggle="tab" aria-expanded="true">
<button style="background-color: #C6B877; width:100px; color: white;" type="button" class="btn btn-default">
Users
</button>
</a></li>
<li class=""><a href="#tab_5" data-toggle="tab" aria-expanded="true">
<button style="background-color: #C6B877; width:100px; color: white;" type="button" class="btn btn-default">
Suppliers
</button>
</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab_1">
<div class="card" style="width: 87.5em; height: 45em;">
<div class="card-header">
<h3 class="card-title">Ingredients</h3>
<div class="table-add-delete" style="float: right;">
<i class="fas fa-plus-square" data-toggle="modal" data-target="#modal-default-1" style="cursor:pointer ;color: #2AC0CC; font-size: 24px;"></i>
<i class="fas fa-trash-alt" data-toggle="modal" data-target="#modal-default-1" style="cursor: pointer; color: #2AC0CC; font-size: 24px;"></i>
</div>
</div>
<!-- /.card-header -->
<div class="card-body">
<div id="example2_wrapper" class="dataTables_wrapper dt-bootstrap4"><div class="row"><div class="col-sm-12 col-md-6"></div><div class="col-sm-12 col-md-6"></div></div><div class="row"><div class="col-sm-12">
<table id="table1" class="table table-bordered table-hover dataTable dtr-inline" role="grid" aria-describedby="example2_info">
<thead>
<tr role="row">
<th><input type="checkbox" name="checkAll" id=""></th>
<th>ID</th>
<th>NAME</th>
<th>QUANTITY IN STOCK</th>
<th>SUPPLIER</th>
<th>COST</th>
</tr>
</thead>
<tbody>
#foreach ($ingredients as $ingredient)
<tr>
<td><input type="checkbox" name="" id=""></td>
<td>{{$ingredient->ingredient_id}}</td>
<td>{{$ingredient->name}}</td>
<td>{{$ingredient->stock_Quantity}}</td>
<td>{{$ingredient->supplier->name ?? '--unset--'}}</td>
<td>{{$ingredient->cost}}</td>
</tr>
#endforeach
</tbody>
</table></div></div>
<div class="row"><div class="col-sm-12 col-md-5">
</div>
<div class="col-sm-12 col-md-7">
{!! $ingredients->links() !!}
</div>
</div>
</div>
</div>
<!-- /.card-body -->
</div>
<div class="tab-pane" id="tab_2">
<div class="card" style="width: 87.5em; height: 45em;">
<div class="card-header">
<h3 class="card-title">Products</h3>
<div class="table-add-delete" style="float: right;">
<i class="fas fa-plus-square" data-toggle="modal" data-target="#modal-default-2" style="cursor:pointer ;color: #2AC0CC; font-size: 24px;"></i>
<i class="fas fa-trash-alt" data-toggle="modal" data-target="#modal-default-2" style="cursor: pointer; color: #2AC0CC; font-size: 24px;"></i>
</div>
</div>
<!-- /.card-header -->
<div class="card-body">
<div id="example2_wrapper" class="dataTables_wrapper dt-bootstrap4">
<div class="row">
<div class="col-sm-12 col-md-6"></div>
<div class="col-sm-12 col-md-6"></div>
</div>
<div class="row">
<div class="col-sm-12">
<table id="table2" class="table table-bordered table-hover dataTable dtr-inline" role="grid" aria-describedby="example2_info">
<thead>
<tr role="row">
<th class="sorting" tabindex="0" aria-controls="example2" rowspan="1" colspan="1" ><input type="checkbox" name="AllProducts" id=""></th>
<th class="sorting_asc" tabindex="0" aria-controls="example2" rowspan="1" colspan="1" aria-sort="ascending">ID</th>
<th class="sorting" tabindex="0" aria-controls="example2" rowspan="1" colspan="1" >NAME</th>
<th class="sorting" tabindex="0" aria-controls="example2" rowspan="1" colspan="1" >DESCRIPTION</th>
<th class="sorting" tabindex="0" aria-controls="example2" rowspan="1" colspan="1" >QUANTITY</th>
<th class="sorting" tabindex="0" aria-controls="example2" rowspan="1" colspan="1" >IMAGE</th>
<th class="sorting" tabindex="0" aria-controls="example2" rowspan="1" colspan="1" >PRICE</th>
<th class="sorting" tabindex="0" aria-controls="example2" rowspan="1" colspan="1" >CATEGORY(s)</th>
</tr>
</thead>
<tbody>
#foreach ($products as $product)
<tr role="row" class="odd">
<td><input type="checkbox" name="" id=""></td>
<td tabindex="0" class="sorting_1">{{$product->product_id}}</td>
<td>{{$product->name}}</td>
<td>{{$product->description}}</td>
<td>{{$product->stock_Quantity}}</td>
<td><img style="height: 100px; width: 150px;" src="{{ asset('storage/' . $product->image) }}" alt="{{ 'storage/' . $product->image }}"></td>
<td>{{$product->price}}</td>
<td>#</td>
#endforeach
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-sm-12 col-md-5">
</div>
<div class="col-sm-12 col-md-7" >
{!! $products->links() !!}
</div>
</div>
</div>
</div>
<!-- /.card-body -->
</div>

Laravel pagination works on the basis of page number parameter in the url. For example, if I have a customers crud and I am on page two of crud the URL will be like:
http://localhost:8080/customers?page=2
So, if you are having two cruds on one page they will not work simultaneously. You should use any client side jquery pagination plugin in order to tackle this problem. Try this plugin:
jquery pagination plugin

Related

Add user email addresses separated by commas in Laravel

I want to add the selected users to a separate table from the list of all users. Similar to the Trello feature, just # and tag their name. I have no idea what to write this function. Any ideas?
This is the form on my interface, and I do not know what to do next in the controller and the form block.
<div class="tab-pane fade" id="group-add-members" role="tabpanel">
<div class="users-manage" data-filter-list="form-group-users">
<div class="mb-3">
<div class="form-group row">
<textarea class="form-control col" name="group-description"
placeholder="Add users by email, each email separated by
commas
e.g: matt#.edu.com, joe#edu.com" rows="3">
</textarea>
</div>
<div class="row align-items-center">
<div class="col">
<button class="btn btn-outline-primary" type="button">
<i class="fad fa-user-plus"></i>Add</button>
<span>   or   </span>
</div>
<div class="d-none d-md-block col-4 col-lg-5 text-right">
</div>
</div>
<div class="row align-items-center mt-2">
<div class="d-block d-md-none d-sm-block ml-2">
</div>
</div>
</div>
<hr>
<h6>Member info</h6>
<div class="row justify-content-center">
<div class="table-responsive mt-3">
<table class="stripe" id="example" style="width:100%">
<thead>
<tr>
<th></th>
<th class="text-left">Full name</th>
<th class="text-left">Email</th>
<th class="text-left">Student ID</th>\
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td class="text-left">My name</td>
<td class="text-left">qnv164#edu.com</td>
<td class="text-left">123456789</td>
<td>
<span class="ic-dark"><i class="fad fa-trash-alt"></i></span>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<th></th>
<th class="text-left">Full name</th>
<th class="text-left">Email</th>
<th class="text-left">Student ID</th>
<th>Action</th>
</tr>
</tfoot>
</table>
</div>
<!-- end div table responsive -->
</div>
<!-- end div row -->
</div>
</div>
{{ profile->description ?? 'Not Available' }}

datatable shows blank spaces below the paginator links

I'm using larashop admin panel.The datatable shows blank spaces below the datatable..The height blank spaces increases with increase in datatable entries.I don't know what to do..
I tried some css.but none of them helped me.
#extends('templates.admin.layout')
#section('title', 'All Courses')
#section('content')
<div class="">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Courses <i class="fa fa-plus"></i> Create New </h2>
<div class="clearfix"></div>
</div>
<div class="x_content">
<table id="datatable-buttons" class="table table-responsive">
<thead>
<tr>
<th>Course Name</th>
<th>Action</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Course Name</th>
<th>Action</th>
</tr>
</tfoot>
<tbody>
#if(count($courses))
#foreach ($courses as $row)
<tr>
<td>{{$row->name}}</td>
<td>
<i class="fa fa-pencil" title="Edit"></i>
<i class="fa fa-trash-o" title="Delete"></i>
</td>
</tr>
#endforeach
#endif
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
#stop
The screenshot of the issue is provided..please check...
https://i.stack.imgur.com/avqf5.png

Form Input Bindings v-model not rendering in a views page in laravel

I have question on it for the vue.js I already have a library vue.js in my web application site. Now my problem is when i try to use the Form Input Bindings the v-model this line of code here below
<input v-model="message" placeholder="edit me">
<p>Message is: {{ message }}</p>
what i notice is it says
Use of undefined constant test - assumed 'test'
So i try to see the solution on this one by adding a # beacuase laravel is using blade template. Now when i add a # the error is gone but the render goes this way {{ test }} . Why does it not rendered correctly in my browser?. Can someone help me figured this thing out?. Any help is muchly appreciated. TIA.
Here is my code
#extends('layouts.app')
#section('title', 'Cases New Invoice | RMTG')
#section('content')
<div id="content-wrapper">
<div class="container-fluid">
<!-- Breadcrumbs-->
<ol class="breadcrumb">
<li class="breadcrumb-item">
Dashboard
</li>
<li class="breadcrumb-item active">Cases New Invoice</li>
</ol>
<div class="row">
<div class="col-lg-12">
<div class="card mb-3">
<div class="card-header">
<i class="fa fa-file"></i>
New Invoice</div>
<div class="card-body">
<div class="form-group">
<div class="form-row">
<div class="col-md-6" >
<div class="table-responsive">
<form action="" method="post">
{{ csrf_field() }}
<table class="table table-bordered" width="100%" cellspacing="0">
<thead>
<tr>
<th width="150px;">Contact Name: </th>
<td>{{ $opp->contacts }}</td>
</tr>
<tr>
<th>Case Number:</th>
<td>OPP -{{ $opp->code }}</td>
</tr>
<tr>
<th>Case Name:</th>
<td>{{ $opp->tax_year }}</td>
</tr>
<tr>
<th>Item Code:</th>
<td>
<div id="app-item">
<select name="itemCode" class="form-control">
<option v-for="item in items" v-bind:value="item.value">
#{{ item.text }}
</option>
</select>
</div>
</td>
</tr>
<tr>
<th>Notes: </th>
<td>
<input type="text" name="notes" class="form-control" />
</td>
</tr>
<tr>
<th>Amount: </th>
<td><input v-model="test" type="text" name="amount" class="form-control" required />
</td>
</tr>
<tr>
<th>VAT 20% Amt: </th>
<td>
<input type="text" name="vatAmount" class="form-control" />
</td>
</tr>
<tr>
<th>Total Amount: </th>
<td>
<input type="text" name="totalAmount" class="form-control" />
</td>
</tr>
</thead>
</table>
<div class="pull-right">
<button type="submit" class="btn btn-success">
<i class="fa fa-save" aria-hidden="true" style="font-size:24px"></i> Save
</button>
</div>
</form>
</div>
</div>
<div class="col-md-6" >
<h3>Amount Due: £ #{{ test }}</h3>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
//Item code
new Vue({
el: '#app-item',
data: {
items:[
{ text:'Tax Returns', value: 'Tax Returns' },
{ text:'UTR Filing', value: 'UTR Filing'}
]
}
})
</script>
#endsection

I have a problem with my laravel pagination

I am new to Laravel. I am trying to create pagination with the data in my bootstrap table.
This is my index Controller function:
$Courses=Courses::orderBy('name','desc')->paginate(1);
return view('Courses.index')->with('Courses',$Courses);
I am getting this error:
Call to undefined method App\Courses::links() (View:
C:\laragon\www\TharakaCollege\resources\views\Courses\index.blade.php)
The information provided is not enough, however I think the problem is in your view. You have to have a code like this in your blade file:
<div class="pages">
<ul class="pagination ">
<li>{{$Courses->appends(request()->query())->links()}}</li>
</ul>
</div>
Moreover you'd better edit your returning view like this:
return view('Courses.index', array('Courses'=> $Courses));
This is the code in Courses/index.blade.php
<div id="page-wrapper">
#include('includes.message');
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-info">
<div class="panel-heading">
Courses
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="table-responsive">
<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th class="text-center">#</th>
<th class="text-center"> code</th>
<th class="text-center">Course Name</th>
<th class="text-center">Category</th>
<th class="text-center">Requirements</th>
</tr>
</thead>
<tbody>
#if(count($Courses)>0)
#foreach($Courses as $Courses)
<tr class="item{{$Courses->id}}">
<td>{{$Courses->id}}</td>
<td>{{$Courses->code}}</td>
<td>{{$Courses->name}}</td>
<td>{{$Courses->category}}</td>
<td>{{$Courses->requirements}}</td>
<td><a class="btn btn-info btn-sm" href="/Courses/{{$Courses->id}}/edit">Edit</a>
</td>
<td>
<form method="POST" action="{{route('Courses.destroy',$Courses->id)}}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="_method" value="DELETE">
<input type="submit" class="btn btn-danger btn-sm" value="Delete">
</form>
</td>
</tr>
#endforeach
#else
<p>No Courses</p>
#endif
</tbody>
</table>
{{ $Courses->links() }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
You should try this:
<div class="pull-left">
<div class="row">
<div class="col-xs-12">
<div class="explore-pagination">
<nav>
<div class="pagination"> {{ $Courses->render() }}</div>
</nav>
</div>
</div>
</div>
</div>
Try this code instead (modified version of yours):
<div id="page-wrapper">
#include('includes.message');
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-info">
<div class="panel-heading">
Courses
</div>
<!-- /.panel-heading -->
<div class="panel-body">
<div class="table-responsive">
<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th class="text-center">#</th>
<th class="text-center"> code</th>
<th class="text-center">Course Name</th>
<th class="text-center">Category</th>
<th class="text-center">Requirements</th>
</tr>
</thead>
<tbody>
#if(count($Courses)>0)
#foreach($Courses as $Course)
<tr class="item{{$Course->id}}">
<td>{{$Course->id}}</td>
<td>{{$Course->code}}</td>
<td>{{$Course->name}}</td>
<td>{{$Course->category}}</td>
<td>{{$Course->requirements}}</td>
<td><a class="btn btn-info btn-sm" href="/Courses/{{$Course->id}}/edit">Edit</a>
</td>
<td>
<form method="POST" action="{{route('Courses.destroy',$Course->id)}}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="_method" value="DELETE">
<input type="submit" class="btn btn-danger btn-sm" value="Delete">
</form>
</td>
</tr>
#endforeach
#else
<p>No Courses</p>
#endif
</tbody>
</table>
{{$Courses->appends(request()->query())->links()}}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
I have modified your foreach loop as well as ->links().
When calling the paginate method, you will receive an instance of Illuminate\Pagination\LengthAwarePaginator. In addition to these helpers methods, the paginator instances are iterators and may be looped as an array. So, once you have retrieved the results, you may display the results and render the page links using Blade:
Your blade should contain:
<div class="container">
#foreach ($courses as $course)
{{ $course->fieldName }}
#endforeach
</div>
{{ $courses->links() }}

How to highlight current active menu in Laravel 5.6 app?

I am using following bootstrap menu items with My laravel application,
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<div class="row">
<div class="col-sm-3 col-md-3">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne"><span class="glyphicon glyphicon-folder-close">
</span> Content Management</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">
<table class="table">
<tr>
<td>
<span class="glyphicon glyphicon-pencil text-primary"></span>Category
</td>
</tr>
<tr>
<td>
<span class="glyphicon glyphicon-pencil text-primary"></span>Brand
</td>
</tr>
<tr>
<td>
<span class="glyphicon glyphicon-pencil text-primary"></span>Model
</td>
</tr>
<tr>
<td>
<span class="glyphicon glyphicon-flash text-success"></span>Province
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
and using this menu bar with #include('menubar) with other blade files. now I need highlight current menu item when I visit each pages. how can I do this?
use
{{ request()->route()->getName() }}
or
{{ route()->currentRouteName() }}
then you can do something like
<a class="{{ request()->route()->getName() === "brands.index" ? "active" : "not-active" }}">
You can use this package I've written to do this: https://packagist.org/packages/arcesilas/active-state
Example with your code:
<div id="collapseOne" class="panel-collapse collapse in">
<div class="panel-body">
<table class="table">
<tr>
<td>
<span class="glyphicon glyphicon-pencil text-primary"></span>Category
</td>
</tr>
<tr>
<td>
<span class="glyphicon glyphicon-pencil text-primary"></span>Brand
</td>
</tr>
<tr>
<td>
<span class="glyphicon glyphicon-pencil text-primary"></span>Model
</td>
</tr>
<tr>
<td>
<span class="glyphicon glyphicon-flash text-success"></span>Province
</td>
</tr>
</table>
</div>
</div>
This package also allows you to check a url, a route with given parameters or a query.

Resources