How to take index from foreach? - php

So, I get the problem when I try to make the code for take the store_id from foreach
View
{{-- Cart --}}
<div class="row">
<div class="col-lg-9 my-3">
<div class="table-responsive mb-4">
#foreach ($carts as $cart => $items)
<h3>{{ $cart }}</h3>
{{-- TABLE --}}
<table class="table">
{{-- HEAD --}}
<thead>
<tr>
<th class="border-0 p-3 h6 title" scope="col">
Product
</th>
<th class="border-0 p-3 h6 title" scope="col">
Price
</th>
<th class="border-0 p-3 h6 title ps-5" scope="col">
Quantity
</th>
<th class="border-0 p-3 ps-4 h6 title" scope="col">
Total
</th>
</tr>
</thead>
{{-- CONTENT --}}
<tbody class="border-0">
#foreach ($items as $cart)
<tr>
<td class="p-3 border-0">
<div class="d-flex align-items-center">
<a class="reset-anchor d-block animsition-link" href="/products/{{ $cart->product->slug }}">
#if($cart->product->image)
<img src="img/admin_store/{{ $cart->product->image }}" width="70" />
#else
<img src="{{ asset('img/customer/img-1.png') }}" width="70" />
#endif
</a>
<div class="ms-3">
<a class="reset-anchor animsition-link title text-decoration-none" href="/products/{{ $cart->product->slug }}">{{ $cart->product->name }}</a>
</div>
</div>
</td>
<td class="p-3 align-middle border-0">
<p class="mb-0 small">Rp{{ number_format(($cart->product->price * ((100 - $cart->product->discount)/100)), 0,",",".") }}</p>
</td>
<td class="p-3 align-middle border-0">
<form action="/update_cart" method="POST">
#csrf
<div class="row">
<div class="col-5">
<input type="hidden" name="cart" value="{{ $cart->id }}">
<input type="number" name="quantity" value="{{ $cart->qty }}" class="w-100 ms-5" min="0" max="{{ $cart->product->stock }}">
</div>
</div>
<button type="submit" class="btn btn-sm btn-dark ms-5 mt-2" style="margin-right:20px">Update</button>
</form>
</td>
<td class="p-3 align-middle border-0">
<p class="mb-0 small">Rp{{ number_format($cart->total_product, 0,",",".") }}</p>
</td>
<td class="p-3 align-middle border-0">
<form action="/delete_cart" method="post">
#csrf
<input type="hidden" name="id" id="id" value="{{ $cart->id }}">
<a class="reset-anchor">
<button type="submit" class="btn btn-link">
<img src="{{ asset('img/customer/bx-trash.svg') }}" width="20">
</button>
</a>
</form>
</td>
</tr>
#endforeach
</tbody>
</table>
<hr>
{{-- TOTAL --}}
<div>
<h6 class="text-md-end">Total : Rp{{ $items->sum('total_product') }}</h6>
</div>
{{-- SHIPPING --}}
<div class="text-md-end">
<a class="btn btn-dark" href="/shipping/{{ $items->store_id }}"> checkout <i class='bx bx-basket'> </i> </a>
</div>
#endforeach
</div>
</div>
so in <a class="btn btn-dark" href="/shipping/{{ $items->store_id }}"> checkout <i class='bx bx-basket'> </i> </a> this is error
The Controller
public function index(Request $request)
{
$itemuser = $request->user();
$cartdetail = CartDetail::where('user_id', $itemuser->id)->get();
$cart = Cart::where('user_id', $itemuser->id)->get();
return view('customer.cart', [
'title' => 'Cart',
'carts' => $cart,
'cartdetail' => $cartdetail
]);
}
this result when using dd($carts)
This is my view
*note : store name, product and pictures are for study only, and the url before I add $items->store_id
So the story is, I'm only going to checkout for carts with the same store_id, but I'm confused about how to pull the store_id. How to solve it?

Related

Table disappears after clicking on add button on Livewire

