Laravel LiveWire Pagination issue - php

I am new to LiveWire and trying to build simple app with Laravel , jetstream and livewire
My application get data from DB and show in Table with Pagination.
every thing is working fine but issue is when i click on any page I got URI '?page=2'
I dont want to see this URI in Url
my blade is also simple as bellow
<x-app-layout>
<x-slot name="header">
</x-slot>
<div class="py-2">
<div class="mx-auto sm:px-2 lg:px-2">
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
<div class="flex flex-wrap">
<livewire:item />
</div>
</div>
</div>
</div>
</x-app-layout>
and livewire:item
<table class="table-auto w-full">
<thead>
<tr>
<th class="px-4 py-2">
<div class="flex items-center">
<button>Image</button>
</div>
</th>
<th class="px-4 py-2">
<div class="flex items-center">
<button wire:click="sortBy('sku')">SKU</button>
<x-sort-icon sortField="sku" :sort-by="$sortBy" :sort-asc="$sortAsc" />
</div>
</th>
<th class="px-4 py-2">
<div class="flex items-center">
<button wire:click="sortBy('title')">Title</button>
<x-sort-icon sortField="title" :sort-by="$sortBy" :sort-asc="$sortAsc" />
</div>
</th>
<th class="px-4 py-2">
<div class="flex items-center">
<button wire:click="sortBy('avg_pprice')">Price</button>
<x-sort-icon sortField="avg_pprice" :sort-by="$sortBy" :sort-asc="$sortAsc" />
</div>
</th>
<th class="px-4 py-2">
<div class="flex items-center">
<button wire:click="sortBy('stock')">Stock</button>
<x-sort-icon sortField="stock" :sort-by="$sortBy" :sort-asc="$sortAsc" />
</div>
</th>
<th class="px-4 py-2">
<div class="flex items-center">
<button wire:click="sortBy('selling_price')">Sale Price</button>
<x-sort-icon sortField="selling_price" :sort-by="$sortBy" :sort-asc="$sortAsc" />
</div>
</th>
<th class="px-4 py-2">
Actions
</th>
</tr>
</thead>
<tbody>
#foreach($items as $item)
<tr>
<td class="border px-4 py-2"><img class="w-20" src='{{ $item->image}}'></td>
<td class="border px-4 py-2">{{ $item->title}}</td>
<td class="border px-4 py-2">{{ number_format($item->price, 2)}}</td>
</tr>
#endforeach
</tbody>
</table>
<div class="mt-4">
{{ $items->links() }}
</div>
Also livewire controller is
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\item;
use Livewire\WithPagination;
class Items extends Component
{
use WithPagination;
public $perPage = 10;
public function render()
{
$items = Item::all();
$items = $items->paginate($this->perPage);
return view('livewire.items', [
'items' => $items,
]);
}
}

It worked as bellow Thanks to #Remul
use Livewire\Component;
use Livewire\WithPagination;
class ContactsTable extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
public function getQueryString()
{
return [];
}
}

You should have only one root item in your Livewire view livewire:item. Move the
<div class="mt-4">
{{ $items->links() }}
</div>
either within the table tag or create a big div around everything.
<div>
<table>
// table stuff
</table>
<div class="mt-4">
{{ $items->links() }}
</div>
</div>
The ?page=2 for the second page is always appended, this is a correct behaviour. Your table should updated accordingly to the page selected.

In my case, i use and define bootstrap theme on the same links.
$users->links('pagination::bootstrap-4')
but, after check this question, i try:
protected $paginationTheme = 'bootstrap';
That fix my error with the pagination links after type string to search.

Related

Laravel Jetstream Modal close not working as intended and has errors

