Undefined property: stdClass::$point - php

I want to display user data in table but when I display point i got the error
Undefined property: stdClass::$point (View:
C:\xampp\htdocs\Gelecek_Üyeliği_Sistemi_f\Gelecek_Üyeliği_Sistemi_f\resources\views\backend\usersaction\total.blade.php)
this is the function i use it to display the data in view
public function ViewActionUserTotal() {
$total = DB::table("action_users")
->join("users", "users.id", "action_users.user_id")
->select("users.id","users.name","users.email", DB::raw("sum(action_users.point)"))
->groupBy("users.id","users.name","users.email",)->get();
return view('backend.usersaction.total',compact('total'));
}
here is the foreach in the table
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr>
<th>User Name</th>
<th>User Email</th>
<th>Total Point</th>
</tr>
</thead>
<tbody>
#foreach($total as $tot)
<tr>
<td>{{$tot->name}}</td>
<td>{{$tot->email}}</td>
<td>{{$tot->point}}</td>
</tr>
#endforeach
</tbody>
</table>
when i use dd for the data it show like that

I think you forgot to make an alias for sum query .Your query should be like this :
$total = DB::table("action_users")
->join("users", "users.id", "action_users.user_id")
->select("users.id","users.name","users.email", DB::raw("sum(action_users.point) as point"))
->groupBy("users.id","users.name","users.email",)->get();
For more :https://laravel.com/docs/7.x/database#running-queries

Related

How to filter a dynamic table in Laravel 9 by variable "type"?

I am trying to filter a dynamic table in Laravel 9 by variable "type" but I don't know the value of the type because it is inserted automatically by the user.
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>IdPp</th>
<th>Name</th>
<th>Type</th>
<th>Position</th>
</tr>
</thead>
<tbody>
#foreach($parts as $part)
<tr>
<th>{{$part->id}}</th>
<th>{{$part->Name}}</th>
<th>{{$part->type->intituléTypePP}}</th>
<th>{{$part->position->intituléPositionP}}</th>
</tr>
#endforeach
</tbody>
</table>

Property [id] [details] [details] [amount] does not exist on this collection instance

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.

Laravel 5.4: execute a raw query and show data in view

I want to run a raw query which I have written in my controller and want to show the data from database in my view.
This is my controller function:
public function unverified_jobs_page()
{
$query = "SELECT jd.*, cd.`company_name`, jc.`category_title`, jt.`job_type_title`, cc.`city_name`
FROM `job_details` AS jd
JOIN `company_details` AS cd ON cd.`company_id`=jd.`company_id`
JOIN `job_category` AS jc ON jc.`category_id`=jd.`category_id`
JOIN `job_type` AS jt ON jt.`job_type_id`=jd.`job_type_id`
JOIN `city` AS cc ON cc.`city_id`=jd.`city_id`
WHERE jd.`is_verified`='NO'
ORDER BY jd.`date_posted` DESC";
$sql = General_model::rawQuery($query);
return view('adminpanel.jobs.unverfied_jobs',compact($sql));
}
This is my model function rawQuery()
public static function rawQuery($query)
{
return DB::select( DB::raw($query) );
}
This is my view:
<table class="table table-striped border-top" id="sample_1">
<thead>
<tr>
<th>JOB ID </th>
<th>TITLE</th>
<th>COMPANY</th>
<th>CITY</th>
<th>DATE POSTED</th>
<th>CLOSING DATE</th>
<th> </th>
</tr>
</thead>
<tbody>
#foreach($sql as $d)
<tr>
<td>{{$d->job_id}}</td>
<td>{{$d->job_title}}</td>
<td>{{$d->company_name}}</td>
<td>{{$d->city_name}}</td>
<td>{{$d->date_posted}}</td>
<td>{{$d->expiry_date}}</td>
<td><a class='btn btn-info' href='#'>DETAILS</a></td>
</tr>
#endforeach
</tbody>
</table>
Now the problem is, every time I try to run the page, it gives me the following error:
ErrorException in 10f46e45beef75fdd05b083aa636ae7821fe6936.php line 30:
Undefined variable: sql (View: C:\AppServ\www\jobs\jobs\unverfied_jobs.blade.php)
Please Help.
You need to pass the variable $sql in to your view properly.
Try
compact('sql');

Undefined property: Illuminate\Pagination\LengthAwarePaginator::$name

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() !!}

Laravel Has Many Through Only brings first record

Well that is my problem.
This is the public function in my model
public function traerDesc(){
return $this->hasManyThrough('App\modeloDescripcionVehiculos', 'App\modeloVehiculos', 'idDescripcion', 'id', 'idVehiculo');
}
This is the controller call
$data = [
'venta' => modeloAccion::where('accion', 'venta')->with('traerVehiculo', 'traerUsuario', 'traerCliente', 'traerTransaccion', 'traerVenta', 'traerDesc')->get(),
];
return view('modulos.general.informes')->with($data);
This is my table in the blade file
<table class="table table-striped table-bordered table-hover" id="myTable">
<thead>
<tr>
<th class="text-center">Vehiculo vendido</th>
<th class="text-center">Precio de compra</th>
<th class="text-center">Precio de venta</th>
<th class="text-center">Ganancia %</th>
<th class="text-center">Usuario</th>
<th class="text-center">Cliente</th>
<th class="text-center">Fecha venta</th>
</tr>
</thead>
<tbody>
#foreach($venta as $ventas)
<tr class="text-center">
#foreach($ventas->traerDesc as $descripcion)
<td>{{$descripcion->marca}}</td>
#endforeach
<td>{{$ventas->traerVehiculo->precioCompra}}</td>
<td>{{$ventas->traerVehiculo->precioVenta}}</td>
<td>asd</td>
<td>{{$ventas->traerUsuario->nombre.' '.$ventas->traerUsuario->apellidoPaterno.' '.$ventas->traerUsuario->apellidoMaterno}}</td>
<td>asd</td>
<td>{{date('d-m-Y', strtotime($ventas->traerVenta->fechaVenta))}}</td>
</tr>
#endforeach
</tbody>
</table>
This is my table accion. As you can see . It has 3 rows where accion = venta and all of them has the same info in all the tables. But it only brings the first row rejecting the others
And the view shows only 1 marca that would be like brand in english.
Hope can make myself clear enough. Thank you
Not sure it will help, but you use eager loading method with wrong way.
Right using is:
Model::with(relations)->where(condition)->get();
Or
Model::where(condition)->get()->load(relations);

Categories