I'm trying to explain my question the best I can, so sorry if it's a bit confusing.
I have in my HTML Table, with table row, and table data, each row is filled with data from data base, and the table is automatically generated.
Example is below.
<thead>
<tr>
<th>Place ID</th>
<th>Map Name</th>
<th>Place Name</th>
<th>Price 1</th>
<th>Price 2</th>
<th>Price 3</th>
<th>Price 4</th>
#if (Auth::user()->role == "admin")
<th>Action</th>
<th>Booking</th>
#endif
</tr>
</thead>
<div id="preloader"></div>
<tbody id="hidden_table_processing">
#foreach ($places as $place)
<tr>
<td>{{ $place->place_id }}</td>
<td>{{ $place->map_name }}</td>
<td>{{ $place->place_name }}</td>
<td>{{ $place->price1 }} €</td>
<td>{{ $place->price2 }} €</td>
<td>{{ $place->price3 }} €</td>
<td>{{ $place->price4 }} €</td>
For booking table head, its filled with a quick booking button, that is supposed to get the Place ID of the data from the same raw, and shows it inside a popup, bellow is the code that creates the popup and fills the data.
<td>{{-- status print --}}
#if ($place->status==0)
<!-- Trigger the modal with a button -->
Quick Book
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<form method=POST action="{{ route('admin.place.quickbooking') }}">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Quick Book</h4>
</div>
<div class="modal-body">
#csrf
<div class="form-group">
<label for="usr">ID:</label>
<input type="text" class="form-control" value="{{ $place->place_id }}" id="qBookingID" name="qID" readonly>
<label for="usr">Full Name:</label>
<input type="text" class="form-control" value="{{ Auth::user()->name }}" id="qBookingFullName" name="qFullName">
<label for="usr">Number of Guests:</label>
<input type="number" class="form-control" id="qBookingNumberOfGuests" name="qNumberOfGuests">
<label for="usr">Number of Babies:</label>
<input type="number" class="form-control" id="qBookingNumberOfBabies" name="qNumberOfBabies">
<label for="usr">Check In:</label>
<input type="text" class="form-control" value="{{ session()->get('startingRange') }}" id="qBookingStartDate" name="qStartDate" readonly>
<label for="usr">Check Out:</label>
<input type="text" class="form-control" value="{{ session()->get('endingRange') }}" id="qBookingEndDate" name="qEndDate" readonly><br>
<label for="usr">Map Name: {{ $place->map_name }}</label><br>
<label for="usr" id="qBookingCreatorName" name="qCreatorName">Booked By: {{ Auth::user()->name }}</label>
</div>
{{-- Book --}}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" style="color: red; border: 1px solid red;" >Close</button>
<button type="submit" class="btn btn-default" style="color: green; border: 1px solid green;" type="submit">Book</button>
</div>
</div>
</form>
</div>
</div>
#endif
#if ($place->status==-1)
<p>Disabled</p>
#endif
#if ($place->status==2)
<p style="color:red;">Busy</p>
#endif
</td>
My problem is that the auto filled ID is only being filled by the First Data, as no matter which row I click on, the ID stays the same "the first ID from the table"
Any idea what might be causing this, or am I missing something very obvious?
THank you for your help.
For your case the better choice is pass the object place to a function using javascript, every time that you give click the modal appears with the data
that you want to edit or show.
Edit
#push('script')
<script>
$(document).ready(function () {
$('body').on('click', '#editModal', function (event) {
event.preventDefault();
let id = $(this).data('id');
console.log(id)
let name = {{ Auth::user()->name }}
let startdate = {{ session()->get('startingRange') }}
let enddate = {{ session()->get('endingRange') }}
let bookname = 'Booked By:' + name
$.get('place/' + id + '/edit', function (data) {
$("#qBookingID").val(data.data.place_id);
$(#qBookingFullName").val(name);
$("#qBookingStartDate").val(startdate);
$("#qBookingEndDate").val(enddate);
$("#qBookingCreatorName").val(bookname);
$('#Mymodal').modal('show');
})
});
});
</script>
#endpush
Related
At the most basic understanding, I've been trying to match the route and the form action. I think that I am doing it right but I wonder why the error keeps on showing. I may have missed something anywhere but I just really couldn't find it. Please help. With a very tight schedule, I need to complete this project.
When I submit the form it goes to this address.
index.blade.php
<tbody>
#foreach($payments as $payment)
<tr>
<td>{{ $payment->order->first_last_name }}</td>
<td>{{ $payment->order->business_name }}</td>
<td>{{ $payment->order->business_type }}</td>
<td>{{ $payment->order->phone_number }}</td>
<td>{{ $payment->order->postal_code }}</td>
<td>{{ $payment->order->email }}</td>
<td>{{ $payment->order->address }}</td>
<button type="button" class="btn btn-success btn-sm" data-action="{{ route('payments.send', $payment->id) }}" data-bs-toggle="modal" data-bs-target="#send" data-id="{{ $payment->id }}">اSend</button>
</td>
<td>
#php $status = $payment->status #endphp
<span class="{{ $status['bs_class'] }}">
{{ $status['label'] }}
</span>
</td>
<td>{{ $payment->accounting_code }}</td>
</tr>
#include('Admin.layouts.modal')
#endforeach
</tbody>
js
<script>
$('#send').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget);
var action = button.data('action');
var orderId = button.data('id');
var modal = $(this);
modal.find('form').attr('action', action);
document.getElementById("orderId").value = orderId;
});
</script>
modal.blade.php
<div class="modal fade" id="send" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="send" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form action="{{ route('payments.accounting', $payment->id) }}" method="post">
#csrf
#method('PUT')
<input type="hidden" id="orderId" value="">
<div class="modal-header">
<h5 class="modal-title" id="sendTitle">send</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<label for="accounting_code" class="form-label">کد accounting_code</label>
<input type="text" class="form-control" id="accounting_code" name="accounting_code">
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success">save</button>
</div>
</form>
</div>
</div>
</div>
web.php
Route::put('/payments/accounting/{payment}', [App\Http\Controllers\Admin\PaymentController::class,'accounting'])->name('payments.accounting');
PaymentController.php
public function accounting(Payment $payment, Request $request)
{
dd('hello');
$data = [
'accounting_code' => $request->post('accounting_code')
];
$payment->update($data);
return back();
}
Because your js code modal.find('form').attr('action', action) replaced the form action when showing the modal. Try to change the data-action from route payments.send to payments.accounting for the send button:
<button type="button" class="btn btn-success btn-sm" data-action="{{ route('payments.accounting', $payment->id) }}" data-bs-toggle="modal" data-bs-target="#send" data-id="{{ $payment->id }}">اSend</button>
Did you try it without naming the route?
delete this:
->name('payments.accounting')
and then in HTML form:
action="/payments/accounting"
I think you are mixing POST, PUT and GET Request here. Make sure you send your form with the correct method.
i have data returned from conntroller by ajax response in json format and I can print data in console.
but I want to display it in a table, how can I display it?
i made a search for solution but all solution write HTML code in controller function and return it as response, so is there any other solution
my controller
<?php
namespace App\Http\Controllers\backend;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Category;
class CategoryCtrl extends Controller
{
//function search - show categories live search
public function index(Request $request)
{
if($request->ajax())
{
$categories = Category::where('name','LIKE','%'.$request->cat_search."%")->orderBY('created_at','DESC')->get();
return Response()->json($categories);
}
else {
$categories = Category::orderBY('created_at','DESC')->get();
return view('backend.category.list')->withcategories($categories);
}
}
}
view
#extends('backend.layouts.app')
#section('content')
<input class="form-control" type="text" name="search" id="cat_search" placeholder="Category Search..." />
<table id="CategoriesTable" class="table table-striped table-vcenter js-dataTable-simple">
<thead>
<tr>
<th class="text-center w-5">#</th>
<th class="text-center">Name</th>
<th class="text-center hidden-xs">Icon</th>
<th class="text-center hidden-xs">Order</th>
<th class="text-center w-15">Status</th>
<th class="text-center">Created At</th>
<th class="text-center">Last Update</th>
<th class="text-center" style="width: 15%;">Actions</th>
</tr>
</thead>
<tbody>
#foreach ($categories as $key=>$category)
<tr>
<td class="text-center">{{ $key+1 }}</td>
<td class="text-center text-capitalize">{{ $category->name }}</td>
<td class="text-center hidden-xs"><i class="{{ $category->icon }} fa-lg"></i></td>
<td class="text-center hidden-xs">{{ $category->order }}</td>
<td class="text-center text-capitalize">
<span class="btn btn-sm btn-pill #if($category->status == 'active') btn-primary #else btn-warning #endif">{{ $category->status }}</span>
</td>
<td class="text-center">{{ $category->created_at->format("Y-m-d g:i a") }}</td>
<td class="text-center">{{ $category->updated_at->format("Y-m-d g:i a") }}</td>
<td class="text-center">
<div class="btn-group">
Edit
<button class="btn btn-app" data-toggle="modal" data-target="#{{ $category->name.$category->id }}">Delete</button>
</div>
<!-- Modal -->
<div class="modal fade" id="{{ $category->name.$category->id }}" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-card-header">
<div class="row">
<h4 class="col-md-10">Delete Category</h4>
<ul class="card-actions col-md-2">
<li>
<button data-dismiss="modal" type="button"><i class="ion-close"></i></button>
</li>
</ul>
</div>
</div>
<div class="card-block">
<p>Are you sure, you want to delete category (<span class="text-capitalize">{{ $category->name }}</span>) ?</p>
<p>If you delete category, you will delete all category's products too.</p>
<p>Notice: if you want to hide category, you can update it's status to not active instad of delete it.</p>
</div>
<div class="modal-footer">
<button class="btn btn-default" type="button" data-dismiss="modal">Close</button>
{!! Form::Open(['url' => route('category.delete', ['id' => $category->id]) ]) !!}
<button class="btn btn-app" type="submit" data-dismiss="modal"> Delete</button>
{!! Form::Close() !!}
</div>
</div>
</div>
</div>
<!-- End Modal -->
</td>
</tr>
#endforeach
</tbody>
</table>
#endsection
ajax code
<!-- Ajax code for category live search -->
<script type="text/javascript">
$('#cat_search').on('keyup',function(){
$value = $(this).val();
$.ajax({
type : 'get',
url : '{{ route('category.index') }}',
data:{'cat_search':$value},
dataType: 'json',
success:function(response){
//console.log(response);
});
});
})
</script>
the best way i can tell is to make a blade for that table and in controller just as usual return data to that view:
return view('your-blade-just-for-table')->with('data', $data);
and in your blade again as usual you render your data with laravel in your table
so laravel will return a blade to your ajax-success method
and in your success method you can do something like:
success: function (data) {
$('.list-group').html(data);
},
and wherever you want your table to be just put this div:
<div class="list-group" id="myFileContainer"></div>
I have this error:
Missing required parameters for [Route: admin.destroy] [URI: admin/{admin}]
That is the all view, and all variables,
i tried a lot but i don't know what's wrong if i change put the second parameter $info
this error appears
The DELETE method is not supported for this route. Supported methods: GET, HEAD, POST.
<div class="table-responsive">
<table class=" table ">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Code</th>
<th scope="col">Phone</th>
<th scope="col">Phone 2</th>
<th scope="col">Delete</th>
{{-- <th scope="col">email</th> --}}
</tr>
</thead>
<tbody>
#foreach ($infos as $info)
<tr>
<td>{{ $info->id }}</td>
<td>{{ $info->name}}</td>
<td>{{ $info->code }}</td>
<td>{{ $info->phone }}</td>
<td>{{ $info->phone2 }}</td>
<td>
<button class="btn btn-danger btn-sm" onclick="handleDelete ({{ $info->id }})">Delete
</button>
</td>
{{-- <td>{{ $info->email }}</td> --}}
</tr>
#endforeach
</tbody>
</table>
</div>
<form action="{{ route('admin.destroy',['admin' => $info])}}" method="post" id="deleteInfoForm">
#method('DELETE')
#csrf
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModal"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModal">Delete Info</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p class=" text-center text-bold">Are your sure ?</p>
</div>
<div class="modal-footer ">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No , Go back</button>
<button type="submit" class="btn btn-danger">Yes , Delete</button>
</div>
</div>
</div>
</div>
</form>
this is my delete function from AdminController
public function destroy(Info $admin)
{
// $info = Info::find($id);
$admin->delete();
// session()->flash('succuss', 'Info deleted successfully');
return redirect('/admin');
}
my routing list
| DELETE | admin/{admin} | admin.destroy | App\Http\Controllers\AdminController#destroy
The route expects parameter 2 to be the model of the id used for route model binding
Add it to the action in the form
<form action="{{ route('admin.destroy', ['admin' => $info]) }}"
Update
The form is outside the foreach loop and therefor $info is undefined
Pass the form inside the foreach instead
<div class="table-responsive">
<table class=" table ">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Code</th>
<th scope="col">Phone</th>
<th scope="col">Phone 2</th>
<th scope="col">Delete</th>
{{-- <th scope="col">email</th> --}}
</tr>
</thead>
<tbody>
#foreach ($infos as $info)
<tr>
<td>{{ $info->id }}</td>
<td>{{ $info->name}}</td>
<td>{{ $info->code }}</td>
<td>{{ $info->phone }}</td>
<td>{{ $info->phone2 }}</td>
<td>
<button class="btn btn-danger btn-sm" onclick="handleDelete ({{ $info->id }})">Delete
</button>
</td>
{{-- <td>{{ $info->email }}</td> --}}
</tr>
<tr>
<form action="{{ route('admin.destroy',['admin' => $info])}}" method="post" id="deleteInfoForm">
#method('DELETE')
#csrf
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModal"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModal">Delete Info</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p class=" text-center text-bold">Are your sure ?</p>
</div>
<div class="modal-footer ">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No , Go
back</button>
<button type="submit" class="btn btn-danger">Yes , Delete</button>
</div>
</div>
</div>
</div>
</form>
</tr>
#endforeach
</tbody>
</table>
</div>
Hope this helps
You're missing the data you want to delete in your form opening:
<form action="{{ route('admin.destroy', ['admin'=>$admin])}}" method="post" id="deleteInfoForm">
Before you do that, you have to pass the $admin variable to that view, in order to use it.
You're getting that error because your route expects to get an admin variable (admin/{admin}), but it isn't there when you call route in {{ route('admin.destroy')}}. You should provide it as the second parameter of the route method, in the keyed array format.
I installed a laravel script. but a page not worked and appear
Trying to get property 'name' of non-object (View:
/mylocal/core/resources/views/admin/users/servicePrice.blade.php)
for this line:
<th>{{ $item->service->name }}</th>
this is the file codes:
<div class="tile">
#include('admin.layouts.flash')
<h3 class="tile-title">Service Price Details</h3>
<form method="post" action="{{ route('store.service.price', $user_id) }}">
#csrf
#method('PUT')
<table class="table table-hover">
<tbody>
#foreach($items as $item)
<tr>
<th>{{ $item->category->name }}</th>
<th>{{ $item->service->name }}</th>
<td>
<div class="input-group">
<input type="hidden" name="id[]" value="{{ $item->id }}">
<input class="form-control" type="text" name="price[]" value="{{ $item->price }}">
<div class="input-group-append">
<span class="input-group-text">{{ $general->currency_symbol }}</span>
</div>
</div>
</td>
</tr>
#endforeach
</table>
<div class="tile-footer">
<button class="btn btn-primary btn-block btn-lg" type="submit"><i
class="fa fa-fw fa-lg fa-check-circle"></i>Save
</button>
</div>
</form>
</div>
Check your relation return a object or not.
<th>
#if($item->service)
{{ $item->service->name }}
#endif
</th>
You didn't share the content of array $items.Please make sure you have a service array in $items array and also make sure the name variable exists in service array.
and can you show me the result of this:
var_dump($items);
I have a view where some data is shown in a table with filtering option. When I choose an option of dropdown from the filtering part I want only table part will be refreshed and shown the updated data.
I have successfully filtered data from database using ajax. But can't show the filtered data (ajax response) in the table.
Filtering and table part of view.php
<div class="col-lg-8">
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title"> Search </h3>
</div>
<div class="panel-body">
<div class=" col-md-5">
<select class="form-control selectpicker searchField" id="selectTitleId_search">
<option value="">Select Title</option>
#foreach($titleData as $value)
<option value="{{$value->id}}">{{$value->name}}</option>
#endforeach
</select>
</div>
<div class="col-md-5">
<input type="text" id="datepicker" class="form-control searchField" placeholder="Select date">
<span class="add-on"><i class="icon-th"></i></span>
</div>
<div class="col-md-2">
<button type="button" class="btn btn-info" id="searchButton">
Search
</button>
</div>
</div>
</div>
</div>
<br/>
<div class="col-lg-9">
<div class="panel panel-info" >
<div class="panel-heading" style="padding:5px" >
<div class="panel-title">
<h3> Daily Income Report</h3>
</div>
</div>
<div class="panel-body" id="report">
<table class="table table-striped">
<thead>
<tr>
<th>Title Name</th>
<th>Amount</th>
<th>Date & Time</th>
</tr>
</thead>
<tbody style="font-size: 1.3em;">
<!-- Button trigger modal -->
<button type="button" class="btn btn-info pull-right addItem" data-toggle="modal" data-target="#exampleModal">
Add
</button>
#foreach($data as $value)
<tr class="itemList" data-toggle="modal" data-target="#exampleModal">
<input type="hidden" id="id" value="{{ $value->id }}">
<input type="hidden" id="titleId" value="{{ $value->title_id }}">
<td id="title_name" >
{{ $value->name }}
</td>
<td id="transaction_amount" >
{{ $value->amount }}
</td>
<td id="transaction_date">
{{ $value->created_at }}
</td>
</tr>
#endforeach
</tbody>
</table>
{{ $data->links() }}
</div>
</div>
</div>
ajax part of view.php
$(".searchField").change(function()
{
var title_id = $("#selectTitleId_search").val();
var date = $('#datepicker').val();
var token = $('input[name=_token]').val();
var report_type_id = 1;
// console.log(date);
$.ajax({
url:"/filter",
type: 'POST',
data: {_token :token, title_id : title_id, date : date, report_type_id : report_type_id},
success:function(msg)
{
console.log(msg);
$(".itemList").append(msg);
}
});
});
Now how can I send the ajax response data to foreach() loop of the table to show the filtered data
Use foreach loop in ajax success function and append data to list
$.ajax({
url:"/filter",
type: 'POST',
data: {_token :token, title_id : title_id, date : date, report_type_id : report_type_id},
success:function(msg){
console.log(msg);
msg.forEach(function(item) {
// do something with `item`
$(".itemList").append(item);
});
}
});