My Livewire Component
public $productId;
public $allTariff = [];
public $rowProducts = [];
public function mount()
{
$this->rowProducts = Products::all();
$this->allTariff = [
['productId' => '', 'basicCharge' => '', 'additionalCharge' => '']
];
}
public function addProduct()
{
$this->allTariff[] = ['productId' => '', 'basicCharge' => '', 'additionalCharge' => ''];
}
public function render()
{
$rowProducts = Products::all();
return view('livewire.admin.admin-add-tariffs-component', ['rowProducts'=>$rowProducts)->layout('layouts.admin.base');
}
My View File
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-8">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Add Tariff</h6>
</div>
<div class="card-body">
<form wire:submit.prevent="storeTariff">
#csrf
<div class="form-row">
<!-- Default input -->
<div class="form-group col-md-8">
<input type="text" class="form-control" placeholder="Enter Tariff Name" wire:model="tariffName" >
</div>
</div><hr>
<div class="card">
<div class="card-header">
<h6 class="text-primary">Products, Basic and Weight Charges</h6>
</div>
<div class="card-body">
<table class="table" id="products_table">
<thead>
<tr>
<th>Product</th>
<th>Basic Charge</th>
<th>Weight Charge</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach ($allTariff as $index => $value)
<tr>
<td>
<select name="allTariff[{{$index}}][productId]"
wire:model="allTariff.{{ $index }}.productId"
class="custom-select custom-select-sm form-control form-control-sm">
#foreach ($rowProducts as $product)
<option value="{{ $product->id }}">
{{ $product->product_name }}
</option>
#endforeach
</select>
</td>
<td>
<input type="text" class="form-control form-control-user" name="allTariff[{{$index}}][basicCharge]" placeholder="Basic Charge" wire:model="allTariff.{{ $index }}.basicCharge" required>
</td>
<td>
<input type="text" class="form-control form-control-user" name="allTariff[{{$index}}][additionalCharge]" placeholder="Weight Charge" wire:model="allTariff.{{ $index }}.additionalCharge" required>
</td>
</tr>
#endforeach
</tbody>
</table>
<div class="row">
<div class="col-md-12">
<button class="btn btn-sm btn-secondary"
wire:click.prevent="addProduct">+ Add Another Product</button>
</div>
</div>
</div>
</div>
<hr>
{{-- <div class="form-row">
<div class="form-group col-md-3"> --}}
<button type="submit" class="form-control btn btn-small btn-primary">Add
Tariff</button>
{{-- </div>
</div> --}}
</form>
</div>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
Every time I click on the add tariff button this photo it give the blank page on this photo, but on console an html response is given.
I have tried a couple methods and tricks still no way out, just stuck for days
I have already include the livewire #livewireStyles and #livewireScripts, and i can't find an answer anywhere else cause i don't see any question that match my problem, and i'm kinda new to livewire
When using Livewire, there are a few things you need to be aware of. Due to the nature of how Livewire updates the page, there are some structural rules you need to follow.
The first and probably most important thing here, is that every Livewire-component view should only consist of one root element. And this includes comments!
If we count the root elements in your view, there are three - a comment, a div, and then another comment. So the first thing I did here, was to move the comments inside that div.
<div class="container-fluid">
<!-- Begin Page Content -->
<!-- Page Heading -->
<div class="row">
<div class="col-lg-8">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Add Tariff</h6>
</div>
<div class="card-body">
<form wire:submit.prevent="storeTariff">
#csrf
<div class="form-row">
<!-- Default input -->
<div class="form-group col-md-8">
<input type="text" class="form-control" placeholder="Enter Tariff Name"
wire:model="tariffName">
</div>
</div>
<hr>
<div class="card">
<div class="card-header">
<h6 class="text-primary">Products, Basic and Weight Charges</h6>
</div>
<div class="card-body">
<table class="table" id="products_table">
<thead>
<tr>
<th>Product</th>
<th>Basic Charge</th>
<th>Weight Charge</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach ($allTariff as $index => $value)
<tr>
<td>
<select name="allTariff[{{ $index }}][productId]"
wire:model="allTariff.{{ $index }}.productId"
class="custom-select custom-select-sm form-control form-control-sm">
#foreach ($rowProducts as $product)
<option value="{{ $product->id }}">
{{ $product->product_name }}
</option>
#endforeach
</select>
</td>
<td>
<input type="text" class="form-control form-control-user"
name="allTariff[{{ $index }}][basicCharge]"
placeholder="Basic Charge"
wire:model="allTariff.{{ $index }}.basicCharge" required>
</td>
<td>
<input type="text" class="form-control form-control-user"
name="allTariff[{{ $index }}][additionalCharge]"
placeholder="Weight Charge"
wire:model="allTariff.{{ $index }}.additionalCharge"
required>
</td>
</tr>
#endforeach
</tbody>
</table>
<div class="row">
<div class="col-md-12">
<button class="btn btn-sm btn-secondary" wire:click.prevent="addProduct">+ Add Another Product</button>
</div>
</div>
</div>
</div>
<hr>
{{-- <div class="form-row">
<div class="form-group col-md-3"> --}}
<button type="submit" class="form-control btn btn-small btn-primary">Add
Tariff</button>
{{-- </div>
</div> --}}
</form>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
Then another thing I would recommend that you look into is using wire:key on the tr element inside your table-loop, and on the option element inside your inner loop. The value to wire:key should always be unique to that particular row, so using $loop->index is not generally advised. You can generate a dummy-ID for each record that you add to your array, which sole purpose is to track the individual row. Here's how, see the wire:key I added in the template,
<div class="container-fluid">
<!-- Begin Page Content -->
<!-- Page Heading -->
<div class="row">
<div class="col-lg-8">
<div class="card shadow mb-4">
<div class="card-header py-3">
<h6 class="m-0 font-weight-bold text-primary">Add Tariff</h6>
</div>
<div class="card-body">
<form wire:submit.prevent="storeTariff">
#csrf
<div class="form-row">
<!-- Default input -->
<div class="form-group col-md-8">
<input type="text" class="form-control" placeholder="Enter Tariff Name"
wire:model="tariffName">
</div>
</div>
<hr>
<div class="card">
<div class="card-header">
<h6 class="text-primary">Products, Basic and Weight Charges</h6>
</div>
<div class="card-body">
<table class="table" id="products_table">
<thead>
<tr>
<th>Product</th>
<th>Basic Charge</th>
<th>Weight Charge</th>
<th></th>
</tr>
</thead>
<tbody>
#foreach ($allTariff as $index => $value)
<tr wire:key="tariff-{{ $value->wireKey }}">
<td>
<select name="allTariff[{{ $index }}][productId]"
wire:model="allTariff.{{ $index }}.productId"
class="custom-select custom-select-sm form-control form-control-sm">
#foreach ($rowProducts as $product)
<option value="{{ $product->id }}" wire:key="product-{{ $product->id }}">
{{ $product->product_name }}
</option>
#endforeach
</select>
</td>
<td>
<input type="text" class="form-control form-control-user"
name="allTariff[{{ $index }}][basicCharge]"
placeholder="Basic Charge"
wire:model="allTariff.{{ $index }}.basicCharge" required>
</td>
<td>
<input type="text" class="form-control form-control-user"
name="allTariff[{{ $index }}][additionalCharge]"
placeholder="Weight Charge"
wire:model="allTariff.{{ $index }}.additionalCharge"
required>
</td>
</tr>
#endforeach
</tbody>
</table>
<div class="row">
<div class="col-md-12">
<button class="btn btn-sm btn-secondary" wire:click.prevent="addProduct">+ Add Another Product</button>
</div>
</div>
</div>
</div>
<hr>
{{-- <div class="form-row">
<div class="form-group col-md-3"> --}}
<button type="submit" class="form-control btn btn-small btn-primary">Add
Tariff</button>
{{-- </div>
</div> --}}
</form>
</div>
</div>
</div>
</div>
<!-- /.container-fluid -->
</div>
And then in your component, just generate a unique string
class AdminAddTariffsComponent
{
public $productId;
public $allTariff = [];
public $rowProducts = [];
public function mount()
{
$this->rowProducts = Products::all();
$this->addProduct();
}
public function addProduct()
{
$this->allTariff[] = [
'productId' => '',
'basicCharge' => '',
'additionalCharge' => '',
'wireKey' => \Str::uuid(),
];
}
public function render()
{
return view('livewire.admin.admin-add-tariffs-component')
->layout('layouts.admin.base');
}
}

How to pass parameters correctly to a paypal button (laravel)

I'm creating a little cart that passes the values of the items you bought to the paypal cart so you can checkout quickly. my problem is that it currently creates a paypal button per item added to the cart. Let me show you.
Since there are 3 items in the cart, there are 3 buttons. once you look at the source code, its pretty obvious: the code is inside a #foreach column. My question is, how do I initialize the value $id => $details so I can pass around the actual values of the products being processed, so the user doesn't need to manually input the products he or she desires? I havent found a way to do this without using the "#foreach" thingy. Let me show you my code:
this is layout.blade.php:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>#yield('Carrito')</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="{{ asset('css/style2.css') }}">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-12 col-sm-12 col-12 main-section">
<div class="dropdown">
<button type="button" class="btn btn-info" data-toggle="dropdown">
<i class="fa fa-shopping-cart" aria-hidden="true"></i> Carrito <span class="badge badge-pill badge-danger">{{ count((array) session('cart')) }}</span>
</button>
<div class="dropdown-menu">
<div class="row total-header-section">
<div class="col-lg-6 col-sm-6 col-6">
<i class="fa fa-shopping-cart" aria-hidden="true"></i> <span class="badge badge-pill badge-danger">{{ count((array) session('cart')) }}</span>
</div>
<?php $total = 0 ?>
#foreach((array) session('cart') as $id => $details)
<?php $total += $details['price'] * $details['quantity'] ?>
#endforeach
<div class="col-lg-6 col-sm-6 col-6 total-section text-right">
<p>Total: <span class="text-info">$ {{ $total }}</span></p>
</div>
</div>
#if(session('cart'))
#foreach(session('cart') as $id => $details)
<div class="row cart-detail">
<div class="col-lg-4 col-sm-4 col-4 cart-detail-img">
<img src="{{ $details['photo'] }}" />
</div>
<div class="col-lg-8 col-sm-8 col-8 cart-detail-product">
<p>{{ $details['name'] }}</p>
<span class="price text-info"> ${{ $details['price'] }}</span> <span class="count"> Quantity:{{ $details['quantity'] }}</span>
</div>
</div>
#endforeach
#endif
<div class="row">
<div class="col-lg-12 col-sm-12 col-12 text-center checkout">
Ver todo
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="container page">
#yield('content')
</div>
#yield('scripts')
</body>
</html>
and this is cart.blade.php
#extends('layout')
#section('title', 'Cart')
#section('content')
<table id="cart" class="table table-hover table-condensed">
<thead>
<tr>
<th style="width:50%">Producto</th>
<th style="width:10%">Precio</th>
<th style="width:8%">Cantidad</th>
<th style="width:22%" class="text-center">Subtotal</th>
<th style="width:10%"></th>
</tr>
</thead>
<tbody>
<?php $total = 0 ?>
#if(session('cart'))
#foreach(session('cart') as $id => $details)
<?php $total += $details['price'] * $details['quantity'] ?>
<tr>
<td data-th="Product">
<div class="row">
<div class="col-sm-3 hidden-xs"><img src="{{ $details['photo'] }}" width="100" height="100" class="img-responsive"/></div>
<div class="col-sm-9">
<h4 class="nomargin">{{ $details['name'] }}</h4>
</div>
</div>
</td>
<td data-th="Price">${{ $details['price'] }}</td>
<td data-th="Quantity">
<input type="number" value="{{ $details['quantity'] }}" class="form-control quantity" />
</td>
<td data-th="Subtotal" class="text-center">${{ $details['price'] * $details['quantity'] }}</td>
<td class="actions" data-th="">
<button class="btn btn-info btn-sm update-cart" data-id="{{ $id }}"><i class="fa fa-refresh"></i></button>
<button class="btn btn-danger btn-sm remove-from-cart" data-id="{{ $id }}"><i class="fa fa-trash-o"></i></button>
</td>
</tr>
#endforeach
#endif
</tbody>
<tfoot>
<tr class="visible-xs">
<td class="text-center"><strong>Total {{ $total }}</strong></td>
</tr>
<tr>
<td><i class="fa fa-angle-left"></i> Seguir comprando</td>
<td colspan="2" class="hidden-xs"></td>
<td class="hidden-xs text-center"><strong>Total ${{ $total }}</strong></td>
<!-- the paypal button part -->
#if(session('cart'))
#foreach(session('cart') as $id => $details)
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" >
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="business" value="notanothergenericaddress#gmail.com">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="{{ $details['name'] }}">
<input type="hidden" name="amount" value="{{ $details['price'] }}">
<input type="hidden" name="currency_code" value="MXN">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="no_note" value="0">
<input type="hidden" name="tax_rate" value="15.000">
<input type="hidden" name="shipping" value="500.00">
<input type="hidden" name="add" value="{{ $details['quantity'] }}">
<input type="hidden" name="bn" value="PP-ShopCartBF:btn_cart_LG.gif:NonHostedGuest">
<input type="image" src="https://www.paypalobjects.com/es_XC/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal, la forma más segura y rápida de pagar en línea.">
<img alt="" src="https://www.paypalobjects.com/es_XC/i/scr/pixel.gif" width="1" height="1">
</form>
#endforeach
#endif
</tr>
</tfoot>
</table>
Instead of add to cart buttons, render a single button using cart upload. However, this is all very old. Instead of these HTML buttons, you should integrate the current version of PayPal Checkout.
Since you have a server, make two routes:, one for 'Create Order' and one for 'Capture Order', documented here. These routes should return only JSON data (no HTML or text). The latter one should (on success) store the payment details in your database before it does the return (particularly purchase_units[0].payments.captures[0].id, the PayPal transaction ID)
Pair those two routes with the following approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server

Laravel 7.0: Login Error - These credentials do not match our records

This is my first big project with Laravel. I added a multirow delete function for my users table, it worked and logged me off and I haven't been able to log in again. Also all my routes aren't working.
i'm not really certain on what to do, i've tried to log in with other user details but the result is still the same. I've created a new user profile too.
Below is the code on the user blade file
#extends('layouts.admin')
#section('content')
<!-- Page Heading -->
#can('user_create')
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h2 class="h3 mb-0 ">Staff</h2>
<span class="d-md-flex d-sm-block left-side ">
Add Staff
</span>
</div>
#endcan
<!-- toolbar -->
<div class="row">
<div class="col-2">
<div class="d-md-flex">
<span class="d-flex mr-4">
<span class="mr-2"><small>Sort</small></span> <div class="dropdown arrow">
<a class="dropdown-toggle font-weight-bold" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<small>All</small>
</a>
<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item" href="#">Name</a>
<a class="dropdown-item" href="#">No of ticket</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
</span>
<span>
Layout off Staff
</span>
</div>
</div>
</div>
<div class="row">
<!-- main content column -->
<div class="col-xl-12 col-lg-12">
<div class="table-responsive px-1">
<table class="ajaxTable datatable datatable-User">
<thead>
<tr>
<th scope="col ml-3"><small class="align-middle">
<label class="checkbox-container">
<input type="checkbox" id="chkCheckAll">
<span class="checkmark"></span>
</label>
</th>
<th scope="col ml-3 "><small class="align-middle">Name <small></th>
<th scope="col ml-3"><small class="align-middle">Position<small></th>
<th scope="col ml-3"><small class="">Department<small></th>
<th scope="col ml-3"><small class="">Phone<small></th>
<th scope="col ml-3"><small class="">Email<small></th>
<th scope="col ml-3"><small class="">Assigned ticket<small></th>
<th scope="col ml-3"><small class="">Date Created<small></th>
<th scope="col ml-3"><small class="">Actions<small></th>
</tr>
</thead>
<tbody>
#foreach($users as $key => $user)
<tr class="rounded-3" id="sid{{ $user->id }}">
<td class="align-middle">
<label class="checkbox-container">
<input type="checkbox" name="ids" value="{{ $user->id }}" class="chkBoxClass" >
<span class="checkmark"></span>
</label>
</td>
<td>
<a href="{{ route("admin.users.show",$user) }}"><span class="d-block font-weight-bold">
<img class="img-profile rounded-circle mr-2" height ="40" width="40" src="https://source.unsplash.com/QAB-WJcbgJk/60x60">
{{ $user->name ?? '' }}</span></a>
</td>
<td>
#foreach($user->roles as $key => $item)
<span class="badge badge-info">{{ $item->title }}</span>
#endforeach
</td>
<td class="align-middle">
#foreach($user->categories as $key => $item)
<div>{{ $item->name }}</div>
#endforeach
</td>
<td class="align-middle">
{{ $user->phone}}
</td>
<td class="align-middle font-weight-bold">
{{ $user->email ?? '' }}
</td>
<td class="align-middle">
{{ count($user->tickets) }}
</td>
<td class="align-middle text-center">
{{ $user->created_at ?? '' }}
</td>
<td>
<div class="dropdown no-arrow">
<a class="dropdown-toggle font-weight-bold" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-ellipsis-v fa-sm fa-fw text-gray-400 "></i>
</a>
<div class="dropdown-menu dropdown-menu-right shadow animated--fade-in" aria-labelledby="dropdownMenuLink">
#can('user_show')
<a class="dropdown-item" href="{{ route('admin.users.show', $user->id) }}">
{{ trans('global.view') }}
</a>
#endcan
#can('user_edit')
<a class="dropdown-item" href="{{ route('admin.users.edit', $user->id) }}">
{{ trans('global.edit') }}
</a>
#endcan
#can('user_delete')
<form class="d-flex" action="{{ route('admin.users.destroy', $user->id) }}" method="POST" onsubmit="return confirm('{{ trans('global.areYouSure') }}');" style="display: inline-block;">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="submit" class="dropdown-item" value="{{ trans('global.delete') }}">
</form>
#endcan
</div>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
{{ $users->links() }}
</div>
</div>
</div>
#endsection
#section('scripts')
#parent
<script>
$(function ()
{
let dtButtons = $.extend(true, [], $.fn.dataTable.defaults.buttons)
#can('user_delete')
let deleteButtonTrans = '{{ trans('global.datatables.delete') }}'
let deleteButton = {
text: deleteButtonTrans,
url: "{{ route('admin.users.massDestroy') }}",
className: 'btn-danger',
action: function (e, dt, node, config) {
var ids = $.map(dt.rows({ selected: true }).nodes(), function (entry) {
return $(entry).data('entry-id')
});
if (ids.length === 0) {
alert('{{ trans('global.datatables.zero_selected') }}')
return
}
if (confirm('{{ trans('global.areYouSure') }}')) {
$.ajax({
headers: {'x-csrf-token': _token},
method: 'POST',
url: config.url,
data: { ids: ids, _method: 'DELETE' }})
.done(function () { location.reload() })
}
}
}
dtButtons.push(deleteButton)
#endcan
$.extend(true, $.fn.dataTable.defaults, {
order: [[ 1, 'desc' ]],
pageLength: 4,
});
$('.datatable-User:not(.ajaxTable)').DataTable({ buttons: dtButtons })
$('a[data-toggle="tab"]').on('shown.bs.tab', function(e){
$($.fn.dataTable.tables(true)).DataTable()
.columns.adjust();
});
})
</script>
<script>
$(function(e){
$("#chkCheckAll").click(function(){
$(".chkBoxClass").prop('checked', $(this).prop('checked'));
});
$('#DASR').click(function(e){
e.preventDefault();
var allids = [];
$("input:checkbox[name=ids]:checked").each(function(){
allids.push($(this).val());
});
$.ajax({
url:"{{route('admin.users.massDestroy')}}",
type:'DELETE',
data:{
ids:allids,
_token: $("input[name=_token]").val()
},
success:function(response)
{
$.each(allids,function(key, val){
$('#sid'+val).remove();
});
}
});
});
});
</script>
#endsection
Do you have a repo to share so we can see the full code base. I would say the problem is not to do with this page exactly. Would be interesting to know what the functionality is behind the route 'admin.users.massDestroy' too... this may have deleted something it should not have done.
Other than that I can only take a guess and possibly say the passwords aren't correct when logging in. Or something wrong with the cache. You could try clearing it.

Partial Print Area PHP

I'm kinda new here, just need help with small code.
I need to print specific area with a Print Payment Record that I've already added, I've added a new button, tried with another tutorial but I couldn't do it, with my other code print the entire page.
I know I can highlight the table and hit print but having a button is easier mostly when the record is like 50 payments.
Start in Deposit Fee in Details.
Help with these please!
This is my code:
#extends('branch.layout.main')
#section('title') Manage Fee #endsection
#section('content')
<div class="container">
<div class="section">
#section('button')
Deposit Fee
#endsection
<div class="row">
<div class="col s12 m12 l12">
<div class="card-panel">
<div class="row">
<h4 class="header2" style="color:#00bcd4"><i class="mdi-social-person" style="font-size:20px"></i> Fee Detail of {{ $student->first_name." ".$student->last_name }}</h4>
<table class="striped" >
<thead>
<tr>
<th>Current Course</th>
<th>Course Fee</th>
<th>Discount</th>
<th>Any Extra</th>
<th>Total Payable</th>
<th>Deposited Fee</th>
<th>Balance</th>
</tr>
<tr>
<td width="20%">{{ $course->courseName }}</td>
<td width="13%">{{ IMS::currency().$course->course_fee }}</td>
<td width="13%">{{ IMS::currency().$course->discount }}</td>
<td width="13%">{{ IMS::currency().$extra }}</td>
<td width="13%">{{ IMS::currency().$payable }}</td>
<td width="13%">{{ IMS::currency().$deposited }}</td>
<td width="13%"><span style="color:red">{{ IMS::currency().$balance }}</span></td>
</tr>
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
<!--Deposited Fee in Detail-->
#if(count($fees) > 0)
<div class="row">
<div class="col s12 m12 l12">
<div class="card-panel">
<div class="row">
<h4 class="header2" style="color:#00bcd4"><i class="mdi-content-add" style="font-size:20px"></i> Deposited Fee of {{ $student->first_name." ".$student->last_name }}</h4>
<button onclick="printContent('row')">Print Payment Record </button>
<table class="striped" >
<thead>
<tr>
<th>Date Added</th>
<th>Amount</th>
<th>Course</th>
<th>Due Date</th>
<th>Option</th>
</tr>
#foreach($fees as $fee)
<tr>
<td width="20%">{{ date('d-M-Y',strtotime($fee->date_added)) }}</td>
<td width="20%">{{ IMS::currency().$fee->amount }}</td>
<td width="20%">{{ $fee->courseName }}</td>
<td width="20%">#if($fee->due_date) {{ date('d-M-Y',strtotime($fee->due_date)) }} #else --- #endif</td>
<td width="20%">
<i class="mdi-maps-local-print-shop"></i>
<i class="mdi-maps-local-print-shop"></i>
#if($delete)
<i class="mdi-content-clear"></i>
#endif
</td>
</tr>
#endforeach
</thead>
</table>
</div>
</div>
</div>
</div>
</div>
#endif
<!--End Deposited Fee in Detail-->
<!--Add New Fee-->
<div id="AddNew" class="modal modal-fixed-footer">
<div class="modal-content">
<h4 class="header2">Deposit Fee For {{ $student->first_name }} {{ $student->last_name }}</h4>
<form action="{{ Asset('fee/'.$student->id) }}" method="post">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="row">
<div class="input-field col s6">
<i class="mdi-editor-insert-invitation prefix"></i>
{!! Form::date('date_added',date('Y-m-d'),['id' => 'date_added','class' => 'datepicker']) !!}
<label for="date_added">Date Added *</label>
</div>
<div class="input-field col s6">
<i class="mdi-editor-attach-money prefix"></i>
{!! Form::number('amount',null,['id' => 'amount','required' => 'required','pattern' => '[0-9]{10}']) !!}
<label for="amount">Amount *</label>
</div>
</div>
<div class="row">
<div class="input-field col s6">
<select name="payment_mode">
<option>Please select Payment Type</option>
<option>Cash</option>
<option>Cheque</option>
<option>Card</option>
<option>Credit or Discount</option>
</select>
</div>
<div class="input-field col s6">
{!! Form::text('cheque_Card_Number', null, ['id' => 'cheque_Card_Number']) !!}
</div>
</div>
<p style="color:red"><i class="fa fa-bell"></i> If you want fee due reminder then select fee due date,if not then leave empty</p>
<div class="row">
<div class="input-field col s12">
<i class="mdi-editor-insert-invitation prefix"></i>
{!! Form::date('due_date',null,['id' => 'due_date','class' => 'datepicker']) !!}
<label for="due_date">Due Date</label>
</div>
</div>
<div class="modal-footer">
Close
<button type="submit" class="btn blue modal-action modal-close">Save</button>
</div>
</form>
</div>
</div>
<!--End Add New Fee-->
#endsection

Laravel : Search result search?page=2 show nothing, just blank page

My pagination works correctly, but when use search component it display only first page of result.
My page URL without search looks like:
http://localhost:8000/dictionary-management/postcode?page=2
And it's work correctly.
My first page URL with search:
http://localhost:8000/dictionary-management/postcode/search
and it's work correctly.
My second page URL with search:
http://localhost:8000/dictionary-management/postcode/search?page=2
and the is nothing to show, only blank page.
This is my Controller Search method:
public function search(Request $request) {
$constraints = [
'postcode' => $request['postcode'],
'address' => $request['address']
];
$postcodes = $this->doSearchingQuery($constraints);
return view('dictionary-mgmt/postcode/index', ['postcodes' => $postcodes, 'searchingVals' => $constraints]);
}
private function doSearchingQuery($constraints) {
$query = Postcode::query();
$fields = array_keys($constraints);
$index = 0;
foreach ($constraints as $constraint) {
if ($constraint != null) {
$query = $query->where( $fields[$index], 'like', '%'.$constraint.'%');
}
$index++;
}
return $query->Paginate(5);
}
This is my route :
Route::resource('dictionary-management/postcode', 'PostCodeController');
Route::post('dictionary-management/postcode/search', PosstCodeController#search')->name('postcode.search');
This is my index view :
#extends('dictionary-mgmt.postcode.base')
#section('action-content')
<!-- Main content -->
<section class="content">
<div class="box">
<div class="box-header">
<div class="row">
<div class="col-sm-8">
<h3 class="box-title">List kodów pocztowych</h3>
</div>
<div class="col-sm-4">
<a class="btn btn-primary pull-right" href="{{ route('postcode.create') }}">Dodaj nowy kod pocztowy</a>
</div>
</div>
</div>
<!-- /.box-header -->
<div class="box-body">
<div class="row">
<div class="col-sm-6"></div>
<div class="col-sm-6"></div>
</div>
<form method="POST" action="{{ route('postcode.search') }}">
{{ csrf_field() }}
#component('layouts.search', ['title' => 'Szukaj'])
#component('layouts.two-cols-search-row', ['items' => ['postcode', 'address'], 'title' => ['Kod','Adres'],
'oldVals' => [isset($searchingVals) ? $searchingVals['postcode'] : '', isset($searchingVals) ? $searchingVals['address'] : '']])
#endcomponent
#endcomponent
</form>
<div id="example2_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
<div class="row">
<div class="col-sm-12">
<table id="example2" class="table table-bordered table-hover dataTable" role="grid" aria-describedby="example2_info">
<thead>
<tr role="row">
<th width="5%">Kod pocztowy</th>
<th width="40%">Adres</th>
<th width="10%">Miejscowość</th>
<th width="10%">Województwo</th>
<th width="10%">Powiat</th>
<th>Akcja</th>
</tr>
</thead>
<tbody>
#foreach ($postcodes as $postcode)
<tr role="row" class="odd">
<td>{{ $postcode->postcode }}</td>
<td>{{ $postcode->address }}</td>
<td>{{ $postcode->city }}</td>
<td>{{ $postcode->voivodeship }}</td>
<td>{{ $postcode->county }}</td>
<td>
<form class="row" method="POST" action="{{ route('postcode.destroy', ['id' => $postcode->id]) }}" onsubmit = "return confirm('Czy napewno usunąć?')">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<a href="{{ route('postcode.edit', ['id' => $postcode->id]) }}" class="btn btn-warning col-sm-3 col-xs-5 btn-margin">
Edytuj
</a>
<button type="submit" class="btn btn-danger col-sm-3 col-xs-5 btn-margin">
Usuń
</button>
</form>
</td>
</tr>
#endforeach
</tbody>
<tfoot>
<tr>
<th width="5%">Kod pocztowy</th>
<th width="40%">Adres</th>
<th width="10%">Miejscowość</th>
<th width="10%">Województwo</th>
<th width="10%">Powiat</th>
<th>Akcja</th>
</tr>
</tfoot>
</table>
</div>
</div>
<div class="row">
<div class="col-sm-5">
</div>
<div class="col-sm-7">
<div class="dataTables_paginate paging_simple_numbers" id="example2_paginate">
{{ $postcodes->links() }}
</div>
</div>
</div>
</div>
</div>
<!-- /.box-body -->
</div>
</section>
<!-- /.content -->
</div>
#endsection
And this is my search component:
<div class="row">
#php
$index = 0;
#endphp
#foreach ($items as $item)
<div class="col-md-6">
<div class="form-group">
#php
$stringFormat = strtolower(str_replace(' ', '', $item));
#endphp
<label for="input<?=$stringFormat?>" class="col-sm-3 control-label">{{$title[$index]}}</label>
<div class="col-sm-9">
<input value="{{isset($oldVals) ? $oldVals[$index] : ''}}" type="text" class="form-control" name="<?=$stringFormat?>" id="input<?=$stringFormat?>" placeholder="{{$title[$index]}}">
</div>
</div>
</div>
#php
$index++;
#endphp
#endforeach
</div>
Please help, I don't know where is my mistake...
Try this
{{ $postcodes->appends(request()->input())->links()}}
instead of {{ $postcodes->links() }}

Categories