Making Data Dynamic when filtering by date #1116
-
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 30 replies
-
Hello @lrljoe , i would love to get your input here ! thanks |
Beta Was this translation helpful? Give feedback.
-
You'll need to use the when () function within your with() call in your builder. At the moment you're effectively saying Instead of |
Beta Was this translation helpful? Give feedback.
-
NOT RELATED TO THIS ISSUE : Desktop.2023.03.25.-.02.05.57.05.mp4as you can see in the video above, i have purchased before as yes or no, if yes i show green check with the project names it was linked to before here the code : Column::make("Purchased Before")
->sortable()
->label(
function ($row) {
$stringList = getPurchasedProjectsNames($row->orders->where('customer_id', auth()->id()));
if ($row->orders->where('customer_id', auth()->id())->isEmpty()) {
//red X
return '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 text-red-500">
<path stroke-linecap="round" stroke-linejoin="round" d="M9.75 9.75l4.5 4.5m0-4.5l-4.5 4.5M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>';
} else {
//green check
return '<svg x-tooltip.raw="' . $stringList . '" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-6 h-6 text-green-500">
<path stroke-linecap="round" stroke-linejoin="round" d="M9 12.75L11.25 15 15 9.75M21 12c0 1.268-.63 2.39-1.593 3.068a3.745 3.745 0 01-1.043 3.296 3.745 3.745 0 01-3.296 1.043A3.745 3.745 0 0112 21c-1.268 0-2.39-.63-3.068-1.593a3.746 3.746 0 01-3.296-1.043 3.745 3.745 0 01-1.043-3.296A3.745 3.745 0 013 12c0-1.268.63-2.39 1.593-3.068a3.745 3.745 0 011.043-3.296 3.746 3.746 0 013.296-1.043A3.746 3.746 0 0112 3c1.268 0 2.39.63 3.068 1.593a3.746 3.746 0 013.296 1.043 3.746 3.746 0 011.043 3.296A3.745 3.745 0 0121 12z" />
</svg>';
}
}
)
->html(),
// here is my configure
public function configure(): void
{
$this->setPrimaryKey('id')
->setDefaultSort('authority_score', 'desc')
->setPerPage(25)
->setPerPageAccepted([25, 50, 75, 100])
->setSingleSortingDisabled()
->setOfflineIndicatorEnabled()
->setQueryStringDisabled()
->setFilterLayoutSlideDown()
->setAdditionalSelects(['links.id as id'])
->setTrAttributes(function ($row, $index) {
return [
'class' => 'hover:bg-gray-100',
];
});
$this->arrayOfCountries = Link::select('country')->distinct()->pluck('country')->toArray();
$this->arrayOfProjects = Project::forAuthCustomer()->select('project_name')->distinct()->pluck('project_name')->toArray();
}
//my builder
public function builder(): Builder
{
return Link::query()
->with(['orders', 'orders.projects'])
->shownToCustomer()
->when(!empty($this->latest), fn ($query) => $query->where('created_at', '>=', Carbon::now()->subDays(7)))
->groupBy('site');
} this is my production app not the demo @lrljoe |
Beta Was this translation helpful? Give feedback.
You'll need to use the when () function within your with() call in your builder.
At the moment you're effectively saying
Get me projects
With all of their orders
Where the project has an order before/after x date
Instead of
Get me projects
With their orders where the order date is before/after x date.