i have some coding, i wanna to update multiple data from select option value in database using laravel 5.1. i'm using ajax onchange="form.submit()", so i can update data without submit.
this is my view
{!! Form::model($UserAccess,['method' => 'POST','url'=>['setting/updaterole']]) !!}
<table class="dataTable" id="table-user">
<thead class="grey lighten-3">
<tr>
<td class="center-align no-sort">Photo</td>
<td class="center-align">Fullname</td>
<td class="center-align">Rule</td>
<td class="center-align">Action</td>
</tr>
</thead>
<tbody>
<?php $hitung = $UserAccess->count(); ?>
#foreach($UserAccess as $list)
<tr>
<td class="center-align" width="50">
#if($list->avatar == NULL)
<img class="circle responsive-img" width="50" src="{{asset(config('param.url_uploads').'blank.jpg')}}"/>
#else
<img class="circle responsive-img" width="50" src="{{$list->avatar}}"/>
#endif
</td>
<td class="red1-text lato-bold center-align">{{$list->name}}</td>
<td class="center-align" width="150">
<select id="selectrole" name="selectrole" onchange="form.submit()">
#foreach($UserAccessRole as $listRole)
<option value="{{$listRole->id}}" #if($list->user_access_role_id_fk == $listRole->id) selected="selected"#endif>{{$listRole->name}}</option>
#endforeach
</select>
</td>
<input type = "hidden" value = "{{$list->id}}" name = "idmain">
#if($hitung > 2)
<td class="center-align">
<a href = "remove_access/{{$list->id}}/delete" >Remove Access<a/>
</td>
#else
<td class="center-align">Remove Access</td>
#endif
</tr>
#endforeach
</tbody>
</table>
{!! Form::close() !!}
this is my controller
public function doUpdateAccessRole(Request $request)
{
$UserAccess = UserAccess::orderBy('name', 'asc')->get();
$id_main = $request->input('idmain');
$id_role = $request->input('selectrole');
$Role = UserAccess::findOrFail($id_main);
$Role->user_access_role_id_fk = $id_role;
$Role->update($request->all());
return redirect('setting/useraccess');
}
this is my route
Route::post('setting/updaterole',['uses'=>'SettingController#doUpdateAccessRole','as'=>'updateaccessrole']);
using my coding update function already work, but just last id has been update. please help me, thank you
my code already work. just add foreach in my controller. like this, my controller :
public function doUpdateAccessRole(Request $request)
{
$UserAccess = UserAccess::all();
foreach($UserAccess as $list)
{
$id_main = $request->input('idmain'.$list->id);
$id_role = $request->input('selectrole'.$list->id);
$Role = UserAccess::find($id_main);
$Role->user_access_role_id_fk = $id_role;
$Role->update($request->all());
}
return redirect('setting/useraccess');
}
and this my view :
{!! Form::model($UserAccess,['method' => 'POST','url'=>['setting/updaterole']]) !!}
<table class="dataTable" id="table-user">
<thead class="grey lighten-3">
<tr>
<td class="center-align no-sort">Photo</td>
<td class="center-align">Fullname</td>
<td class="center-align">Rule</td>
<td class="center-align">Action</td>
</tr>
</thead>
<tbody>
<?php $hitung = $UserAccess->count(); ?>
#foreach($UserAccess as $list)
<tr>
<td class="center-align" width="50">
#if($list->avatar == NULL)
<img class="circle responsive-img" width="50" src="{{asset(config('param.url_uploads').'blank.jpg')}}"/>
#else
<img class="circle responsive-img" width="50" src="{{$list->avatar}}"/>
#endif
</td>
<td class="red1-text lato-bold center-align">{{$list->name}}</td>
<td class="center-align" width="150">
<select id="selectrole" name="selectrole{{$list->id}}" onchange="form.submit()">
#foreach($UserAccessRole as $listRole)
<option value="{{$listRole->id}}" #if($list->user_access_role_id_fk == $listRole->id) selected="selected"#endif>{{$listRole->name}}</option>
#endforeach
</select>
</td>
<input type = "hidden" value = "{{$list->id}}" name = "idmain{{$list->id}}">
#if($hitung > 2)
<td class="center-align">
<a href = "remove_access/{{$list->id}}/delete" >Remove Access<a/>
</td>
#else
<td class="center-align">Remove Access</td>
#endif
</tr>
#endforeach
</tbody>
</table>
{!! Form::close() !!}
and now my coding already work.
Related
I am trying to send an array per compact but when viewing it it throws an error.
SaleController.php
public function generarRecibo($id)
{
$sales = Sale::with('client', 'products')->where('id', '=', $id)->get();
$pdf = PDF::loadView('pdf.sales-recibo', compact(['sales']) );
return $pdf->stream('Recibo N° '.$id.'.pdf');
}
sales-recibo.blade.php
<table class="table">
<tbody>
#foreach ($sales->products as $product)
<tr>
<td style="border: 0px;" colspan="3">{{ $product->name }}</td>
</tr>
<tr>
<td style="border: 0px;">
<ul>
<li>{{ $product->quantity }} X ${{ number_format($product->price, 0,',','.') }}</li>
</ul>
</td>
<td style="border: 0px;" width="150px"></td>
<td style="border: 0px;" width="150px">${{ number_format($product->price, 0,',','.') }}</td>
</tr>
#endforeach
</tbody>
</table>
Instead of get() use find() method
$sales = Sale::with('client', 'products')->find($id);
and also you have issue with compact
$pdf = PDF::loadView('pdf.sales-recibo', compact('sales') );
I have a table that loops its value from the database using FOREACH LOOP. The first loop seems okay when I inserted IF ELSE STATEMENT in another FOREACH LOOP inside the first loop, the td begin to not align anymore. Which means if the value is empty, it will hidden the cell and other values from the first loop will be push forward.
For your information, I'm using different server database which are SQL and MYSQL. SQL is my main db and mysql is for inserting, updating and deleting the textarea known as 'NOTES' in the table.
Here's the query from my controller
$getNote1 = DB::connection('mysql')->table('note1')->select('stockcode', 'note')->orderBy('stockcode', 'ASC')->get();
$getNote2 = DB::connection('mysql')->table('note2')->select('stockcode', 'note')->orderBy('stockcode', 'ASC')->get();
$getNote3 = DB::connection('mysql')->table('note3')->select('stockcode', 'note')->orderBy('stockcode', 'ASC')->get();
$getNote4 = DB::connection('mysql')->table('note4')->select('stockcode', 'note')->orderBy('stockcode', 'ASC')->get();
return view('posts.index')->with('title', $title)->with('query', $query)->with('getNote1', $getNote1)->with('getNote2', $getNote2)->with('getNote3', $getNote3)->with('getNote4', $getNote4);
Here's my table code
<table id="table1" class="table table-bordered">
<thead>
<tr>
<th style="display:none;">Stock Code</th>
<th>Stock Name</th>
<th>Note 1</th>
<th>Note 2</th>
<th>Note 3</th>
<th>Note 4</th>
<th>Order Level</th>
<th>Qty Level</th>
<th>Balance</th>
<th>Purchase Price</th>
<th>UOM</th>
#for ($i=0; $i<=12; $i++)
<th><?php echo date('Y/m', strtotime('-'.$i.' month', strtotime($getDate)));?></th>
#endfor
</tr>
</thead>
<tbody>
<!-- Foreach loop from db -->
#foreach ($query as $val)
<?php
$stockcode = $val->StockCode;
$stockname = $val->StockName;
$currentbalance = $val->CurrentBalance;
$purchaseprice = $val->PurchasePrice;
$baseuom = $val->BaseUOM;
?>
<tr>
<td style="display:none;">{{ $val->StockCode }}</td>
<td class="text-nowrap align-middle">{{ $val->StockName }}</td>
#foreach($getNote1 as $note1)
#if($note1->stockcode == $stockcode)
<td><textarea rows="2" cols="10" name="note1" class="note1 align-middle" data-stockcode="{{ $stockcode }}" data-stockname="{{ $stockname }}">{{ $note1->note }}</textarea></td>
#else
<td><textarea rows="2" cols="10" name="note1" class="note1 align-middle" data-stockcode="{{ $stockcode }}" data-stockname="{{ $stockname }}"></textarea><td>
#endif
#endforeach
<td><textarea rows="2" cols="10" name="note2" class="note2 align-middle" data-stockcode="{{ $stockcode }}" data-stockname="{{ $stockname }}"></textarea></td>
<td><textarea rows="2" cols="10" name="note3" class="note3 align-middle" data-stockcode="{{ $stockcode }}" data-stockname="{{ $stockname }}"></textarea></td>
<td><textarea rows="2" cols="10" name="note4" class="note4 align-middle" data-stockcode="{{ $stockcode }}" data-stockname="{{ $stockname }}"></textarea></td>
<td><input type="text" id="orderlevel" class="text-right"></td>
<td><input type="text" id="qtylevel" class="text-right"></td>
<td class="text-right align-middle">{{ number_format($currentbalance, 2) }}</td>
<td class="text-right align-middle">{{ number_format($purchaseprice, 2) }}</td>
<td class="text-center align-middle">{{ $baseuom }}</td>
#for ($i=1; $i<=13; $i++)
<?php
//looping variables
$Qty = 'Qty'.$i;
$Date = 'Date'.$i;
?>
<td class="text-right align-middle">
#if($val->$Qty > 0)
<a id="viewdetails" data-toggle="modal"
data-productid="{{$val->Id}}"
data-productname="{{$val->StockName}}"
data-getdate="{{date('Y-m', strtotime($val->$Date))}}"
href="#" data-target="#dataModal">{{ number_format($val->$Qty, 2) }}</a>
#endif
</td>
#endfor
</tr>
#endforeach
<!-- End Foreach loop -->
</tbody>
</table>
Here's my screenshot
Here's the table that I want it to be
don't hide the cell instead put an empty value in it.
<td><textarea rows="2" cols="10" name="note1" class="note1 align-middle" data-stockcode="{{ $stockcode }}" data-stockname="{{ $stockname }}">
#foreach($getNote1 as $note1)
#if($note1->stockcode == $stockcode)
{{ $note1->note }}
#endif
#endforeach
</textarea></td>
then it will align just fine
I am having some trouble writing some nested HTML Tables from my Laravel Collection.
My Model
public static function offers($userId)
{
return DB::table('users_vehicles')
->join('dealer_offers', 'users_vehicles.id', '=', 'dealer_offers.vehicle_id')
->where('user_id', '=', $userId)
->select('users_vehicles.*', 'dealer_offers.*');
}
My Controller
public function dash()
{
$userCars = UserVehicles::offers(Auth::user()->id)->get();
return view('customer.dash', compact('userCars'));
}
My Collection Results
In My View blade Template
#foreach( $userCars->chunk(1) as $userCarChunk)
<div id="no-more-tables">
<table class="table table-bordered table-hover">
<caption>Offers for My Mazda 326 </caption>
<thead>
<tr>
<th class="numeric">DEALER RATING</th>
<th class="numeric">AMOUNT </th>
<th class="numeric"> 3 DAYS To Accept </th>
</tr>
</thead>
<tbody>
#foreach( $userCarChunk as $car)
<tr>
<td data-title="First Name">
<div class="rating">
<label>
<input type="radio" name="rating" value="5" title="5 stars"> 5
</label>
</div>
</td>
<td data-title="Last Name"> 55 000 </td>
<td data-title="Username">
Accept
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
#endforeach
Front-End View
Question
How can I create a nested HTML Table for all the user vehicles, so that I can write the vehicle name and all the offers for that particular vehicle?
I hope my question is clear.
Try it like this :
<div id="no-more-tables">
<table class="table table-bordered table-hover">
<caption>Offers for My Mazda 326 </caption>
<thead>
<tr>
<th class="numeric">DEALER RATING</th>
<th class="numeric">AMOUNT </th>
<th class="numeric"> 3 DAYS To Accept </th>
</tr>
</thead>
<tbody>
#foreach( $userCars->chunk(1) as $userCarChunk)
#foreach( $userCarChunk as $car)
<tr>
<td data-title="First Name">
<div class="rating">
<label>
<input type="radio" name="rating" value="5" title="5 stars"> 5
</label>
</div>
</td>
<td data-title="Last Name"> 55 000 </td>
<td data-title="Username">
Accept
</td>
</tr>
#endforeach
#endforeach
</tbody>
</table>
</div>
Answer
My Model UserVehicles.php
public function offers() {
return $this->hasMany(DealerOffers::class, 'vehicle_id');
}
My Controller CustomerController.php
$offersToCustomer = UserVehicles::with('offers')->get();
Dashboard Blade template
#foreach( $offersToCustomer as $offer)
<div id="no-more-tables_">
<table class="table table-bordered table-hover">
<caption>Offers for My :: <b style="color: #00BFF0"> {{ $offer->vehicle_make }} {{ $offer->vehicle_model }} </b> </caption>
<thead>
<tr>
<th class="numeric">DEALER RATING</th>
<th class="numeric">AMOUNT REQUESTED </th>
<th class="numeric">AMOUNT OFFERED </th>
<th class="numeric"> Expires :: {{ Carbon\Carbon::parse($offer->offer_expiry)->format('d-m-Y') }} </th>
</tr>
</thead>
<tbody>
#foreach( $offer->offers as $subOffer)
<tr>
<td data-title="DEALER RATING">
<input id="rating" name="rating" class="rating rating-loading" value="3" data-min="0" data-max="5" data-step="1" />
</td>
<td data-title="AMOUNT REQUESTED">R {{ number_format($offer->vehicle_amount_asked, 2, '.', ' ') }} </td>
<td data-title="AMOUNT OFFERED">R {{ number_format($subOffer->offer_amount, 2, '.', ' ') }} </td>
<td data-title="ACTIONS">
<button data-offer_id="{{ $offer->id }} " data-vehicle_id="{{ $subOffer->vehicle_id }}"
class="btn btn-xs btn-success accept-offer">Accept</button>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
#endforeach
Output
Hi Guy's Im always getting an error from laravel 5.4.
Im creating a list of members... but when i use #foreach it says
ErrorException in 6163a8b030c7474bc8eaad359ab99eb61ebdb127.php line 38:
Trying to get property of non-object (View: E:\wamp64\www\gplspring2017\resources\views\admin\memberlist.blade.php)
Here's my controller
public function listmember(Request $request, $idteam)
{
$teams = DB::table('gpl_team')->where('gpl_team_id', $idteam)->first();
$count = count($teams);
if (!$count) {
return redirect('404');
} else {
return view('/admin/memberlist', ['team' => $teams]);
}
}
and here's my view code:
<table class="table table-striped">
<tr>
<td style="width:15%;"></td>
<td style="width:25%;">Summoners Name</td>
<td style="width:25%;">Name</td>
<td style="width:25%;">Role</td>
<td style="width:10%;"></td>
</tr>
<?php
$qmember = DB::table('team_member')->where('gpl_team_id', $team->gpl_team_id)->first();
$counting = count($qmember);
?>
#if (! $counting)
<tr>
<td colspan="4"> No Recored! </td>
</tr>
#else
#foreach($qmember as $get_member)
<tr>
<td><img src="{{ $get_member->member_pic }}" /></td>
<td></td>
<td></td>
<td></td>
<td>
<div class="glyphicon glyphicon-pencil"></div> |
<div class="glyphicon glyphicon-trash"></div>
</td>
</tr>
#endforeach
#endif
</table>
When i remove the foreach the code is working.. but i try to add the #foreach($qmember as $get_member) it not working anymore...
Check this line:
$qmember = DB::table('team_member')->where('gpl_team_id', $team->gpl_team_id)->first();
when you are using first() then it does not return an Std Class object. If you want it so then use get()
Using first() method you are fetching only one record from DB that match with the ID (First one matched). You need to use get().
Controller:
public function listmember(Request $request, $idteam)
{
$teams = DB::table('gpl_team')->where('gpl_team_id', $idteam)->get(); //Use get() if you expect more than one result not first()
$count = count($teams);
if(! $count)
{
return redirect('404');
}
else
{
return view('/admin/memberlist', ['teams' => $teams]);// this team variable must be used in the blade
}
}
View:
<table class="table table-striped">
<tr>
<td style="width:15%;"></td>
<td style="width:25%;">Summoners Name</td>
<td style="width:25%;">Name</td>
<td style="width:25%;">Role</td>
<td style="width:10%;"></td>
</tr>
<?php
$qmember = DB::table('team_member')->where('gpl_team_id', $team->gpl_team_id)->first();
$counting = count($qmember);
?>
#if (! $counting)
<tr>
<td colspan="4"> No Recored! </td>
</tr>
#else
#foreach($teams as $team)
<tr>
<td><img src="{{ $team['member_pic'] }}" /></td>
<td></td>
<td></td>
<td></td>
<td>
<div class="glyphicon glyphicon-pencil"></div> |
<div class="glyphicon glyphicon-trash"></div>
</td>
</tr>
#endforeach
#endif
</table>
Trying to create a PDF invoice using barryvdh's laravel dompdf wrapper. I want the invoice to begin on a new page when a certain number of rows is reached. However I'm unsure on how to do it since I don't get the expected results. Here is my controller:
function invoice() {
$resellerId = Input::get('resellerId');
$startdate = Input::get('invoiceStartDate');
$enddate = Input::get('invoiceEndDate');
$orders = \App\order::where('reseller',1)->orderBy('date', 'desc')->where('customer_id' , $resellerId )->where('date', '>=',$startdate)->where('date', '<=',$enddate)->get();
$pdf = PDF::loadView('pdf.invoicePrint',['orders' => $orders]);
// $PDFOutput = $pdf->output();
return $pdf->stream("trestaki.pdf");
}
And here is the relevant portion of the blade:
<table style="border:1px solid #000;width: 100%;">
<tr>
<td>
<span style="font-size: 14px;font-weight: 900;">Art. Nr.</span>
</td><td>
<span style="font-size: 14px;font-weight: 900;">Benämning</span>
</td><td>
<span style="font-size: 14px;font-weight: 900;">Antal</span>
</td><td>
<span style="font-size: 14px;font-weight: 900;">Pris</span>
</td><td>
<span style="font-size: 14px;font-weight: 900;">Summa</span>
</td></tr>
<?php $i=0; ?>
#foreach($orders as $order)
<tr>
<td>{{ $order->order_id }}</td>
<td>{{ $order->getProduct->mobile }} {{ $order->getProduct->model }}</td>
<td>1</td>
<td>{{ $order->price }}</td>
<td>{{ $order->price }}</td>
</tr>
<?php
$i++;
if($i % 25 == 0)
echo "<div style='page-break-after: always;'></div>";
?>
#endforeach
<tr>
<td colspan=5 style="padding-top: 20px;">
<table style="width: 45%;">
<tr>
<td>
<span style="font-size: 14px;font-weight: 900;">Moms %</span>
</td>
<td>
<span style="font-size: 14px;font-weight: 900;">Netto</span>
</td>
<td>
<span style="font-size: 14px;font-weight: 900;">Moms</span>
</td>
<td>
<span style="font-size: 14px;font-weight: 900;">Summa</span>
</td>
</tr>
<tr>
<td>25%</td>
<td>639,20</td>
<td>159,80</td>
<td>799,00</td>
</tr>
</table>
</td>
</tr>
</table>
The thing is that if I remove all the closing tags from the echo, the webpage times out.
The problem was the fixed position of the main div. After removing it the page did break correctly.