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() !!}
Related
I tried to display all menus from the db in table form however i got an error saying that "undefined variable:menus(0)"
dashboard_index.blade.php
<div class= "menu-content">
<table class="table table-hover table-bordered">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">Category Code</th>
<th scope="col">Menu Title</th>
<th scope="col">Menu Price</th>
</tr>
</thead>
<tbody>
#foreach ($menus as $menu)
<tr>
<td>{{ $menu->id }}</td>
<td>{{ $menu->category_code }}</td>
<td>{{ $menu->menu_title }}</td>
<td>RM{{ $menu->menu_price }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
web.php
Route::get('/dashboard', 'AdminMenuController#index');
AdminMenuController.php
public function index()
{
$menus = \App\Menu::all();
return view('admin.dashboard_index',
[
'menus'=>$menus,
]);
}
You have a syntax error in $menu = \App\Menu::all()
it should be $menus = \App\Menu::all()
I'm beginner in laravel, when I put stats table in blade I got this warning
Attempt to read property "name" on array (View: C:\xampp\htdocs\Testing\resources\views\product.blade.php)
This is Controller
public function index()
{
$response = Http::get('https://api.lazada.co.id/rest/products/get?filter=live&app_key=100132&sign_method=sha256×tamp=1612318435886&access_token=50000801006o5nrcA5192d1f9ag1FHQBUqffCEyCmrXDohvhzExSkczUnnxJ4y&sign=F31584775544970D59AB58EC4B1B77933BC2D32401E33C1D2D5095690C31627C');
$data = $response->json();
return view('product',compact ('data'));
}
This is view:
#extends('layout/main')
#section ('title', 'Testing Laravel')
#section ('container')
<div class="container">
<div class="row">
<div class="col-10">
<h1 class="mt-3">List Product</h1>
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Desc</th>
<th scope="col">Brand</th>
<th scope="col">Clothing Material</th>
<th scope="col">Leather Material</th>
</tr>
</thead>
<tbody>
#foreach($data as $datas)
<tr>
<th scope="row">1</th>
<td>{{ $datas->name }}</td>
<td>{{ $datas-description }}</td>
<td>{{ $datas->brand }}<td>
<td>{{ $datas->clothing_material }}</td>
<td>{{ $datas->leather_material }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
#endsection
According to the error message its clearly saying Attempt to read property (because you are trying to access like $data->name <--OBJECT) on array and your foreach variable is array. so you will need to access like key value pair.
Use like this in loop-
{{ $data['name'] }}
{{ $data['description'] }}
I want to show data in tabular form in Laravel Blade View. Now, data is not showing up in blade, but when I check in controller using print_r it shows up Following is the code for Controller:-
public function index(){
$pickup = PickupLocation::select('*')
->whereNull('deleted_at')
->get()
->toArray();
$page = 'pickup_locations';
return view('backEnd.pickupManagement.index',compact('page'));
}
Following is the code in web.php:-
Route::match(['get','post'],'pickup-locations','backEnd\pickupManagement\PickupController#index');
And following is the code I am using View:-
<div class="table-responsive">
<table id="zero_config" class="table table-striped table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Contact Number</th>
<th>Address</th>
<th width="13%">Action</th>
</tr>
</thead>
<tbody>
#if(!empty($pickup))
#foreach($pickup as $key=>$value)
<tr>
<td>{{ ucfirst($value['name']) }}</td>
<td>{{ ucfirst($value['contact_no']) }}</td>
<td>{{ $value['location'] }}</td>
<td>
<i class="fa fa-edit"></i>
<i class="fa fa-trash"></i>
</td>
</tr>
#endforeach
#endif
</tbody>
</table>
</div>
add $pickup variable as second argument in your compact method.
Try like this
return view('backEnd.pickupManagement.index',compact('page', 'pickup')); }
Happy codding
#foreach($lastactivity as $activity)
{{ $activity }}
#endforeach
That is the for loop.
Now this is the output in the view.
{"id":2,"log_name":"index-log","description":"I visited index","subject_id":null,"subject_type":null,"causer_id":1,"causer_type":"App\\User","properties":[],"created_at":"2017-07-18 11:05:08","updated_at":"2017-07-18 11:05:08"}
How will I be able to put that in a table with all the columns and data arranged? Thank you very much.
You should use table.
<table>
<thead>
<tr>
<th>Log Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
#foreach($lastactivity as $activity)
<tr>
<td>{{$activity->log_name}}</td>
<td>{{$activity->description}}</td>
</tr>
#endforeach
</tbody>
</table>
In the same way, Add other fields as well.
You have to define your field name
{{ $activity->id }}
{{ $activity->log_name }}
etc
Like this:
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Log Name</th>
.
.
.
<th>Updated At</th>
</tr>
</thead>
<tbody>
#foreach($lastactivity as $activity)
<tr>
<td>{{ $activity->id }}</td>
<td>{{ $activity->log_name }}</td>
.
.
.
<td>{{ $activity-> }}</td>
</tr>
#endforeach
</tbody>
</table>
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() !!}