Undefined property: Symfony\Component\HttpFoundation\ParameterBag::$dated (export excel using maatwebsite) - laravel

i got error and i don't know what the error is this
in my controller
public function exportExcel(Request $data)
{
return Excel::download(new VgetAttGeneralExport($data), 'rekap-perkelas.xlsx');
}
here's my request
0:{keyid: 6046, att_seq: 6046, att_enumber: "101415287", att_method: null, att_workcode: null,…}
in my export folder
namespace App\Exports;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\Exportable;
class VgetAttGeneralExport implements FromView
{
use Exportable;
public $data;
/**
* #return \Illuminate\Support\Collection
*/
public function __construct($data) {
$this->data = $data;
}
public function view(): View
{
$data = $this->data;
return view('exports.Kehadiran',compact('data'));
}
}
and this my view
<table>
<tbody>
#foreach($data as $item)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $item->dated }}</td>
<td>{{ $item->employee_id }}</td>
<td>{{ $item->employee_name }}</td>
<td>{{ $item->tingkat }}{{$item->div_name}}{{$item->kelas}}</td>
<td>{{ $item->stat_name }}</td>
<td>{{ $item->stat_desc }}</td>
</tr>
#endforeach
</tbody>
</table>
i've tried many way and i got stuck, anyone please help me, i'am very beginner in api laravel

Related

How to clear undefined variable Laravel 9.48.0

public function student(){
$users=DB::select('select * from details');
return view('welcome',['users'->$users]);
}
#foreach ($users as $user)
<tr>
<td>{{ $user->id }}</td>
<td>{{ $user->email}}</td>
<td>{{ $user->status}}</td>
<td>{{ $user->subject}}</td>
</tr>
#endforeach
don't use raw sql query instead you can do it like this
public function student()
{
$users=Details::all();
return view('welcome',compact('users'));
}
or like this
public function student()
{
$users = DB::table('details')
->select('*')
->get();
return view('welcome', compact('users'));
}
and then in your blade you could get it like this
#isset($users)
#foreach ($users as $user)
<tr>
<td>{{ $user->id }}</td>
<td>{{ $user->email }}</td>
<td>{{ $user->status }}</td>
<td>{{ $user->subject }}</td>
</tr>
#endforeach
#endisset

how to retrieve one to many relationship. Property [produks] does not exist on this collection instance

Operator Model
public function produk()
{
return this->hasMany(Produk::class);
}
Produk Model
public function operator()
{
return this->belongsTo(Operator::class);
}
Controller
public function operator()
{
$data = Operator::all();
return view('data', compact('data'));
}
View
#foreach ($data as $o)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $o->n_oper }}</td>
<td>
#foreach ($data->produk as $p)
{{ $p->n_prod }}
#endforeach
</td>
</tr>
#endforeach
Output
Exception
Property [produk] does not exist on this collection instance. (View: C:\xampp\htdocs\laravel\oni\resources\views\data.blade.php)
what went wrong? please kindly assist me, im new to this
this is a typo may be?? whatever, you are calling relationship on collection. relation belongs to an object.
#foreach ($data as $o)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $o->n_oper }}</td>
<td>
#foreach ($o->produk as $p)
{{ $p->n_prod }}
#endforeach
</td>
</tr>
#endforeach
data is the collection. you have to call relationship on $o
and there's some other typos may be. you are missing the $ sign in $this keyword. update your relationship
public function produk()
{
return $this->hasMany(Produk::class);
}
and
public function operator()
{
return $this->belongsTo(Operator::class);
}
You are calling relation on collection. You have to call it on single instance like this
#foreach ($data as $o)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $o->n_oper }}</td>
<td>
#foreach ($o->produk as $p)
{{$p->n_prod}}
#endforeach
</td>
</tr>
#endforeach
And also change
return this->hasMany(Produk::class);
this to
return $this->hasMany(Produk::class);
and also for other relation like
return this->belongsTo(Operator::class);
to
return $this->belongsTo(Operator::class);
I hope its work.

show all subjects offered by a student using laravel eloquent

