The following is my controller Wordings_test.php code
The issue is I am not able to print #wording.product. Even though, I can print #wording.template_name.
Thanks
class Wordings_test extends Controller{
function show($f3)
{
$wordings = Wordings::all()->orderBy('id')->select()->toArray();
foreach ($wordings as $wording) {
$wording['product'] = ProductTypes::where(['id' =>
$wording['product_type_id']])->select()->getAttribute('name');
}
$f3->set('wordings',$wordings);
$this->render('admin/wordings/view')
}
The following is the template code view.html
<i class="fa fa-user-plus"></i> Add New Brokerage Head Group
<div class="row">
<div class="form-group">
<div class="tab-content">
<div id="brokerageheadlist" class="active in tab-pane fade">
<table class="table table-bordered adminTable" id="brokerageheadList">
<thead>
<tr>
<th>Wording</th>
<th>Product Type</th>
<th style="width:140px;">Controls</th>
</tr>
</thead>
<tbody>
<repeat group="{{ #wordings }}" value="{{ #wording }}">
<tr>
<td>{{ #wording.template_name }}</td>
<td>
{{ #wording.product }}
</td>
<td>
<a class="btn btn-sm btn-info showLoader" href="/admin/wordings/edit-wordings/{{ #wording.id }}">Edit</a>
<button type="button" class="btn btn-danger btn-sm" data-toggle="modal" data-target="#myModal{{#brokeragehead.id}}">Delete</button>
<div id="myModal{{#brokeragehead.id}}" class="modal fade" role="dialog">
<div class="modal-dialog">
Related
I created one table that list items, and I added two buttons(edit and delete) so, the button edit is working, but the button delete is not working, and I'm making me carzy because I don't find the error. this is the table:
<table id="datatable" class="table align-items-center table-flush">
<thead class="thead-light">
<tr>
<th>text</th>
<th class="disabled-sorting" width="10%"></th>
<th class="disabled-sorting" width="10%"></th>
</tr>
</thead>
<tbody>
#foreach($Items as $item)
<tr>
<td>{{ $item->text }}</td>
<td><a href="{{ route('ItemsController.edit', $item->id) }}" class="btn btn-primary btn-fab btn-icon btn-round" title="Edit">
<i class="fa fa-edit"></i></a>
</td>
<td>
<a href="#" class="btn btn-primary btn-fab btn-icon btn-round btn-delete" title="Delete" data-id="{{ $item->id }}" data-toggle="modal" data-target="#modal-default" data-route="{{ route('ItemsController.destroy', $item->id) }}" data-title="{{ $item->id }}">
<i class="fa fa-trash"></i></a>
</td>
</tr>
#endforeach
</tbody>
</table>
the modal is:
<div class="modal fade" id="modal-default" tabindex="-1" role="dialog" aria-labelledby="modal-default" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Delete Item</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Delete?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<form class="" action="" method="post">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button type="submit" class="btn btn-danger" name="button">yes, delete</button>
</form>
</div>
</div>
</div>
</div>
javascript data:
<script>
$(document).on('click', '.btn-delete', function(){
$('.modal form').attr('action', $(this).data('route'));
$('#ModalLabel').text($(this).data('title'));
})
</script>
and controller function destroy
public function destroy(Items $item) {
$item->delete();
return redirect()->route('items.index')->with('success', 'Deleted Success');
}
I checked it line by line, and I don't know what I'm wrong, please help me
Many times thanks for getting into this.
You need to trigger your modal from JS.
If it is bootstrap 4 then just simply open it using,
$('.modal form').attr('action', $(this).data('route'));
$('#ModalLabel').text($(this).data('title'));
//This will trigger modal
$("#modal-default").modal();
If it is bootstrap 5 then just simply open it using,
$('.modal form').attr('action', $(this).data('route'));
$('#ModalLabel').text($(this).data('title'));
//This will trigger modal
modal = new bootstrap.Modal(document.getElementById("modal-default"));
modal.show();
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 am using the button to display the details of the particular person using the data-toggle="modal" but the button is not performing any action. When I click the button I am not able to display any details of the user.
Route:
Route::get('document', 'PatientController#show');
Controller:
public function show()
{
$patient_user=patient_user::all();
return view('document')->with('patient_user',$patient_user);
}
View:
<form id="myForm" method="get">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="panel-body">
<table class="table table-striped table-bordered table-hover table-full-width" id="sample_1">
<thead>
<tr>
<th>Patient ID</th>
<th>Patient Name</th>
<th>Full Name</th>
<th>DOB</th>
<th>Ref. Name</th>
<th>Payment</th>
<th>Doc Status</th>
<th>Appointment</th>
<th>Action</th>
</tr>
</thead>
#foreach($patient_user as $key=>$row)
<tbody>
<tr>
<td>{{$row->patient_id}}</td>
<td>{{$row->patient_firstname}}</td>
<td>{{$row->patient_firstname}} {{$row->patient_lastname}}</td>
<td>{{$row->dob}}</td>
<td>{{$row->refering_physician_name}}</td>
<td>{{$row->dob}} </td>
<td>{{$row->dob}}</td>
<td>{{$row->app_date}}</td>
<td class="center">
<div class="visible-md visible-lg hidden-sm hidden-xs">
<i class="fa fa-edit"></i>
<i class="fa fa-eye"></i>
<i class="fa fa-times fa fa-white"></i>
</div>
</td>
</tr>
</tbody>
#endforeach
</table>
</div>
<div id="static" class="modal fade" tabindex="-1" data-backdrop="static" data-keyboard="false" style="display: none;">
<div class="modal-body">
<h4><i>Patient Details</i></h4>
</div>
<div class="modal-body">
<div class="col-md-12">
<div class="col-md-6">First Name</div>
<div class="col-md-5" id="fname"> {{ $row->patient_firstname}} </div>
</div>
<br>
<div class="col-md-12">
<div class="col-md-6">Middle Name</div>
<div class="col-md-5" id="mname"> {{ $row->middle_name}} </div>
</div>
<br>
<div class="col-md-12">
<div class="col-md-6">Last Name</div>
<div class="col-md-5" id="lname"> {{ $row->patient_lastname}} </div>
</div>
</div>
</div>
</form>
jquery:
<script type="text/javascript">
$('#static').on('show', function(e)
{
e.preventDefault();
var link = e.relatedTarget(),
modal = $(this),
patient_firstname = link.data("patient_firstname"),
middle_name = link.data(middle_name),
patient_lastname = link.data("patient_lastname"),
modal.find("#fname").val(patient_firstname);
modal.find("#mname").val(middle_name);
modal.find("#lname").val(patient_lastname);
});
</script>
where #static is my modal Id and the value within find are the id's of the particular fields and val are the database values.
The problem is that you're requesting data from attributes that are not set.
patient_firstname = link.data("patient_firstname"),
The above part is trying to retrieve the value of the attribute data-patient_firstname. Since the original link does not have this attribute there won't be any data.
Change
<i class="fa fa-eye"></i>
Into
<a href='#' data-toggle="modal"
data-patient_firstname="{{$row->patient_firstname}}" <-- do this for all requested vars
class="btn btn-xs btn-green tooltips" data-id="{{ $row->patient_id}}" data-target="static" onclick="pat_det{{ $row->patient_id }}" data-placement="top" data-original-title="View" id="pat_det"><i class="fa fa-eye"></i></a>
That way the data-* attributes will be availble.
I have a html table with a list of cars from my database, I wish to select a row in the table to open a bootstrap modal with the right id from the db table. The button "Change Status" opens the modal showing the car, numberplate and status. But it only fetches the latest id. When I move the modal to the top, It fetches the first id on the table. I'm baffled on what I can do to fix this.
Here's my html code:
#if (isset($results))
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th width="15%"></th>
<th>#</th>
<th>Numberplate</th>
<th>Status</th>
<th>Added</th>
<th>Changed</th>
<th>Change</th>
</tr>
</thead>
#foreach ($results as $result)
<tbody>
<tr>
<td></td>
<td>{{ $result->id }}</td>
<td>{{ $result->LicencePlate }}</td>
<td>{{ $result->Status }}</td>
<td>{{ $result->created_at }}</td>
<td>{{ $result->updated_at }}</td>
<td>
<button type="button" class="btn btn-secondary btn-sm" style="background-color: #000; color: #FFF;" data-toggle="modal" data-target="#myModal">Change Status</button>
</td>
</tr>
</tbody>
#endforeach
#endif
</table>
</div>
#if (isset($cars))
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th width="15%"></th>
<th>#</th>
<th>Numberplate</th>
<th>Status</th>
<th>Added</th>
<th>Changed</th>
<th>Change</th>
</tr>
</thead>
#foreach ($cars as $car)
<tbody>
<tr>
<td></td>
<td>{{ $car->id }}</td>
<td>{{ $car->LicencePlate }}</td>
<td>{{ $car->Status }}</td>
<td>{{ $car->created_at }}</td>
<td>{{ $car->updated_at }}</td>
<td>
<button type="button" class="btn btn-secondary btn-sm" style="background-color: #000; color: #FFF;" data-toggle="modal" data-target="#myModal">Change Status</button>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
#endif
</div>
</div>
</div>
#if (isset($cars))
#foreach ($cars as $car)
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<p>ID: {{ $car->id }}</p>
<p>Numberplate: {{ $car->LicencePlate }}</p>
<p>Status: {{ $car->Status }}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
#endforeach
#endif
Not completely sure if a special method in my controller or you need to see my model. If so I can edit this question.
Now in your case the modal id #myModal is repeated inside the loop. Change the modal id and button id like,
<button type="button" class="btn btn-secondary btn-sm" style="background-color: #000; color: #FFF;" data-toggle="modal" data-target="#myModal_{{ $car->id }}">Change Status</button>
And modal
<div class="modal fade" id="myModal_{{ $car->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<!--Modal content here -->
<div>
FYI: Use the single loop for both button and modal.