I am trying to get data from my table and show it in my view and paginate this data. I received this problem and couldn2t find any solution. I did the exactly same thing in my previous project and it worked well.
here is my Controller
public function hadiBirlikteCalisalimShow (){
$users =DB::table('birlikte_calisalim')->paginate(15);
return view('admin.birliktecalisalim',compact(['users']));
}
and this is my view
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>İsim</th>
<th>Email</th>
<th>Tarih</th>
<th>İstek</th>
</tr>
</thead>
<tbody>
#foreach($users as $row)
<tr>
<td>{{$users->name}}</td>
<td>{{$users->email}}</td>
<td>{{$users->tarih}}</td>
<td>{{$users->message}}</td>
</tr>
#endforeach
</tbody>
</table>
{{$users->links()}}
#foreach($users as $row)
<tr>
<td>{{$row->name}}</td>
<td>{{$row->email}}</td>
<td>{{$row->tarih}}</td>
<td>{{$row->message}}</td>
</tr>
#endforeach
should be $row->name,$row->email, etc... not $users->name, and change {{$users->links()}} to {!! $users->render() !!}
Related
On my controller take data via foreach where the $upcoming->order_id is same I am checked by dd($notes) data is show but i can't get on my view php. before I am tried $note->get('amount') method it is also not working
public function index()
{ $upcomings = Booking_informations::Upcoming();
$notes = [];
foreach ($upcomings as $upcoming) {
$notes[] = Notes :: where('order_id',$upcoming->order_id)-> orderBy('id', 'ASC')->get();
};
return View('upcoming',compact('upcomings','notes',));
}
upcoming.blade.php
<table class="table table-bordered mb-0">
<tbody>
#foreach($notes as $note )
<tr>
<th scope="row">1</th>
<td>{{date('d-M-Y', strtotime($note->created_at))}}</td>
<td>{{$note->details}} </td>
<td>{{$note->amount}} </td>
</tr>
#endforeach
</tbody>
</table>
I have got answer while wrote below method have any more simple way for get results..
<table class="table table-bordered mb-0">
<thead>
<tr>
<th>#</th>
<th>Date</th>
<th>Content</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
#foreach($notes as $note )
#foreach($note as $id )
<tr>
<td scope="row">1</td>
<td>{{$id->details}} </td>
<td>{{$id->amount}} </td>
</tr>
#endforeach
#endforeach
</tbody>
</table>
Try referencing $note instead of $notes in your foreach loop and see if that works.
I have also noticed that you have named your view file View.blade.php. Should this be upcoming.blade.php to match the name you have provided in the returned view? Just a thought.
My code is here if you want any other section of code, i will provide also that piece of code
<div class="panel-heading ">Organization Profile</div>
<table class="table table-striped">
<thead>
<tr>
<th>Attributes</th>
<th>Values</th>
</tr>
</thead>
<tbody>
<tr>
<td>Org Name</td>
<td>{{$org->name}}</td>
</tr>
<tr>
<td>Owner Name</td>
<td>{{$org->owner}}</td>
</tr>
</tbody>
</table>
</div>
Trying to get property of non-object issue usually comes in Laravel when you are returning array but try using object in your blade file or not passing the correct object string at all.
I notice from comments that you are passing $orgs, not $org in the function.
public function create() {
return view('Admin.organizations.create',compact('orgs'));
}
Update your blade file like below:
<div class="panel-heading ">Organization Profile</div>
<table class="table table-striped">
<thead>
<tr>
<th>Attributes</th>
<th>Values</th>
</tr>
</thead>
<tbody>
<tr>
<td>Org Name</td>
<td>{{$orgs->name}}</td>
</tr>
<tr>
<td>Owner Name</td>
<td>{{$orgs->owner}}</td>
</tr>
Considering all the comments, you should probably have something like this in your controller:
public function show($id)
{
$org = Organization::find($id);
// $data = ['org', $id];
return view('Admin.organizations.show')->with(compact('org'));
}
and this is your blade view:
<div class="panel-heading ">Organization Profile</div>
#if (empty($org))
<h1>Organization is empty</h1>
#else
<table class="table table-striped">
<thead>
<tr>
<th>Attributes</th>
<th>Values</th>
</tr>
</thead>
<tbody>
<tr>
<td>Org Name</td>
<td>{{$org->name}}</td>
</tr>
<tr>
<td>Owner Name</td>
<td>{{$org->owner}}</td>
</tr>
</tbody>
</table>
#endif
</div>
Of course not knowing what is in the Organization model would keep us from knowing whether owner and name exist as properties of the model.
Hello i am a laravel beginner , when i do foreach its shows double of all single items what should i do with it code and ss are below
Brower image
code
<div >
<h1 style="text-align: center">Lists of Outlets</h1>
#foreach($outlets as $outlet)
<table class="table table-striped">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
</tbody>
</table>
#endforeach
</div>
The issue is, you have put the entire table inside the loop, which is wrong. You have to only put the tr inside the loop.
Try this:
#foreach($outlets as $outlet)
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
#endforeach
and one more thing, you are also using the static content inside the loop instead of using the loop variable value. So instead of:
<td>john#example.com</td>
it is something like:
<td>{{ $outlet['name'] }}</td> <!-- where name is the index in outlet array -->
#foreach should be inside <tbody> and instead of hard-coded content, you should be using $outlet variable to get firstname, lastname and Email:
<div>
<h1 style="text-align: center">Lists of Outlets</h1>
<table class="table table-striped">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
#foreach($outlets as $outlet)
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
#endforeach
</tbody>
</table>
</div>
I have a table display and each row contains a button. With this button l have to pass the id to the controller where using this Admin can view user details one by one.
<table id="example2" class="table table-bordered table-hover" style="text-align: center">
<thead>
<tr>
<th>Applicant ID</th>
<th>Full name</th>
<th>Position applied</th>
<th>Date & time applied</th>
<th>View CV</th>
</tr>
</thead>
<tbody>
#foreach ($jobapplied as $row)
<tr>
<td>{{$row->app_id}}</td>
<td>{{$row->fullname}}</td>
<td>{{$row->position}}</td>
<td>{{$row->created_at}}</td>
<td>
<button type="submit" class="btn btn-
default" name="viewcv"> View</button> <br>
<br>
</td>
</tr>
#endforeach
</tbody>
</table>
Please check the code , hope it helps:
<table id="example2" class="table table-bordered table-hover" style="text-align: center">
<thead>
<tr>
<th>Applicant ID</th>
<th>Full name</th>
<th>Position applied</th>
<th>Date & time applied</th>
<th>View CV</th>
</tr>
</thead>
<tbody>
#foreach ($jobapplied as $row)
<tr>
<td>{{$row->app_id}}</td>
<td>{{$row->fullname}}</td>
<td>{{$row->position}}</td>
<td>{{$row->created_at}}</td>
<td>CV</td>
</tr>
#endforeach
</tbody>
</table>
Assuming you want to pass the field "id" or change it according to your requirement.
If you want to link to a show view, try something like this:
#foreach ($jobapplied as $row)
<tr>
<td>{{$row->app_id}}</td>
<td>{{$row->fullname}}</td>
<td>{{$row->position}}</td>
<td>{{$row->created_at}}</td>
<td>
<a href="{{action('JobController#show', $row->id)}}" class="btn btn-default">View</button>
</td>
</tr>
#endforeach
This will create a link to a view, where you can show the data.
In your controller JobController, you must create a function that receives the data:
public function show(Request $request, $id) {
...
}
Just pass the id of the record to controller function and get the details from database.
<td>
View <br>
</td>
I am using laravel pagination. When I click on next page or any page number, nothing happens.
Controller function
public function getIndex()
{
$articles = Inspector::paginate(15);
return view('admin.inspector.test', compact('articles'));
}
View file
<table class="table table-bordered" id="mytable">
<thead>
<tr>
<th>Sr. No. </th>
<th>Email</th>
</tr>
</thead>
<tbody>
#foreach ($articles as $article)
<tr>
<td>{{ $article->id }}</td>
<td>{{ $article->email }}</td>
</tr>
#endforeach
</tbody>
</table>
{!! $articles->render() !!}
Any help is much appreciated...Thanks...
public function getIndex()
{
return view('admin.inspector.test');
}
just return view while calling the action. dont send any data from the controller, just load the view,
when the view loads, fetch the db connection with pagination method. and render the pagination as below
<?php $articles = DB::connection('table_name')->where('if any condition')->get(); ?>
<table class="table table-bordered" id="mytable">
<thead>
<tr>
<th>Sr. No. </th>
<th>Email</th>
</tr>
</thead>
<tbody>
#foreach ($articles as $article)
<tr>
<td>{{ $article->id }}</td>
<td>{{ $article->email }}</td>
</tr>
#endforeach
</tbody>
</table>
{!! $articles->render() !!}