Reputation: 119
The first table "Offers" I store there offers details. If offer status = public then everyone able to access and status will be shown "Approved" in Yajra Datatable.
Otherwise, If offer status = request, the user can request for access. when they submit requests for access, It will be stored in Offer Request table with user id and offer id and with status = 0 means in yajra datatable status pending. then admin can set status = 1 mean in yajra datatable status approve.
I'm getting this error within this code.
NB: Sorry for bad English
->editColumn('status', function(Offer $offer) {
if($offer->offer_permission == 'public')
{
$status = '<span class="badge badge-primary">Approve</span>';
}elseif($offer->offer_permission == 'request')
{
$checkstatus= OfferRequest::select('status')->where('offer_id', $offer->id )->where('user_id', Auth::id())->pluck('status')->toArray();
if($checkstatus['status'] == 0)
{
$status = '<span class="badge badge-secondary">Pending</span>';
}elseif ($checkstatus['status'] == '1')
{
$status = '<span class="badge badge-primary">Approve</span>';
}elseif ($checkstatus['status'] == '2')
{
$status = '<span class="badge badge-danger">Rejected</span>';
}elseif ($checkstatus['status'] == '3')
{
$status = '<span class="badge badge-danger">Blocked</span>';
}else
{
$status = '<a href="' . route('offers.show', $offer->id) .'"><span class="badge badge-secondary">Apply Now</span></a>';
}
}
return $status;
})
Upvotes: 0
Views: 671
Reputation: 376
I think you should to add checkpoint for checkstatus variable that it's empty or not.
editColumn('status', function(Offer $offer) {
if($offer->offer_permission == 'public')
{
$status = '<span class="badge badge-primary">Approve</span>';
}elseif($offer->offer_permission == 'request')
{
$checkstatus= OfferRequest::select('status')->where('offer_id', $offer->id )->where('user_id', Auth::id())->pluck('status')->toArray();
if(empty($checkstatus)){
if($checkstatus['status'] == 0)
{
$status = '<span class="badge badge-secondary">Pending</span>';
}elseif ($checkstatus['status'] == '1')
{
$status = '<span class="badge badge-primary">Approve</span>';
}elseif ($checkstatus['status'] == '2')
{
$status = '<span class="badge badge-danger">Rejected</span>';
}elseif ($checkstatus['status'] == '3')
{
$status = '<span class="badge badge-danger">Blocked</span>';
}else
{
$status = '<a href="' . route('offers.show', $offer->id) .'"><span class="badge badge-secondary">Apply Now</span></a>';
}
}else{
$status = '<a href="' . route('offers.show', $offer->id) .'"><span class="badge badge-secondary">Apply Now</span></a>';
}
}
return $status;
})
Try it!
Upvotes: 2