Original code
<tbody id="table">
#foreach($services as $service)
<tr>
<td colspan="7" class="theme-bg" style="color:white">{{ $service->name }}
#if($service->brand != '')
<span style="font-family:'Font Awesome 5 Brands','FontAwesome';">&#x{{ $service->brand }};</span>
#endif
</td>
</tr>
<tr>
<th>#lang('general.package_id')</th>
<th>#lang('general.name')</th>
<th>#lang('general.price_per_item') {{ getOption('display_price_per') }}</th>
<th>#lang('general.minimum_quantity')</th>
<th>#lang('general.maximum_quantity')</th>
<th>#lang('general.description')</th>
</tr>
#foreach($packages as $package)
#if(isset($categories[$service->id]) && in_array($package->category_id,explode(',',$categories[$service->id])))
<tr>
<td>{{ $package->id }}</td>
<td>{{ $package->name }}</td>
<td>
#php
$price = isset($userPackagePrices[$package->id]) ? $userPackagePrices[$package->id] : $package->price_per_item;
#endphp
{{ getOption('currency_symbol') . number_format(($price * getOption('display_price_per')),2, getOption('currency_separator'), '') }}
</td>
<td>{{ $package->minimum_quantity }}</td>
<td>{{ $package->maximum_quantity }}</td>
<td style="white-space: pre-line">{{ $package->description }}</td>
</tr>
#endif
#endforeach
#endforeach
</tbody>
I was trying to replace "{{ $package->description }}" with a button to show the content in a new popup, using this.
<tbody id="table">
#foreach($services as $service)
<tr>
<td colspan="7" class="theme-bg" style="color:white">{{ $service->name }}
#if($service->brand != '')
<span style="font-family:'Font Awesome 5 Brands','FontAwesome';">&#x{{ $service->brand }};</span>
#endif
</td>
</tr>
<tr>
<th>#lang('general.package_id')</th>
<th>#lang('general.name')</th>
<th>#lang('general.price_per_item') {{ getOption('display_price_per') }}</th>
<th>#lang('general.minimum_quantity')</th>
<th>#lang('general.maximum_quantity')</th>
<th>#lang('general.description')</th>
</tr>
#foreach($packages as $package)
#if(isset($categories[$service->id]) && in_array($package->category_id,explode(',',$categories[$service->id])))
<tr>
<td>{{ $package->id }}</td>
<td>{{ $package->name }}</td>
<td>
#php
$price = isset($userPackagePrices[$package->id]) ? $userPackagePrices[$package->id] : $package->price_per_item;
#endphp
{{ getOption('currency_symbol') . number_format(($price * getOption('display_price_per')),2, getOption('currency_separator'), '') }}
</td>
<td>{{ $package->minimum_quantity }}</td>
<td>{{ $package->maximum_quantity }}</td>
<td><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">+ Description</button></td>
</tr>
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" 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>
</div>
<div class="modal-body">
<p style="white-space: pre-line">{{ $package->description }}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
#endif
#endforeach
#endforeach
</tbody>
But I'm getting same content on each button, but the content must be different because each row have won service name + description. This description must be different on the popup box.
The problem might be caused by your modal-ids. Since all your modals have the id "exampleModalCenter" your Button probably only opens the first one it can find (since ids are supposed to be unique).
If you would dynamicly change your modal-ID and the corresponding Button-target
Example with adding your package-ID:
<tbody id="table">
#foreach($services as $service)
<tr>
<td colspan="7" class="theme-bg" style="color:white">{{ $service->name }}
#if($service->brand != '')
<span style="font-family:'Font Awesome 5 Brands','FontAwesome';">&#x{{ $service->brand }};</span>
#endif
</td>
</tr>
<tr>
<th>#lang('general.package_id')</th>
<th>#lang('general.name')</th>
<th>#lang('general.price_per_item') {{ getOption('display_price_per') }}</th>
<th>#lang('general.minimum_quantity')</th>
<th>#lang('general.maximum_quantity')</th>
<th>#lang('general.description')</th>
</tr>
#foreach($packages as $package)
#if(isset($categories[$service->id]) && in_array($package->category_id,explode(',',$categories[$service->id])))
<tr>
<td>{{ $package->id }}</td>
<td>{{ $package->name }}</td>
<td>
#php
$price = isset($userPackagePrices[$package->id]) ? $userPackagePrices[$package->id] : $package->price_per_item;
#endphp
{{ getOption('currency_symbol') . number_format(($price * getOption('display_price_per')),2, getOption('currency_separator'), '') }}
</td>
<td>{{ $package->minimum_quantity }}</td>
<td>{{ $package->maximum_quantity }}</td>
<td><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter-{{ $package->id }}">+ Description</button></td>
</tr>
<div class="modal fade" id="exampleModalCenter-{{ $package->id }}" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" 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>
</div>
<div class="modal-body">
<p style="white-space: pre-line">{{ $package->description }}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
#endif
#endforeach
#endforeach
</tbody>
Related
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.
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">
When refresh the page then my content broken, I couldn't understand why this happening. Some time's my whole page broken. Please help me to solve this problem.
Bootstrap v: 3.3.7
laravel v: 5.4
Here is my code:
#extends('layouts.admin-user.main')
#section('main_content')
<div class="ptb-80">
<div class="users-mang">
<div class="container">
<div class="row">
<div class="col-md-12">
#include('layouts.success')
#include('layouts.errors')
<h1>User Management</h1>
<div class="portlet-title">
<div class="caption font-dark">
#if(isset($searchData))
<a href="#if (isset($companyData->company_name)){{ url($companyData->company_name.'/user-list') }}#endif"
class="btn btn-info">Back to User List</a>
#else
<a href="#if (isset($companyData->company_name)){{ url($companyData->company_name.'/user') }}#endif"
class="btn btn-success">Add User</a>
Import User
#endif
</div>
<div class="tools"> </div>
</div>
<table class="table table-striped table-bordered table-hover" id="sample_1">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Group</th>
<th>Action</th>
</tr>
</thead>
<tbody>
#if(isset($allData) && !$allData->isEmpty())
<?php $i = 0; ?>
#foreach($allData as $data)
<?php $i++; ?>
<tr>
<td>{{ $i }}</td>
<td>{{ $data->name }}</td>
<td>{{ $data->email }}</td>
<td>{{ $data->phone }}</td>
<td>{{ $data->group_id }}</td>
<td>
<a href="#if (isset($companyData->company_name)){{ url($companyData->company_name.'/user/contact/'.$data->id) }}#endif"
class="btn btn-info">Contact</a>
<a href="#if (isset($companyData->company_name)){{ url($companyData->company_name.'/user/edit/'.$data->id) }}#endif"
class="btn btn-primary">Edit</a>
<a href="#if (isset($companyData->company_name)){{ url($companyData->company_name.'/user/delete/'.$data->id) }}#endif"
onclick="return confirm('Are you sure?')"
class="btn btn-danger">Delete</a>
</td>
</tr>
#endforeach
#else
<tr>
<td colspan="6" class="text-center"> No available data.</td>
</tr>
#endif
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
#endsection
Here is a broken content screenshot:
Thanks so much.
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.
im trying to divide my items by category with javascript and twig, so after bringing all the products from the database i dont know how can i separate products with {% for %}. this is my twig code:
<div class="col-sm-4" itemscope itemtype="http://schema.org/Product">
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title truncate">Categoria:{{ producto.idCategoria }}</h5>
</div>
<div class="panel-body">
Nombre:{{ producto.producto }}
<img src="{{ asset('bundles/savainventario/images/'~producto.filePersistencePath ) }}"
alt="404 file not found" class="img-thumbnail"/>
</div>
<div class="panel-footer">
<div class="container-fluid">
{#Precio#}
<span itemprop="price">
Precio:{{ producto.precio }}.Bsf
</span>
{#Form#}
<form class="form-inline" role="form" method="get"
action={{ path('sava_inventario_addcart', {'id': producto.idProducto }) }}>
<div class="form-group">
<input class="btn btn-default" type="submit" value="Agregar">
</div>
{#Ver mas#}
<!-- Button trigger modal -->
</form>
<button class="btn btn-primary btn-sm" data-toggle="modal"
data-target="#myModal{{ producto.idProducto }}">
Ver mas...
</button>
<!-- Modal -->
<div class="modal fade" id="myModal{{ producto.idProducto }}" tabindex="-1" role="dialog"
aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span
aria-hidden="true">×</span><span class="sr-only">Close</span>
</button>
<h4 class="modal-title" id="myModalLabel">{{ producto.producto }}</h4>
</div>
<div class="modal-body">
<!-- Datos productos -->
<table class="table table-striped">
<tr>
<td>Nombre:</td>
<td>{{ producto.producto }}</td>
</tr>
<tr>
<td>Image:</td>
<td>
<img src="{{ asset('bundles/savainventario/images/'~producto.filePersistencePath ) }}"
alt="404 file not found"/></td>
</tr>
<tr>
<td>Descripcion</td>
<td>{{ producto.descripcionProducto }}</td>
</tr>
<tr>
<td>Precio:</td>
<td>{{ producto.precio }}</td>
</tr>
<tr>
<td>Cantidad:</td>
<td>{{ producto.cantidad }}</td>
</tr>
<tr>
<td>Categoria:</td>
<td>{{ producto.idCategoria.categoria }}</td>
</tr>
<tr>
<td>Modelo:</td>
<td>{{ producto.idModelo.modelo }}</td>
</tr>
<tr>
<td>Video:</td>
<td>
<iframe width="433" height="315"
src="//www.youtube.com/embed/tQShyqnRx3s?list=PLw4rBoBPv1Vbq16M4SFkJPZj08FMaaR-8"
frameborder="0" allowfullscreen></iframe>
</td>
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div> {#footer end#}
</div>
</div>
{% endif %}
{% endfor %}
</div>
</div>
my question is how can i separate my items by category, in one category i print it in one div container, in another div container i add products from another category and so on.
If your entites are setup properly this shouldnt be hard:
//Contoller
/**
* #Template()
*/
public function showProductsByCategory()
{
$categories = $this->getDoctrine()->getManager()
->getRepository("NamespacedBundle:Category")->findAll();
return array(
'categories' => $categories
);
}
Assuming your categories know about products
//Category Entity
/**
* #ORM\OneToMany(targetEntity="Product", mappedBy="category")
*/
protected $products;
And your products are tied to the category
//Product Entity
/**
* #ORM\ManyToOne(targetEntity="Category", inversedBy="products")
* #ORM\JoinColumn(name="category", referencedColumnName="category_id")
*/
protected $category;
Then your twig could be something based on:
//Sample Twig
{% for category in categories %}
<div class="container">
<h1>{{category.name}}</h1>
<ul>
{% for product in category.products %}
<li>{{product.name}}</li>
{% endfor %}
</div>
{% endfor %}