I have a table in the page "map.blade.index.php" as:
<table id="table">
<thead>
<tr><th>ID</th>
<th>Name</th>
<th>Latitude</th>
<th>Longitude</th>
</tr>
</thead>
<tbody><tr>
<td>0</td>
<td id="0">Name 174</td>
<td id="lat0">41.1230199</td>
<td id="lng0">14.73767010000006</td>
</tr>
</tbody>
</table>
and I try to use the table elements in my function Controller called "MapController#saved" , but I think that I can't use the table by her id.
there a way to use all the elements of the table ? Now I must use one item at a time.
You can parse your table with any HTML parser. I'm using this one.
$html->find('td[id=lat0]')->innertext; // Returns 41.1230199
If I understood then what you need is a multi input like:
<form action="map/saved">
<table id="table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Latitude</th>
<th>Longitude</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td id="0">Name 174</td>
<td id="lat0">41.1230199</td>
<td id="lng0">14.73767010000006</td>
<input type="hidden" name="entry[0][name]" value="Name 174">
<input type="hidden" name="entry[0][lat]" value="41.1230199">
<input type="hidden" name="entry[0][lng]" value="14.73767010000006">
</tr>
</tbody>
</table>
<button type="submit">
</form>
Your controller method will looks like this:
public function map(Request $request) {
foreach ($request->input('entry') as $i => $entry) {
// here you get an array with:
// array (3) [
// 'name' => 'Name 174'
// 'lat' => '41.1230199'
// 'lng' => '14.73767010000006'
// ]
}
}
Related
I'm facing an issue with checking the checkbox on the edit page using Livewire. I've tried many ways but still not able to check the old selected value
View Code:
<table id="branches" class="table table-bordered table-sm" width="100%" cellspacing="0">
<thead>
<tr>
<th width="10%">
</th>
<th>Branch ID</th>
</tr>
</thead>
<tbody>
#foreach ($propertiesOptions as $key => $property)
<tr>
<td>
<input class="branchCheckbox"
type="checkbox"
wire:model="propertyIds.{{$property->id}}"
value="{{$property->id}}" #if(in_array($property->id,$propertyIds)) checked #endif>
</td>
<td>{{$property->id}}</td>
</tr>
#endforeach
</tbody>
</table>
Backend Code:
public $propertyIds, $propertiesOptions;
public function mount($record)
{
$this->propertiesOptions = Properties::where('merchant_id',$record->id)->get()
$this->propertyIds = $record->properties->pluck('property_id')->toArray();
}```
updated
And can you check if this correct? wire:model="propertyIds.{{$property->id}}"? Try to delete the wire:model .
<input class="branchCheckbox" type="checkbox"
value="{{$property->id}}"
#if(in_array($property->id,$propertyIds)) checked #endif>
`<table id="branches" class="table table-bordered table-sm" width="100%" cellspacing="0">
<thead>
<tr>
<th width="10%">
</th>
<th>Branch ID</th>
</tr>
</thead>
<tbody>
#foreach ($propertiesOptions as $key => $property)
<tr>
<td>
<input class="branchCheckbox"
type="checkbox"
wire:model="propertyIds"
value="{{$property->id}}" >
</td>
<td>{{$property->id}}</td>
</tr>
#endforeach
</tbody>
</table>`
BACKEND
public $propertyIds, $propertiesOptions;
public function mount($record)
{
$this->propertiesOptions = Properties::where('merchant_id',$record->id)->get()
$this->propertyIds = $record->properties->pluck('property_id')->toArray();
}
I have a Function to showing a single data . but if this data empty its having error. I using first because just want to
Trying to get property of non-object
its my Controller
public function PDF_profile(Request $request,$id){
$users = User::findOrFail($id);
$pns = Data_pns::where('user_id',$id)->first();
$pendidikan = Data_riwayat_pendidikan::where('user_id',$id)->latest()->first();;
$r_kgb = DB::table('data_riwayat_kgb')->latest()->first();
$pdf = PDF::loadView('admin.pdf_profile',
['users' => $users,
'pendidikan'=>$pendidikan,
'r_kgb'=>$r_kgb,
'pns' => $pns,
]);
// dd($pns);
return $pdf->stream('Profile.pdf')->header('Content-Type','application/pdf');
}
my View
<table align="left" border="" >
<thead>
<tr>
<th> <b>Riwayat Pendidikan </b></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td> <b>Tingkat Pendidikan </b></td>
<td>:
{{ $pendidikan->jenjang}}
</td>
</tr>
<tr>
<td> <b> Tempat Pendidikan</b></td>
<td>:{{$pendidikan->nama_tempat}}</td>
</tr>
<tr>
<td><b>Konsentrasi/Jurusan</b></td>
<td>:{{ $pendidikan->jurusan}}</td>
</tr>
<tr>
<td><b>Tahun Lulus</b></td>
<td>:{{$pendidikan->lulus_tahun}}</td>
</tr>
</tbody>
</table>
its just part on my view .
and this line is mentioned error .
<td>:
<?php echo e($pendidikan->jenjang); ?>
</td>
but if this data is inputed or not empty its not having error . how to solved it ?
You can first check if the object is not null as first() returns null hence the error, so do this instead:
<td>:
#if($pendidikan)
{{$pendidikan->nama_tempat}}
#endif
</td>
You can also replace this: ->latest()->first() with just calling last().
You can use the optional() helper method
{{ optional($pendidikan)->nama_tempat}}
or short form #
{{ #$pendidikan->nama_tempat}}
The error is on the view which says that
my $audio variable is not defined.
I want to show everything from the database using a foreach loop.
I tried base on paginate on the laravel documentation https://laravel.com/docs/5.7/pagination#basic-usage
My controller is below:
use Illuminate\Http\Request;
use App\Audio_lectures;
use Illuminate\Support\Facades\DB;
public function index(){
$audio = DB::table('audio_lectures')->latest()->paginate();
return view('welcome', ['audio_lectures' => $audio]);
}
The welcome view is below:
<div class="container">
<div class="row">
<table class="table table-dark">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Subject</th>
<th scope="col">Date Added</th>
<th scope="col">Download</th>
</tr>
</thead>
<tbody>
#foreach ($audio as $audio_lectures)
<tr>
<th scope="row">{{$audio_lectures->id}}</th>
<td>{{$audio_lectures->subject}}</td>
<td>{{$audio_lectures->created_at}}</td>
<td>Download</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
My route web.php is below:
Route::get('/','Audio_lecturesController#index');
I expect to show all the audio lectures from my database to my view.
try this one
#foreach ($audio_lectures as $audio)
<tr>
<td scope="row">{{$audio->id}}</td>
<td>{{$audio->subject}}</td>
<td>{{$audio->created_at}}</td>
<td>
Download
</td>
</tr>
#endforeach
you are passing from controller audio_lectures array but you
getting as in your view audio
On your view file looping try this
#foreach ($audio_lectures as $value)
<tr>
<td scope="row">{{$value->id}}</td>
<td>{{$value->subject}}</td>
<td>{{$value->created_at}}</td>
<td>Download</td>
</tr>
#endforeach
#model Example.Model1ViewModel
#if (Model != null && Model.TableSix != null)
{
<table>
<thead>
<tr>
<td style="width:60%"></td>
<td style="width:20%">Outstanding Amount</td>
</tr>
</thead>
<tbody>
<tr>
<td>Total</td>
<td class="Total cursor">#Html.DisplayFor(x => x.TableSix.Total)</td>
</tr>
<tr>
<td>One</td>
<td>#Html.DisplayFor(x => x.TableSix.One)</td>
</tr>
<tr>
<td>Two</td>
<td>#Html.DisplayFor(x => x.TableSix.Two)</td>
</tr>
</tbody>
</table>
}
<div style="display: none">
#(Html.Kendo().Window()
.Name("RemainingAssetsDrillDown")
.Modal(true)
.Title("Item Drill Down")
.Actions(actions => actions.Close())
.Content(#<text>
<div>
<table>
<tbody>
<tr>
<td>One</td>
<td>#Html.DisplayFor(x => x.TableSix.One)</td>
</tr>
</tbody>
</table>
</div>
</text>)
</div>
)
$(".Total").click(function () {
$("#MVC").load('#Url.Action("PartList", "Report")');
var win = $("#DrillDown").data("kendoWindow");
win.center().open();
});
<style type="text/css">
.cursor {
cursor: pointer;
}
</style>
So, the problem is that #Html.DisplayFor(x => x.TableSix.One) fetches the correct value from the view model in the first table, but in the table under kendo window I get the value as 0.
Any idea how I can get #Html.DisplayFor(x => x.TableSix.One) to display the value from the view model into the table that is under kendo window?
Thanks in advance. :)
On the List.js site, they show how to use tables and even provide an example at http://www.listjs.com/examples/table.
<tr>
<td class="name">Jonny Stromberg</td>
<td class="born">1986</td>
</tr>
However, I want to use input values instead.
<tr>
<input class="name" value="Jonny Stromberg">
<input class="born" value="1986">
</tr>
The outcome is unexpected, with the input values rendering as empty. However, the ultimate goal is to give the input values names and save the columns/rows in a session. Has anyone been in the same boat?
Try wrapping the <input> in a <td></td> tag. You have set the value of the <inputs> tags correctly and so they should populate correctly.
Something like so worked fine for me:
<table>
<!-- IMPORTANT, class="list" have to be at tbody -->
<tbody class="list">
<tr>
<td><input class="name" value="Jonny Stromberg"></td>
<td><input class="born" value="1986"></td>
</tr>
<tr>
<td><input class="name" value="Jonas Arnklint"></td>
<td><input class="born" value="1985"></td>
</tr>
<tr>
<td><input class="name" value="Martina Elm"></td>
<td><input class="born" value="1986"></td>
</tr>
<tr>
<td><input class="name" value="Gustaf Lindqvist"></td>
<td><input class="born" value="1983"></td>
</tr>
</tbody>
</table>
JSFiddle - https://jsfiddle.net/oLbey91h/1/
I was able to achieve the desired result using an input field and filling the value attribute. Here's a Pastebin: http://pastebin.com/dEfjdNCi.
Notice that in "options" the class name points to the attribute "value."
<div id="users">
<table>
<!-- IMPORTANT, class="list" have to be at tbody -->
<tbody class="list">
<tr>
<td style="display:none;"><input class="id" type="hidden"></td>
<td><input class="name"></td>
<td><input class="born"></td>
</tr>
</tbody>
</table>
</div>
<script>
$(document).ready(function () {
var options = {
valueNames: [
{attr: 'value', name: 'id'},
{attr: 'value', name: 'name'},
{attr: 'value', name: 'born'},
]
};
</script>