I have a table what populates from database:
#extends('layouts.master')
#section('main')
#parent
<table border=1 align=center;>
<tr><td rowspan=10><img src="media/productimg/question.jpg" width=250px></td>
<th>Márka</th><td colspan=3>{{ $productdetails->brand }}</td></tr>
<tr><th>Beszállító</th><td colspan=3>{{ $productdetails->supplier }}</td></tr>
<tr><th>{{ $productdetails->type }}</th>
<th colspan=3>{{ $productdetails->name }}</th></tr>
<tr><th>Nettó beszerzési ár</th><td>{{ $productdetails->wholeprice }} Ft</td>
<th rowspan=2>Ár</th><td rowspan=2>{{ $productdetails->price }} Ft</td></tr>
<tr><th>Bruttó beszerzési ár</th><td>{{ $productdetails->wholeprice }} Ft</td>
<tr><th>Vonalkód</th><td>{{ $productdetails->barcode }}</td><th>Raktáron</th><td>{{ $productdetails->count }} {{ $productdetails->dimension }}</td></tr>
<tr><th>Elhelyezkedés</th><td>{{ $productdetails->whereis }} {{ $productdetails->whereis2 }}</td><th>Küszöb</th><td>{{ $productdetails->threshold }} {{ $productdetails->dimension }}</td></tr>
<tr><th>Utolsó rendelés</th><td> NA </td>
<th>Utolsó vásárlás</th><td> NA </td></tr>
<tr><td colspan=5><button class="button">Kép szerkesztése</button>
<button class="button">Termék szerkesztése</button>
<button class="button">Mennyiség szabályozása</button></td></tr>
</table>
#endsection
And I got this error:
ErrorException in 20d205ed160f36c734b8252e44ac81bfa0977988.php line 6:
Trying to get property of non-object
If I replace the table with
<?php print_r($productdetails);?>
I got the the array with the good values.
What going wrong?
You are saying that the array will show as it should be.
You could try for example:
{{ $productdetails['type'] }} instead of {{ $productdetails->type }}
But please post the result of the print_r($productdetails) function so that we can see whats wrong with the code.
The solution was: {{ $productdetails[0]->type }}
Thanks for #rahul_m for his answer:
Once check the structure of array it is having 0th index first,
You should get it like,
{{$product[0]->brand}}
OR
$product = DB::table("inventory")->where("barcode", $id)->first(); //
and get data as echo $product->brand;
Give it a try, it should work.
Related
i just get error "Trying to get property 'rute_asal' of non-object". before i ask this queston, i tried so many things but not worked (i tried the similiar question by others too).
so, this my my code
Controller
$biaya_pengantaran = BiayaPengantaran::latest()->get();
$biaya_pelayaran = BiayaPelayaran::latest()->get();
$detail_transaksi = DetailTransaksiPengiriman::where('noinvoice', $noinvoice)->get();
return view('pengiriman.create', compact('biaya_pengantaran', 'biaya_pelayaran', 'detail_transaksi'));
View:
#foreach ($detail_transaksi as $item)
<tr>
<td>{{ $loop->iteration }}</td>
<td>
<small>Nama Penerima: {{ $item->nama_penerima }}</small><br>
<small>Nama Penerima: {{ $item->telepon_penerima }}</small><br>
<small>Nama Penerima: {{ $item->alamat_penerima }}</small>
<br>
<small>Rute Pengantaran:
{{ $item->biaya_pengantaran->rute_asal }} -
{{ $item->biaya_pengantaran->rute_tujuan }}
</small><br>
<br>
<small>Merk/Tipe: {{ $item->merk_type }}</small><br>
<small>Warna: {{ $item->warna }}</small><br>
<small>No. Polisi: {{ $item->no_polisi }}</small>
<br>
<small>Biaya Pengantaran
{{ number_format($item->biaya_pengantaran) }}</small><br>
<small>Biaya Koordinasi {{ number_format($item->biaya_koordinasi) }}</small>
</td>
<td><b>{{ number_format($item->total_biaya_per_unit) }}</b></td>
</tr>
#endforeach
Model:
public function biaya_pengantaran()
{
return $this->belongsTo(BiayaPengantaran::class);
}
When I try to use $student->links() I see this error :
Facade\Ignition\Exceptions\ViewException
Call to undefined method App\Student::links()
I checked the controller, model etc but all of them seem OK... How can I fix this?
(I tried this code both on my Macbook and VPS -CentOS7- but same problem occurs)
That part of my view looks like this:
</tr>
#endforeach
</tbody>
</table>
{{ $student->links() }}
</div>
#endsection
Change
{{ $student->links() }}
to
{{ $students->links() }}
(use plural form).
You need to paginate in your backend code. $students = App\Student::paginate(15);
And then you can access the links()
<div class="container">
#foreach ($students as $student)
{{ $student->name }}
#endforeach
</div>
{{ $students->links() }}
I am fetching records with pagination. The first page is working fine but when I click on page number 2 then it return following error
Undefined offset: 0
I am trying following script in controller
$Jobs = Jobs::orderBy('job_id', 'asc')->paginate(5);
return view('veteran.job-posting.index',['Jobs'=>$Jobs]);
In the blade following code I am trying
#if($Jobs)
#foreach($Jobs as $Job)
{{ ucfirst(trans($Job->job_title)) }}
#endforeach
#endif
For pagination I am using following script
<div class="pagination-test">
{{ $Jobs->links() }}
</div>
Please guide me why it does returning error when I click on page number 2. I would like to appreciate
After Request For More Detail from #pseudoanime
For more detail about error
2/2) ErrorException
Undefined offset: 0 (View: E:\xampp\htdocs\project\project-sub-root\resources\views\index.blade.php)
Try adding this outside of the loop
{{ $Jobs->links() }}
Can you try to add Pagination like this.
#if(count($Jobs) > 0)
#foreach($Jobs as $Job)
{{ ucfirst(trans($Job->job_title)) }}
#endforeach
{{ $Jobs->links() }}
#endif
With your CSS class
#if(count($Jobs) > 0)
#foreach($Jobs as $Job)
{{ ucfirst(trans($Job->job_title)) }}
#endforeach
<div class="pagination-test">
{{ $Jobs->links() }}
</div>
#endif
Edited Update
Try With With in controller
return view('veteran.job-posting.index')->with('Jobs',$Jobs);
Update your controller's function return and use compact function for to pass jobs to view.
$jobs = Job::orderBy("id", "asc")->paginate(5);
return view("jobs", compact("jobs"));
You need to add this for pagination in blade.
<ul class="pagination" >
{!! $Jobs->render() !!}
</ul>
I don't know exactly why I'm getting this error as indicated by title. I am trying to write the code fro deleting records. This is the code below.
<TABLE >
#foreach($users as $user)
<TR><TD>{{ $user->id }}</TD><TD>{{ $user->firstname }}</TD><TD><div id="divContainer"><div class="theDiv"><form action="/users/{{ $users->id }}" method="POST"> {{ csrf_field() }} {{ method_field('DELETE') }}<button class="css-deletebutton">DELETE</button></form></div></div></TD><TD>{!! Form::submit('DEACTIVATE', ['class'=>'css-statusbutton']) !!}</TD></TR>
#endforeach
<!--{!! $users->render() !!}-->
</TABLE>
This is the route:
Route::resource('users', 'UserController');
This is the controller method:
public function show($id)
{
$users = User::find($id);
return view('userpages.show')->with('users', $users);
}
This is the view to be displayed for deletion of any record.
#section('body')
{!! Form::open([ 'method' => 'delete', 'route' => ['users.destroy', $users->id]]) !!}
<TABLE>
<TR><TD>{{ $users->firstname }}</TD><TD>{{ $users->lastname }}</TD><TD>{{ $users->email }}</TD><TD>{{ $users->username }}</TD><TD>{!! Form::submit('DELETE', ['class'=>'css-deletebutton']) !!}</TD></TR>
</TABLE>
{!! Form::close() !!}
#stop
This is the error message I'm getting:
ErrorException in acf1a7ad2174bd2b743200b1a50b4c9f line 14:
Undefined property: Illuminate\Database\Eloquent\Collection::$id (View: C:\Users\ken4ward\Documents\xampp\htdocs\schoolproject\resources\views\userpages\index.blade.php)
I can see you are referring to $users->id within the foreach loop in the first code snippet - that's what's causing the error you're getting. $users is the variable that holds the collection and $user is the variable that you should use to access user's data, including user's ID.
I have a loop foreach in a blade template where i print data from a specific model, the problem is I am not able of getting the value of "$pedido->proveedor()->first()->name" in the code giveing me this error "ErrorException (E_UNKNOWN) Trying to get property of non-object (View: C:..":
#foreach($pedidos as $pedido)
<tr>
<td>
{{ $pedido->id }}
</td>
<td>
{{ $pedido->proveedor()->first()->name }}
</td>
<td>
{{ date('d/m/Y', $pedido->fecha) }}
</td>
<td>
<a onclick="return confirm('deseas borar este registro?')" class="btn btn-danger btn-xs fullButton">Borrar</a>
</td>
</tr>
#endforeach
The weird thing here is when I code this "$pedido->proveedor()->first()" in side the loop of the template I get an object like this:
{"name":"nombre","domicilio":"domicilio","cp":"46006","poblacion":"poblacion","ciudad":"ciudad","pais":"pais"}
but coding this "$pedido->proveedor()->first()->name" I get the error:
the data is sent from a controller:
public function listPedidos()
{
$pedidos = Pedido::all();
// this next pice of code shows me i can get the name as spected but only from php
// foreach($pedidos as $pedido){
// ddd($pedido->proveedor()->first()->name);exit;
// }
return View::make('pedidos/pedidos-list')->with('pedidos', $pedidos);
}
Another weirder thing is that I have the same code with different model and it is working.
Thanks in advance for any help. ;)
You should use:
{{ $pedido->proveedor->name }}
Problem solved:
the previos answer was ok. I can use:
{{ $pedido->proveedor()->first()->name }}
or
{{ $pedido->proveedor->name }}
but because in one of the way of the loop there was not content to refer to i.e($pedido->proveedor didn't exixt) I use this:
{{ isset($pedido->Proveedor->name )?$pedido->Proveedor->name :''; }}