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.
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 want to pass the parameter $questions to view, but it gives the following error:
ErrorException (E_ERROR)
Undefined variable: questions (View: C:\Users\Krishan\Documents\GitHub\GroupProject\lcurve\resources\views\quizz\questions\index.blade.php)
This is my controller index function part:
public function index()
{
$questions = Question::all();
return view('quizz/questions.index', compact('questions'));
}
This is a part Of my view:
<tbody>
#if (count($questions_options) > 0)
#foreach ($questions_options as $questions_option)
<tr data-entry-id="{{ $questions_option->id }}">
<td></td>
<td>{{ $questions_option->question->question_text or '' }}</td>
<td>{{ $questions_option->option }}</td>
<td>{{ $questions_option->correct == 1 ? 'Yes' : 'No' }}</td>
<td>
View-->
<!--Edit-->
{!! Form::open(array(
'style' => 'display: inline-block;',
'method' => 'DELETE',
'onsubmit' => "return confirm('".trans("quickadmin.are_you_sure")."');",
'route' => ['questions_options.destroy', $questions_option->id])) !!}
{!! Form::submit(trans('quickadmin.delete'), array('class' => 'btn btn-xs btn-danger')) !!}
{!! Form::close() !!}
</td>
</tr>
#endforeach
#else
<tr>
<td colspan="5">no_entries_in_table</td>
</tr>
#endif
</tbody>
enter image description here
where is questions_options coming from? You are passing questions. So your for loop should be
#if (count($questions) > 0)
#foreach ($questions as $question)
//rest of your code
#endforeach
#endif
and your return view part can be return view(quizz.questions.index, compact('questions'))
Firstly, the error message you have mention should be shown. The error message should be:
Undefined variable: questions_options (View:C:\Users\Krishan\Do........
Because you are passing questions to view but you are accessing question_options in view. So, it should say question_options in undefined in view.
Besides, do you know you can avoid this count check? You can use laravel's forelse tag here a below:
#forelse($questions as $question)
//Your table goes here
#empty
<tr>
<td colspan="5">no_entries_in_table</td>
</tr>
#endforelse
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.
Firstly it works fine But I don't know how to come this error in this page but this problem can be solve when i changed the code in view {{$training->first()->sectionsCount}} but my specification has been incorrect.
My complete error is:-
ErrorException in Training.php line 51: Trying to get property of non-object (View:resources/views/Training/index.blade.php)
My code in model is:-
public function sectionsCountRelation()
{
return $this->hasOne('App\Schedule')->selectRaw('training_id, count(*) as count')->groupBy('training_id')->where('training_end_date','<',carbon::now());
}
public function getSectionsCountAttribute()
{
return $this->sectionsCountRelation->count;<!--This is line 51 -->
}
In controller is
public function index()
{
$training = Training::with('sectionsCountRelation')->get();
return view('Training.index',compact('training'));
}
In View:-
#foreach ($training as $training)
<tr>
<td>{{$i}}</td>
<td>{{ $training->category }}</td>
<td>{{ $training->topic }}</td>
<td>{{$training->sectionsCount}}</td>
<td>Update</td>
<td>Schedule</td>
<td>
{!! Form::open(['method' => 'DELETE', 'route'=>['training.destroy', $training->id]]) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
<?php $i++;?>
{!! Form::close() !!}
</td>
</tr>
#endforeach
Looks like you have some Trainings that have no Schedule assigned. That means, $this->sectionsCountRelation returns null and you can't access ->count on it. Try checking for null:
public function getSectionsCountAttribute()
{
return $this->sectionsCountRelation === null ? 0 : $this->sectionsCountRelation->count;
}