I have done one-to-many relationships but when I loop through it in my view only one subject displays even when I have more than one subjects.
This is what I have done in my controller
$broadsheet = Broadsheet::with(['subject', 'session', 'term', 'student', 'classarm'])
->where('session_id', $request->sessions)
->where('term_id', $request->terms)
->where('class_arm_id', $request->classarms)
->selectRaw('sum(total) as totals, count(subject_id) as countrow, student_id, subject_id, session_id, term_id, class_arm_id, total')
->groupBy('student_id')
->orderBy('totals', 'desc')
->get();
return view('broadsheet.index')->with('broadsheet', $broadsheet);
This is the index view
#extends('layouts.app')
#section('content')
{{--#foreach($broadsheet as $subjects)
#foreach ($subjects->subject as $sub)
<th> {{ strtoupper($sub->subject->subject_name) }}</th>
#endforeach
#endforeach--}}
<div class="table-responsive">
<table class="table table-striped table-sm">
<thead>
<tr>
#foreach($broadsheet as $subject)
<th> {{ strtoupper($subject->subject->subject_name) }}</th>
#endforeach
<th>TOTAL</th>
<th>AVERAGE</th>
<th>POSITION</th>
</tr>
</thead>
<tbody>
#foreach($broadsheet as $result)
<tr>
<td>{{ $result->total }}</td>
<td>{{ $result->totals }}</td>
<td>{{ number_format($result->totals/$result->countrow,2) }}</td>
<td>{{ $i++ }}</td>
<td>{{ $result->exams }}</td>
<td>{{ $result->total }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
#endsection
and this is my Broadsheet schema
class Broadsheet extends Model
{
use HasFactory;
protected $fillable = [
'student_id',
'subject_id',
'session_id',
'term_id',
'class_arm_id',
'subject_total',
];
public function student()
{
return $this->belongsTo(Student::class, 'student_id');
}
public function subject()
{
return $this->belongsTo(Subject::class, 'subject_id');
}
public function session()
{
return $this->belongsTo(Session::class, 'session_id');
}
public function term()
{
return $this->belongsTo(Term::class, 'term_id');
}
public function classarm()
{
return $this->belongsTo(ClassArm::class, 'class_arm_id');
}
}
I want to display students results like this
Intended result
Please, I would really need assistance to get this working as any help would be greatly appreciated.I just started learning laravel recently. I don't really know where the issue is coming from

group data in foreach in laravel

I have this table
here's the index function
use App\GrantLoanAmount;
use App\LoanAmount;
use App\User;
use App\Profile;
public function index(Request $request)
{
$defaultAmount = LoanAmount::where('default', 1)->first();
$grantloanamounts = GrantLoanAmount::with('users','amounts')->get();
return view('loan.grant-loan-amounts.index', compact('grantloanamounts'))
->with('defaultAmount',$defaultAmount);
}
here's my index blade table
#foreach($grantloanamounts as $item)
#if($item->amounts[0]->amount > $defaultAmount->amount)
<tr>
<td>{{ $item->users[0]->email }}</td>
<td>{{ $item->amounts[0]->amount }}</td>
<td>{{ $item->users[0]->name }}</td>
<td class="text-right">action buttons</td>
</tr>
#endif
#endforeach
How can I group the user name to become look like this?
username
amount
amount
amount

laravel get Data from table using model in laravel 5.2

i want to get vendor_name and user who assign order to vendor in view. But every time i got this error
ErrorException in b6bb559eccdc8a2d45a2d2d6ce89e8e217411386.php line 26:
Trying to get property of non-object (View: E:\xampp\htdocs\ftdindia\resources\views\view\Orders\allorder.blade.php)
in b6bb559eccdc8a2d45a2d2d6ce89e8e217411386.php line 26
at CompilerEngine->handleViewException(object(ErrorException), '1') in PhpEngine.php line 44
my codes are given below
Controller for Order
public function allorder(){
$orders = OrderGrid::paginate(100);
return view ('view.Orders.allorder', ['orders' => $orders]);
//dd($orders->all());
}
Here is My Model
class OrderGrid extends model{
protected $table = 'order_grids';
public function vendor() {
return $this->belongsTo(User::class);
}
public function assignedBy() {
return $this->belongsTo(User::class, 'vendor_assigned_by_user');
}
}
Here is my view
#foreach($orders as $order)
<tr>
<td> {{ $i }}</td>
<td>{{ $order->order_id }}</td>
<td>{{ $order->vendor->username }}</td>
<td>{{ $order->assignedBy->username }}</td>
<td>{{ $order->delivery_city }}</td>
<td>{{ $order->delivery_date }}</td>
<td>{{ $order->delivery_time }}</td>
<td>{{ $order->order_statuss }}</td>
<td>{{ $order->order_status }}</td>
<td>
#if(!$order->vendor_id)
Unassigned
#else
Assigned
#endif
</td>
<td></td>
</tr>
<?php $i +=1; ?>
#endforeach
#foreach($orders as $order)
<tr>
<td> {{ $i }}</td>
<td>{{ $order->order_id }}</td>
<td>{{ $order->vendor->username }}</td> inspite of this do <td>{{ !is_null($order->vendorName) ? $order->vendorName->username : null }}</td>
<td>{{ $order->assignedBy->username }}</td> and same here also <td>{{ !is_null($order->assignedBy) ? $order->assignedBy->username : null }}</td>
<td>{{ $order->delivery_city }}</td>
<td>{{ $order->delivery_date }}</td>
<td>{{ $order->delivery_time }}</td>
<td>{{ $order->order_statuss }}</td>
<td>{{ $order->order_status }}</td>
<td>
#if(!$order->vendor_id)
Unassigned
#else
Assigned
#endif
</td>
<td></td>
</tr>
<?php $i +=1; ?>
#endforeach
and in Model
public function vendorName() {
return $this->belongsTo('App\Model\User', 'vendor_id', 'id');
}
public function assignedBy() {
return $this->belongsTo('App\Model\User', 'assigned_by', 'id');
}
The error you are getting relates to how you are calling the vendor() function in the $order collection.
The docs are a good place for a solid understanding on this, but essentially all Eloquent relationships are defined via functions and so you may call those functions to obtain an instance of the relationship without actually executing the relationship queries.
As such it needs to be:
<td>{{ $order->vendor()->username }}</td>
Nothing that we are now chaining vendor() rather than vendor.

Resources