So I have this forelse that displays all the variants, now what I want to happen is that, if there is no variant. the submit button will be disabled.
<table class="table table-striped">
<thead>
<tr>
<th class="col-sm-5">Name</th>
<th class="col-sm-1">Default?</th>
<th class="col-sm-2 text-right">Retail Price</th>
<th class="col-sm-2 text-right">Quantity</th>
<th class="col-sm-2"></th>
</tr>
</thead>
<tbody>
#forelse ($product->variants as $index => $variant)
<tr>
<td>{{ $variant->name }}</td>
<td>{{ $variant->is_default ? 'Yes' : 'No' }}</td>
<td class="text-right">{{ number_format($variant->retail_price, 2) }} {{ $variant->price_currency }}</td>
<td class="text-right">{{ number_format($variant->quantity, 0) }}</td>
<td>Edit</td>
</tr>
#empty
<tr>
<td colspan="5">No variants found</td>
<?php $varbutton = 'disabled';?>
</tr>
#endforelse
</tbody>
</table>
here is the button
<div class="panel-footer">
<button class="btn btn-default" type="submit"<?php $varbutton; ?>>Update Store</button>
</div>
Is it possible using php and html in the blade alone or do I have to do it in the controller?
You should be using blade in your button:
<div class="panel-footer">
<button class="btn btn-default" type="submit" {{ $varbutton }}>Update Store</button>
</div>
Also please note that there needs to be a space after "submit".
Or, if you don't want that space when the button is not disabled, use:
<?php $varbutton = ' disabled';?>
<div class="panel-footer">
<button class="btn btn-default" type="submit"{{ $varbutton }}>Update Store</button>
</div>
Related
I need to go to my bill list page but this error is stopping me: 'Trying to get property 'name' of non-object'
My route:
Route::get('bill/{id?}',[
'as'=>'bill',
'uses'=>'PageController#editBill'
]);
My Controller:
public function editBill($id)
{
$customerInfo=DB::table('customer')->select('customer.id','customer.name','customer.created_at','customer.phone_number','customer.address','customer.note','bills.total','customer.email')->join('bills','bills.id_customer','=','customer.id')->where('customer.id', '=', $id)->first();
$billInfo=Bill::where('id',$id)->get();
return view('admin.editBill',compact('customerInfo','billInfo'));
}
My view:
<section class="content">
<!-- Default box -->
<div class="box">
<div class="box-header with-border">
<div class="row">
<div class="col-md-12">
<div class="container123 col-md-6" style="">
<h4></h4>
<table class="table table-bordered">
<thead>
<tr>
<th class="col-md-4">Customer Info</th>
<th class="col-md-6"></th>
</tr>
</thead>
<tbody>
<tr>
<td>Customer name</td>
<td>{{ $customerInfo->name }}</td>
</tr>
<tr>
<td>Date Order</td>
<td>{{ $customerInfo->created_at }}</td>
</tr>
<tr>
<td>Phone Number</td>
<td>{{ $customerInfo->phone_number }}</td>
</tr>
<tr>
<td>Address</td>
<td>{{ $customerInfo->address }}</td>
</tr>
<tr>
<td>Email</td>
<td>{{ $customerInfo->email }}</td>
</tr>
<tr>
<td>Note</td>
<td>{{ $customerInfo->note }}</td>
</tr>
</tbody>
</table>
</div>
<table id="myTable" class="table table-bordered table-hover dataTable" role="grid" aria-describedby="example2_info">
<thead>
<tr role="row">
<th class="sorting col-md-1" >Id</th>
<th class="sorting_asc col-md-4">Product name</th>
<th class="sorting col-md-2">Quantity</th>
<th class="sorting col-md-2">Unit_price</th>
</thead>
<tbody>
#foreach($billInfo as $key=>$bill)
<tr>
<td>{{ $key+1 }}</td>
<td>{{ $bill->product }}</td>
<td>{{ $bill->quantity }}</td>
<td>{{ number_format($bill->unit_price) }} VNĐ</td>
</tr>
#endforeach
<tr>
<td colspan="3"><b>Total</b></td>
<td colspan="1"><b class="text-red">{{ number_format($customerInfo->total) }} đ</b></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="col-md-12">
<form action="{{route('pdf',$customerInfo->id)}}" method="GET">
<input type="hidden" name="_method" value="PUT">
{{ csrf_field() }}
<div class="col-md-8"></div>
<div class="col-md-4">
<div class="form-inline">
<label>Delivery Status: </label>
<select name="status" class="form-control input-inline" style="width: 200px">
<option value="1">None</option>
<option value="2">On going</option>
<option value="2">Delivered</option>
</select>
<input type="submit" method="get" value="Print" class="btn btn-primary">
</div>
</div>
</form>
</div>
</div>
</div>
</section>
The bill detail list is working fine but the customers detail is not
I tried others way like {{$customer->name ?? ''}} and it did't give an error anymore but it doesn't show any data
I have a modal pop out when pressing a button. Problem is, how do pass the value to the modal?
My table as shown in figure below. As you can see each row have different id. I wanted to get the id of a particular row after pressed the button.
The problem is how to display data in to bootstrap modal according to id. Thanks in advance.
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>ردیف</th>
<th>مقطع تحصیلی</th>
<th>رشته تحصیلی</th>
<th>تاریخ اخذ مدرک</th>
<th>جزییات بیشتر</th>
</tr>
</thead>
<tbody>
#foreach($user->educationals as $educational)
<tr>
<td class="fw-normal">{{ $educational->id }}</td>
<td class="fw-normal">{{ $educational->grade }}</td>
<td class="fw-normal">{{ $educational->major }}</td>
<td class="fw-normal">{{ $educational->end }}</td>
<td><a class="btn btn-link" data-bs-toggle="modal" data-bs-target="#educationals{{ $educational->id }}">جزییات بیشتر</a></td>
</tr>
#endforeach
</tbody>
</table>
</div>
#if(isset($educational))
<div class="modal fade" id="educationals{{ $educational->id }}" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="educationals{{ $educational->id }}" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="educationals{{ $educational->id }}">درخواست</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<table class="table">
<tr>
<th>مقطع تحصیلی</th>
<td>{{ $educational->grade }}</td>
</tr>
<tr>
<th>رشته تحصيلي</th>
<td>{{ $educational->major }}</td>
</tr>
<tr>
<th>معدل</th>
<td>{{ $educational->avg }}</td>
</tr>
<tr>
<th>تاريخ شروع</th>
<td>{{ $educational->start }}</td>
</tr>
<tr>
<th>تاريخ اخذ مدرك</th>
<td>{{ $educational->end }}</td>
</tr>
<tr>
<th>موسسه دريافت اخذ مدرك</th>
<td>{{ $educational->docPlaceName }}</td>
</tr>
<tr>
<th>عنوان پايان نامه / رساله</th>
<td>{{ $educational->thesisTitle }}</td>
</tr>
<tr>
<th>مدارك</th>
<td>{{ $educational->upload_doc }}</td>
</tr>
<tr>
<th>کشور محل دريافت مدرك</th>
<td>{{ $educational->docPlaceCountry }}</td>
</tr>
<tr>
<th>شهر محل دريافت مدرك</th>
<td>{{ $educational->docPlaceCity }}</td>
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">اوکی</button>
</div>
</div>
</div>
</div>
#else
<div class="alert alert-warning text-center" role="alert">
اطلاعاتی وجود ندارد.
</div>
#endif
You have many options but I suggest you to use javascript in any form you prefer. But if you don't want to use javascript, you should make model for each of table rows.
#foreach($user->educationals as $educational)
<div class="modal fade" id="educationals{{ $educational->id }}" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="educationals{{ $educational->id }}" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="educationals{{ $educational->id }}">درخواست</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<table class="table">
<tr>
<th>مقطع تحصیلی</th>
<td>{{ $educational->grade }}</td>
</tr>
<tr>
<th>رشته تحصيلي</th>
<td>{{ $educational->major }}</td>
</tr>
<tr>
<th>معدل</th>
<td>{{ $educational->avg }}</td>
</tr>
<tr>
<th>تاريخ شروع</th>
<td>{{ $educational->start }}</td>
</tr>
<tr>
<th>تاريخ اخذ مدرك</th>
<td>{{ $educational->end }}</td>
</tr>
<tr>
<th>موسسه دريافت اخذ مدرك</th>
<td>{{ $educational->docPlaceName }}</td>
</tr>
<tr>
<th>عنوان پايان نامه / رساله</th>
<td>{{ $educational->thesisTitle }}</td>
</tr>
<tr>
<th>مدارك</th>
<td>{{ $educational->upload_doc }}</td>
</tr>
<tr>
<th>کشور محل دريافت مدرك</th>
<td>{{ $educational->docPlaceCountry }}</td>
</tr>
<tr>
<th>شهر محل دريافت مدرك</th>
<td>{{ $educational->docPlaceCity }}</td>
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">اوکی</button>
</div>
</div>
</div>
</div>
#endforeach
#extends('layouts.app')
#section('content')
<body>
<button class="btn" onclick="deleteSelected()">delete</button>
<table class="table">
<thead>
<tr>
<th scope="col">
<input type="checkbox" id="all" onclick="chkd()">
</th>
<th scope="col">id</th>
<th scope="col">title</th>
<th scope="col">Paragraph</th>
</tr>
</thead>
#foreach ($categories as $categorie)
<tbody>
<tr>
<td>
<input type="checkbox" class="ss" value="{{ $categorie->id }}" onclick="deleteSelected()">
</td>
<th scope="row">{{ $categorie->id }}</th>
<td>{{ $categorie->Title }}</td>
<td>{{ $categorie->Paragraph }}</td>
<form action={{ route('categorie.destroy', $categorie->id) }} method="POST">
#csrf
#method('DELETE')
<td>
<button id="deleteRow" class="btn btn-danger" type="submit" style="display: none">
delete
</button>
</form>
<button class="btn btn-warning"> <a href={{ route('edit', $categorie->id) }}>edit</a> </button>
</td>
</tr>
</tbody>
#endforeach
</table>
</body>
#endsection
that is my view , when I check one of my checkbox and press the button delete I want this row to be deleted or when I checked all I want to delete all row
I think html input must inside the form. How about moving code like this:
#foreach ($categories as $categorie)
<tbody>
<tr>
<td>
<form action={{ route('categorie.destroy', $categorie->id) }} method="POST">
#csrf
#method('DELETE')
<input type="checkbox" class="ss" value="{{ $categorie->id }}" onclick="deleteSelected()">
<button id="deleteRow" class="btn btn-danger" type="submit" style="display: none">
delete
</button>
</form>
</td>
<th scope="row">{{ $categorie->id }}</th>
<td>{{ $categorie->Title }}</td>
<td>{{ $categorie->Paragraph }}</td>
<td><button class="btn btn-warning"> <a href={{ route('edit', $categorie->id) }}>edit</a> </button></td>
</tr>
</tbody>
#endforeach
But, I don't know this is can fix your case or not. I can't see the whole code
I am fetching data to a table from mysql database using php and jquery. But I want to keep the "details" column hidden, which I want should be slide down(appear ) in the corresponding table row after clicking a button named "show details". The following Image may clear my thought:
The jquery Code I am using for slide down is :
$(document).ready(function(){
$("#get_details").click(function(){
$("#get_details_button").slideToggle("slow");
});
});
The code I am using to fetch data is :
$sub_array = array();
$sub_array[] = $row["id"];
$sub_array[] = $row["product_name"].'<p id="get_details">'.$row["details"].'</p>';
$sub_array[] = '<button type="button" name="get_details_button" id="get_details_button" class="btn btn-success btn-xs get_details_button">Get Details</button>';
$data[] = $sub_array;
}
Please feel free to ask for any additional code if you need.
the html part is here :
<table id="user_data" class="table table-bordered table-striped">
<thead>
<tr>
<th width="30%">Image</th>
<th width="50%">Product Name</th>
<th width="20%">get Details</th>
</tr>
</thead>
</table>
You need to use class for p tag then whenever button is clicked use $(this).closest('tr').find(".get_details") to get p tag and show/hide same
Demo Code :
$(document).ready(function() {
//onclick of button
$(".get_details_button").click(function() {
//get p tag and show/hide it
$(this).closest('tr').find(".get_details").slideToggle("slow");
});
});
.get_details {
display: none
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="user_data" class="table table-bordered table-striped">
<thead>
<tr>
<th width="30%">Image</th>
<th width="50%">Product Name</th>
<th width="20%">get Details</th>
</tr>
</thead>
<tr>
<td>1
</td>
<td>Soemthig,,
<!--use class-->
<p class="get_details">Soemthing.....</p>
</td>
<td><button type="button" name="get_details_button" class="btn btn-success btn-xs get_details_button">Get Details</button>
</td>
</tr>
<tr>
<td>2
</td>
<td>Soemthig,,2
<p class="get_details">Soemthing2.....</p>
</td>
<td><button type="button" name="get_details_button" class="btn btn-success btn-xs get_details_button">Get Details</button>
</td>
</tr>
</table>
You don't need any ids to make this work. I don't know your markup but here is an example. You will need to work it out for your markup.
<div class="container">
<table>
<tr>
<td>{{ id }}</td>
<td>{{ product_name }}</td>
<td><button>details</button></td>
</tr>
</table>
<div class="product-details" style="display:none">...</div>
</div>
<div class="container">
<table>
<tr>
<td>{{ id }}</td>
<td>{{ product_name }}</td>
<td><button>details</button></td>
</tr>
</table>
<div class="product-details" style="display:none">...</div>
</div>
<div class="container">
<table>
<tr>
<td>{{ id }}</td>
<td>{{ product_name }}</td>
<td><button>details</button></td>
</tr>
</table>
<div class="product-details" style="display:none">...</div>
</div>
jquery
$('.container').find('button').on('click', function(e) {
e.preventDefault();
$(this).parent().parent().parent().parent().find('.product-details').slideToggle();
});
I've got this code:
<div class="container col-md-6 col-md-offset-3">
<div class="well well bs-component">
<table class="table">
<thead>
<tr>
<th>Logo</th>
<th>Bedrijfsnaam</th>
<th>Plaats</th>
</tr>
</thead>
<tbody>
#foreach($companies as $company)
<a href="/bedrijf/{!! $company->CompanyId !!}">
<tr>
<td><img class="img-circle-company" src="{!! $company->Logo != null ? '/files/images/companylogos/'.$company->Logo : '/files/images/companylogos/default.png'!!}"/></td>
<td>{{ $company->CompanyName }}</td>
<td>{{ $company->City }}</td>
</tr>
</a>
#endforeach
</tbody>
</table>
</div>
But the a tag is not working why is that? In my page source it looks like this:
Unfortunately wrapping <tr> elements in an anchor isn't valid HTML. Some browsers may not blink an eye at it, but most with remove the offending element. If you want to continue using tables, another option would be to add the anchor inside each <td> element.
<div class="container col-md-6 col-md-offset-3">
<div class="well well bs-component">
<table class="table">
<thead>
<tr>
<th>Logo</th>
<th>Bedrijfsnaam</th>
<th>Plaats</th>
</tr>
</thead>
<tbody>
#foreach($companies as $company)
<tr>
<td>
<a href="/bedrijf/{!! $company->CompanyId !!}">
<img class="img-circle-company" src="{!! $company->Logo != null ? '/files/images/companylogos/'.$company->Logo : '/files/images/companylogos/default.png'!!}"/>
</a>
</td>
<td><a href="/bedrijf/{!! $company->CompanyId !!}">{{ $company->CompanyName }}</td>
<td>{{ $company->City }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>