I'm fairly new to laravel jetstream and is trying to use their build in modal component. I have already created a button that will open the modal for the user to edit information. Everything works fine in terms of opening the modal, saving and whatnot but when I set the wire:model to false, it will produce a bunch of errors that I have no idea what's happening, everything on the component is unclickable unless I refresh.
Below is my code
index.blade.php
<div>
<div class="py-12">
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
<livewire:church.church-add-form />
<div class="flex flex-col">
<div class="overflow-x-auto sm:-mx-6 lg:-mx-8">
<div class="py-2 inline-block min-w-full sm:px-6 lg:px-8">
<div class="overflow-x-auto">
<table class="min-w-full">
<thead class="bg-gray-50 border-b">
<tr>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">
Church Name
</th>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">
Region
</th>
<th scope="col" class="text-sm font-medium text-gray-900 px-6 py-4 text-left">
Action
</th>
</tr>
</thead>
<tbody>
#foreach($churches as $church)
<tr class="bg-white border-b transition duration-300 ease-in-out hover:bg-gray-100">
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
{{$church->name}}
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
#foreach ($regions as $region)
#if ($region->id == $church->region_id)
{{ $region->name }}
#endif
#endforeach
</td>
<td class="text-sm text-gray-900 font-light px-6 py-4 whitespace-nowrap">
<x-jet-button class="bg-blue-500" wire:click="edit({{$church}})">Edit</x-jet-button>
<x-jet-button class="bg-red-500" wire:click="delete({{$church}})">Delete</x-jet-button>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<div class="mt-5">
{{ $churches->links() }}
</div>
</div>
</div>
</div>
</div>
<x-jet-dialog-modal wire:model="showEditModal">
<x-slot name="title">
Edit Church
</x-slot>
<x-slot name="content">
<div>
<x-jet-label for="name" value="{{ __('Church Name') }}" />
<x-jet-input id="name" class="block mt-1 w-full" type="text" name="name" wire:model.defer="state.name" required/>
#error('name')
<p class="text-red-500">{{$message}}</p>
#enderror
</div>
<div class="mt-5">
<x-jet-label for="region" value="{{ __('Region') }}" />
<select class="border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm block mt-1 w-full" aria-label="region-select" wire:model="state.region_id">
#foreach($regions as $region)
<option value="{{$region->id}}">{{$region->name}}</option>
#endforeach
</select>
</div>
</x-slot>
<x-slot name="footer">
<x-jet-secondary-button wire:click="$set('showEditModal', false)" wire:loading.attr="disabled">
Close
</x-jet-secondary-button>
<x-jet-button class="ml-2" wire:click="updateChurch" wire:loading.attr="disabled">
Save
</x-jet-button>
</x-slot>
</x-jet-dialog-modal>
</div>
index Component
public $showEditModal = false;
public function edit(Church $church)
{
$this->showEditModal = true;
}
app.blade.php
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Fonts -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Nunito:wght#400;600;700&display=swap">
<!-- Scripts -->
#vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
Below is the error when I click close.
wire:click="$set('showEditModal', false)"
is correct.
public function edit(Church $church)
{
$this->showEditModal = true;
$this->church = $church;
}
public function close()
{
$this->showEditModal = false;
$this->church = null;
}
public function mount()
{
$this->Church = new Church(); // if your model name is Church
}
I have found the problem, apparently there's a conflict between the alpine.js from livewire and alpine.js from #powerGridScripts, once I commented out, everyone works fine.
#livewireScripts
{{-- #powerGridScripts--}}

How to take index from foreach?

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?

livewire action not happening when link is clicked

So I have popup which contains a form that shows a table with editable cells using livewire and each row has a delete button, above this table is a button to add a new empty row to the table. Editing in the cells is working (click the cell and it changes to the inline edit input) but clicking the delete link does nothing and neither does the add link.
So for this process I have the following in the client index file which loads the popup modal when the button to edit the client is clicked.
For this question I am looking at why the add isn't working but as for the delete that would be a bonus!
<script>
$(document).ready(function() {
$("#clients tbody").on("click", ".actions", function () {
var data = table.row( $(this).parents('tr') ).data();
// now call ajax on this url
call_ajax( "/client/" + data[0] + "/edit" );
loader.style.display = "block";
modal.style.display = "block";
});
});
function call_ajax( url ) {
// ToDo make an actual ajax call to get the form data
$.get( url )
.done(
function( data ) {
$("#content-region").html( data );
}
)
.fail(
function() {
$("#content-region").html( "<p>error</p>" );
}
);
}
</script>
So using this when a client has its action section clicked then a call to client/{x}/edit is called which is calls my edit.blade.php file:
#extends('layouts.popup')
#section('header')
<i class="fa fa-fw fa-pencil-square-o fa-lg text-success"></i> Edit Client
#stop
#section('content')
<div class="client-editor">
<form class="admin-link" method="post" action="client/save">
#csrf
<input type="hidden" name="id" value="{{ old( 'id', $client->id ) }}">
<div class="max-w-10xl mx-auto py-10 sm:px-6 lg:px-8">
<div class="md:grid md:grid-cols-3 md:gap-6">
<div class="md:col-span-1 flex justify-between">
<div class="px-4 sm:px-0">
<h3 class="text-lg font-medium text-gray-900">Client Edit</h3>
<p class="mt-1 text-sm text-gray-600">
Update the Client title, you can add and remove contacts below.
</p>
</div>
<div class="px-4 sm:px-0">
</div>
</div>
<div class="mt-5 md:mt-0 md:col-span-2">
<div class="px-4 py-5 bg-white sm:p-6 shadow sm:rounded-tl-md sm:rounded-tr-md">
<!-- Eclipse Account Handler -->
<div class="col-span-6 sm:col-span-4">
<label class="block font-medium text-sm text-gray-700" for="client_id">
Client Title
</label>
<input
class="border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 rounded-md shadow-sm mt-1 block w-full"
id="title"
name="title"
type="text"
value="{{ $client->title }}"
>
</div>
<br>
<div class="col-span-6 sm:col-span-4">
<x-toggle
left="No"
right="Yes"
name="is_enabled"
label="Is this client active?"
colourleft="#805050"
colourright="#508050"
default="{{ $client->is_enabled }}"
/>
</div>
</div>
<div class="hidden sm:block">
<div class="py-8">
<div class="border-t border-gray-200"></div>
</div>
</div>
</div>
</div>
</div>
<!-- client contacts -->
<div class="max-w-10xl mx-auto py-10 sm:px-6 lg:px-8">
<div class="md:grid md:grid-cols-3 md:gap-6">
<div class="md:col-span-1 flex justify-between">
<div class="px-4 sm:px-0">
<h3 class="text-lg font-medium text-gray-900">Client Contacts</h3>
<p class="mt-1 text-sm text-gray-600">
Enter details for client contacts assigned to this client.
</p>
</div>
</div>
<div class="mt-5 md:mt-0 md:col-span-2">
<div class="px-4 py-5 bg-white sm:p-6 shadow sm:rounded-tl-md sm:rounded-tr-md">
#livewire("contacts-table", [ 'client' => $client ])
</div>
<div
class="flex items-center justify-end px-4 py-3 bg-gray-50 text-right sm:px-6 shadow sm:rounded-bl-md sm:rounded-br-md">
<button
type="submit"
class="inline-flex items-center px-4 py-2 bg-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:ring focus:ring-gray-300 disabled:opacity-25 transition"
>
Save
</button>
</div>
<div class="hidden sm:block">
<div class="py-8">
<div class="border-t border-gray-200"></div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
#stop
and from in this a call of #livewire("contacts-table", [ 'client' => $client ]) and this are it's parts.
ContactsTable.php
<?php
namespace App\Http\Livewire;
use App\Models\Client;
use App\Models\ClientContact;
use Livewire\Component;
class ContactsTable extends Component
{
protected $listeners =['refresh' => '$refresh'];
public Client $client;
public $clientContacts;
public function mount( Client $client )
{
$this->clientContacts = ClientContact::where( 'client_id', $client->id )->get();
}
public function render()
{
return view('livewire.contacts-table');
}
public function addNewContact()
{
die('Test that we got here!'); // I actually have a breakpoint here.
}
}
and contacts-table.blade.php:
<div class="col-span-6 sm:col-span-4">
<a
class="inline-flex items-center px-4 py-2 bg-gray-800 dark:bg-gray-100 dark:text-gray-800 border border-transparent rounded-md font-semibold text-xs text-white uppercase tracking-widest hover:bg-gray-700 active:bg-gray-900 focus:outline-none focus:border-gray-900 focus:ring focus:ring-gray-300 disabled:opacity-25 transition"
wire:click="addNewContact"
>
{{ __('Add') }}
</a>
<table id="contacts" class="table table-striped table-bordered table-hover">
<thead>
<td>Name</td>
<td>Email</td>
<td>Phone</td>
<td>Action</td>
</thead>
<tbody>
#foreach( $clientContacts as $contact )
<tr id="{{ $contact->id }}">
<td>
#livewire( 'inline-edit', ['item' => $contact, 'type' => 'title', 'number' => $client->id] )
</td>
<td>
#livewire( 'inline-edit', ['item' => $contact, 'type' => 'email', 'number' => $client->id] )
</td>
<td>
#livewire( 'inline-edit', ['item' => $contact, 'type' => 'phone_number', 'number' => $client->id] )
</td>
<td class="width-8">
<a
class="cursor-pointer"
wire:click="$emit( 'openModal', 'delete-contact',{{ json_encode(['contact_id' => $contact->id]) }} )"
>
<i class="fas fa-trash"></i>
</a>
</td>
</tr>
#endforeach
</tbody>
</table>
<p class="mt-1 text-sm text-gray-600">
Edit the cells above, click the bin to delete or the + to add a new row to populate with a new contact.
</p>
</div>
for completeness here is the popup layout blade file:
<!-- Page Heading-->
<header class="bg-white shadow">
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
#yield('header')
</h2>
</div>
</header>
<!-- Page Content -->
<main>
#if (Session::has('message'))
<!-- will be used to show any messages -->
<div class="alert alert-info">{{ Session::get('message') }}</div>
#endif
<div class="py-12">
<div class="bg-white overflow-hidden shadow-xl sm:rounded-lg">
#yield('content')
</div>
</div>
</main>
<!-- End Popup -->
Just to reiterate, the popup form is loading and the content in it is rendered correctly. The top part of the form works so the client is updated.
The inline edit livewire is working (well kind of as I've yet to implement the actual save of it's data but that isn't my issue.
The add button does nothing and nothing is shown in my dev toolbar (no network activity and nothing in the console tab) this is also the case with the delete buttons (which i have working elsewhere in the app - it should show a confirm box and if yes it then removes the contact.
thanks
*** EDIT ***
As an afterthought I have tried this with the client table commented ( the entire table in contacts-table.blade.php) so it just has the add link but it still doesn't work.
*** MORE INFO ***
I have tried removing from the popup and it works this way. Not what I wanted but It does work this way. Why would it not work in a popup?

Pagination with Laravel Blade

I'm trying to return data with a pagination. When I'm returning the data as paginate() I receive an error: htmlspecialchars() expects parameter 1 to be string, array given
My controller:
$tickets = Ticket::where('company_id', Auth::user()->company_id)->paginate(3);
Blade:
<table class="bg-white overflow-hidden table-auto w-full flex-row flex-no-wrap whitespace-nowrap">
<tr>
<th></th>
<th class="bg-white px-4 py-2">Updated at</th>
<th class="bg-white px-4 py-2">Case Title</th>
<th class="bg-white px-4 py-2">Manager</th>
<th class="bg-white px-4 py-2">Case ID</th>
<th class="bg-white px-4 py-2">Remaining</th>
<th class="bg-white px-4 py-2">Status</th>
</tr>
#foreach($tickets as $ticket)
<tr class="bg-gray-100 text-center">
<td class="px-2"><span class="text-blue-900 font-bold text-xs">
#if($ticket->isNew($ticket->created_at))
New
#endif
</span></td>
<td class="px-4">{{ $ticket->updated_at }}</td>
<td class="px-4 py-4">{{ $ticket->title }}</td>
<td class="px-4 py-4">{{ $ticket->getAdmin->first_name }} {{ $ticket->getAdmin->last_name }}</td>
<td class="px-4 py-4">{{ $ticket->id }}</td>
<td class="px-4 py-4">
#php
$dueDate = \Carbon\Carbon::parse($ticket->end_date);
#endphp
#if($dueDate->isPast())
<span class="text-red-600">Overdue</span>
#else
{{ $ticket->remaining_date() }} Days
#endif
</td>
<td class="px-4 py-4">
#if($ticket->status == 1)
<span class="bg-yellow-500 font-semibold text-white p-2 rounded">Active</span>
#endif
#if($ticket->status == 2)
<span class="bg-blue-500 font-semibold text-white p-2 rounded">Closed</span>
#endif
#if($ticket->status == 3)
<span class="bg-red-800 font-semibold text-white p-2 rounded">Late</span>
#endif
</td>
</td>
</tr>
#endforeach
</table>
{{!! $tickets->links() !!}}
I don't get it why I receive the error and have tried to Google around it. Why is the error appear and what's the solution?
Update your version of Laravel. This was a breaking bug for 8.78. They tried changing Pagination Navigation for screen readers, but it broke certain translation settings, so it was reverted back. The details are at https://github.com/laravel/framework/pull/39928
#taylorotwell #xanderificnl This actually introduces a bug that breaks Tailwind pagination out of the box, and it should ideally be reverted.
When attempting to use Tailwind pagination, I'm seeing the following: htmlspecialchars(): Argument #1 ($string) must be of type string, array given (View: /var/www/html/vendor/laravel/framework/src/Illuminate/Pagination/resources/views/tailwind.blade.php)
The line causing the issue:
<nav role="navigation" aria-label="{{ __('Pagination') }}" class="flex items-center justify-between">
This is due to Laravel shipping with a resources/lang/en/pagination.php file by default. This PR causes the array returned by the pagination language file to be passed into the __() method, which results in the parsing exception.

Laravel 8 Call to undefined method Illuminate\Database\MySqlConnection::tabel()

its laravel 8 course im getting this error while using query builder but with ORM its perfectly run well. when i comment this code and use another method for getting data with query builder in AllCat() method DB::table is running perfectly
Category Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Category;
use Auth;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
class CategoryController extends Controller
{
public function AllCat(){
$categories = DB::tabel('categories')
->join('users','categories.user_id','users.id')
->select('categories.*','users.name')
->latest()->paginate(5);
// $categories = Category::latest()->paginate(5);
//$categories = DB::table('categories')->latest()->paginate(5);
return view('admin.category.index',compact('categories'));
}
public function AddCat(Request $request){
$validated = $request->validate([
'category_name' => 'required|unique:categories|max:255',
],
[
'category_name.required' => 'Please Input Category Name',
'category_name.max' => 'Category Less Then 255Chars',
]);
Category::insert([
'category_name' => $request->category_name,
'user_id' => Auth::user()->id,
'created_at' => Carbon::now()
]);
// $category = new Category;
// $category->category_name = $request->category_name;
// $category->user_id = Auth::user()->id;
// $category->save();
// $data = array();
// $data['category_name'] = $request->category_name;
// $data['user_id'] = Auth::user()->id;
// DB::table('categories')->insert($data);
return redirect()->back()->with('success','Category Inserted Successfull');
}
}
Index.blade.php
<x-app-layout>
<x-slot name="header">
<h2 class="font-semibold text-xl text-gray-800 leading-tight">
All Category<b> </b>
</b>
</h2>
</x-slot>
<div class="py-12">
<div class="container">
<div class="row">
<div class="col-md-8">
<div class="card">
#if(session('success'))
<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>{{ session('success') }}</strong>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
#endif
<div class="card-header"> All Category
</div>
<table class="table">
<thead>
<tr>
<th scope="col">SL No</th>
<th scope="col">Category Name</th>
<th scope="col">User</th>
<th scope="col">Created At</th>
</tr>
</thead>
<tbody>
<!-- #php($i = 1) -->
#foreach($categories as $category)
<tr>
<th scope="row">{{ $categories->firstItem()+$loop->index }}</th>
<td>{{ $category->category_name }}</td>
<td>{{ $category->name }}</td>
<td>
#if($category->created_at == NULL)
<span class="text-danger">No Date Set</span>
#else
{{ Carbon\Carbon::parse($category->created_at)->diffforHumans() }}</td>
#endif
</tr>
#endforeach
</tbody>
</table>
{{ $categories->links() }}
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header">Add Category</div>
<div class="card-body">
<form action="{{ route('store.category') }}" method="POST">
#csrf
<div class="mb-3">
<label for="exampleInputEmail1" class="form-label">Category Name</label>
<input type="text" name="category_name" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
#error('category_name')
<span class="text-danger">{{ $message }}</span>
#enderror
</div>
<button type="submit" class="btn btn-primary">Add Category</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
Can you tell me what is wrong here
are you sure it is DB::tabel and not DB::table ?? It surely has to be DB::table

Categories