Just started to working with laravel and found it really cool framework to work with , I'm working with basic Shopping cart and after i do Add to Cart Option , product values goto another table called "customer_items" along with current user ID,
now when I want to call current product which user already added to cart and show it in a table ,
here is the code
#foreach($shoppingCarts as $items)
<tr>
<td class="name">{{ $items->product_name }}</td>
<td class="price">{{ $items->product_price }}</td>
<td class="total"> <img class="tooltip-test" data-original-title="Remove" src="img/remove.png" alt=""></td>
</tr>
#endforeach
note : {{ $items->product_price }} , usually there is 4, 6 items added by user ,
I want to get total value of product price from each row ,
Thanks in Advance for the help :) !
Used this and worked fine ,
<?php $total = 0; ?>
#foreach($shoppingCarts as $items)
<?php $total += $items->product_price; ?>
<tr>
<td class="name">{{ $items->product_name }}</td>
<td class="price">{{ $items->product_price }}</td>
<td class="total">{{ $total }}<img class="tooltip-test" data-original-title="Remove" src="img/remove.png" alt=""></td>
</tr>
#endforeach
or
#foreach($shoppingCarts as $items)
<tr>
<td class="name">{{ $items->product_name }}</td>
<td class="price">{{ $items->product_price }}</td>
<td class="total">{{ $items->sum('product_price') }}<img class="tooltip-test" data-original-title="Remove" src="img/remove.png" alt=""></td>
</tr>
#endforeach
Thanks everyone for the support :) !
Source : https://laracasts.com/discuss/channels/general-discussion/get-total-value-from-table-rows
Related
so I recently learn how to use Laravel for my class project, and heres my problem
when I create pagination the result in my project is <
.1
>
like that, the pagination is not styled and the pagination like the picture I upload, I have done everything I could do , I browse the internet too, and the result is null , thanks heres the picture of my problem
$no = 1 {{-- buat nomor urut --}}
)
#if ($forms->count() > 0)
#foreach ($forms as $angs)
<tr align="center">
<td height="32">{{ $no++ }}<div align="center"></div></td>
<td>{{ $angs->username }}<div align="center"></div></td>
<td>{{ $angs->nama }}<div align="center"></div></td>
<td>{{ $angs->nik}}<div align="center"></div></td>
<td>{{ $angs->status_aktif}}<div align="center"></div></td>
<td bgcolor="#EEF2F7"><div align="center">Detail | Edit | Hapus</div></td>
<tr align="center" bgcolor="#DFE6EF">
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tr>
#endforeach
{{ $forms->links()}}
`
this is my code in blade
and this is my code in my controller
`
$forms= login::paginate(3);
return view('crud.form.viewMember', compact('forms'));
`
I am using Laravel 5 and I have a page which have some tables. My problem is, when there is no data in database, it shows nothing. I want it show 'Data is not found'. This first picture below is when the data is available in the database, and the second picture is when the data is unavailable in the database.
1.
2.
This is my code:
#if($candidateskill != '')
#foreach($candidateskill as $getData)
<tr>
<td>{{ $getData->SKILL_NAME }}</td>
<td align="center">{{ $getData->SKILL_LEVEL }}</td>
</tr>
#endforeach
#else
<td>Data is Not Found</td>
<td>Data is Not Found</td>
#endif
And this is the output of the null data:
Illuminate\Database\Eloquent\Collection Object ( [items:protected] =>
Array ( ) )
You can use the #forelse (https://laravel.com/docs/5.6/blade#loops)
#forelse($candidateskill as $getData)
<tr>
<td>{{ $getData->SKILL_NAME }}</td>
<td align="center">{{ $getData->SKILL_LEVEL }}</td>
</tr>
#empty
<tr><td colspan="2">No Data</td></tr>
#endforelse
Try this:
#if($candidateskill && !$candidateskill->isEmpty())
#foreach($candidateskill as $getData)
<tr>
<td>{{ $getData->SKILL_NAME }}</td>
<td align="center">{{ $getData->SKILL_LEVEL }}</td>
</tr>
#endforeach
#else
<tr>
<td>Data is Not Found</td>
</tr>
#endif
You need to evaluate your database variable if it exists, and if its not empty aka null.
First Laravel Project. I want to populate a table automiticaly from database
The table looks like this:
{{ Form::open(array('url' => '/invoicenew/$invoicenum')) }}
<table border=1 align=center>
<t>
<td colspan=3>
<table>
<tr>
<td>ACME INC.</td>
</tr>
<tr>
<td>Post code, City</td>
</tr>
<tr>
<td>Address</td>
</tr>
<tr>
<td>Tax number</td>
</tr>
</table>
</td>
<td colspan=3>
<table>
<tr>
<td>{{ $supplier[0]->name }}</td>
</tr>
<tr>
<td>{{ $supplier[0]->postcode}} {{ $supplier[0]->city}}</td>
</tr>
<tr>
<td>{{ $supplier[0]->address }}</td>
</tr>
<tr>
<td>{{ $supplier[0]->taxnumber }}</td>
</tr>
</table>
</tr>
<tr>
<td colspan=2>Invoice number:</td><td>{{ $invoicenum }}</td>
<td colspan=2>Invoice date:</td><td>{{ $invoicedate }}</td>
</tr>
<tr>
<td>Barcode</td><td>Name</td><td>Count</td><td>Netto Price</td><td>Brutto Price</td><td>VAT kex</td>
</tr>
<tr>
<td>{{Form::text('barcode')}}</td><td></td>{{Form::text('count')<td></td><td></td><td></td><td></td>
</tr>
<tr colspan=6>{{Form::submit('Next>>')}}</tr>
</table>
I want to fill the Name, Netto Price, Brutto Price and VAT key from table inventory instantly after I write the barcode in the field.
How can I accomplish it?
Use the form model binding feature.
Often, you will want to populate a form based on the contents of a model. To do so, use the Form::model method:
{!! Form::model($user, ['route' => ['user.update', $user->id]]) !!}
Now, when you generate a form element, like a text input, the model's value matching the field's name will automatically be set as the field value. So, for example, for a text input named email, the user model's email attribute would be set as the value. However, there's more! If there is an item in the Session flash data matching the input name, that will take precedence over the model's value.
I am having the problem in embeding images, but for the icon that is working fine and display the icon in mail, but for inside the foreach I am having some problem in displaying the images.
This is the shopping cart details I am trying to send for the customer email address! please help me to fix this !
#foreach($products as $item)
<?php $i++; ?>
<tr>
<td align="center">
**<img src="{{ $message->embed('img/tempEng/{!!$item->imgPath]!!}') }}" style="padding:0px; margin:0px" />**
</td>
<td align="center">
{{$item['name']}}
</td>
<td>
<td align="center">{{ $item['quantity'] }}</td>
<?php $quantity = $quantity + $item['quantity'] ?>
</td>
<td align="center">LKR {{$item['price']}}</td>
<td align="center">{{$item['discount']}}%</td>
<td align="center"><?php $item['price']=$item['price']*$item['quantity'] - ($item['price']*$item['quantity']*$item['discount'])/100.0 ?>LKR {{$item['price']}}</td>
</tr>
<?php $total=$total+$item['price']; ?>
{{--$i++;--}}
#endforeach
Hi I made a Laravel Project which I can view some records with sorting. For examle I have a deliveries page with URL
http://localhost/dboard/public/deliverytracker
In that form there are From Date and To Date to sort out the data before the query.
When I clicked submit the data is rendered and the pagination links is there. However when click, for example page 2 of the pagination which is
http://localhost/dboard/public/deliverytracker?page=2
in the link it won't rendered the page 2 of the data. It just reloaded the page where I need to select again the from date and to date then clicking submit again. Did I missed something?
Here's my route
/* Delivery Tracker */
Route::get('deliverytracker', 'DeliveryTrackerController#deliveryIndex');
Route::post('deliverytracker', 'DeliveryTrackerController#getDeliveries');
My function when I submit the form
public function getDeliveries()
{
$rules = array(
'fromdate' => 'required',
'todate' => 'required',
);
$validator = Validator::make(Input::all(), $rules);
// Check if all fields is filled
if ($validator->fails())
{
return Redirect::to('deliverytracker')->withErrors($validator);
}
else
{
$from = Input::get('fromdate');
$to = Input::get('todate');
$deliveries = new DeliveryTracking();
$result = $deliveries->getDeliveries($from, $to);
// Get the current page from the url if it's not set default to 1
$page = Input::get('page', 1);
// Number of items per page
$perPage = 5;
// Start displaying items from this number;
$offSet = ($page * $perPage) - $perPage; // Start displaying items from this number
// Get only the items you need using array_slice (only get 10 items since that's what you need)
$itemsForCurrentPage = array_slice($result, $offSet, $perPage, true);
// Return the paginator with only 10 items but with the count of all items and set the it on the correct page
$result = new LengthAwarePaginator($itemsForCurrentPage, count($result), $perPage, $page);
$result->setPath('deliverytracker');
return view('deliverytracker.index')->with(array('result' => $result));
}
}
My view
<div class="panel-body">
#if(isset($result))
<table class="table table-striped table-bordered">
<thead>
<tr>
<td>Delivery Status</td>
<td>Ref. Number</td>
<td>PO #</td>
<td>Count</td>
<td>Delivery QTY</td>
<td>Date Delivered</td>
<td>Filename</td>
<td>Invoice #</td>
<td>Date Invoice</td>
</tr>
</thead>
<tbody>
#foreach($result as $key => $value)
#if($value->stat == "Completed")
<tr>
<td class="bg-success">{{ $value->stat }}</td>
<td class="bg-success">{{ $value->oc }}</td>
<td class="bg-success">{{ $value->pon }}</td>
<td class="bg-success">{{ $value->cnt }}</td>
<td class="bg-success">{{ $value->dq }}</td>
<td class="bg-success">{{ $value->dd }}</td>
<td class="bg-success">{{ $value->fn }}</td>
<td class="bg-success">{{ $value->inum }}</td>
<td class="bg-success">{{ $value->di }}</td>
</tr>
#elseif($value->stat == "Active")
<tr>
<td class="bg-danger">{{ $value->stat }}</td>
<td class="bg-danger">{{ $value->oc }}</td>
<td class="bg-danger">{{ $value->pon }}</td>
<td class="bg-danger">{{ $value->cnt }}</td>
<td class="bg-danger">{{ $value->dq }}</td>
<td class="bg-danger">{{ $value->dd }}</td>
<td class="bg-danger">{{ $value->fn }}</td>
<td class="bg-danger">{{ $value->inum }}</td>
<td class="bg-danger">{{ $value->di }}</td>
</tr>
#endif
#endforeach
</tbody>
</table>
{!! $result->render() !!}
#else
No records found.
#endif
</div>
In your post you mention that the second page is called using only ?page=N, seeing your route is defined with both GET and POST you will hit the route definition for GET when clicking the next page link.
The pages buttons are simply links and not POST forms. So instead of hitting the getDeliveries() you are hitting deliveryIndex().
Also you might consider appending the fromdate and todate to your pagination links; see Appending To Pagination Links
Form fields(fromdate, todate) are not automatically attached to the pagination. You need to add query string values to paginator using ->append() method.
// Return the paginator with only 10 items but with the count of all items and set the it on the correct page
$result = new LengthAwarePaginator($itemsForCurrentPage, count($result), $perPage, $page);
$result->setPath('deliverytracker');
$result->appends(['fromdate' => $from, 'todate' => $todate]);
Reference:
http://laravel.com/api/5.0/Illuminate/Contracts/Pagination/Paginator.html#method_appends