giorg-332048 wrote a reply+100 XP
3mos ago
ok sorry, I was too quick being excited. This is my SuspensionDatatable:
<?php
namespace App\Datatables;
use App\Models\Customer;
use App\Models\Suspension;
use App\Models\User;
use Sebastienheyd\Boilerplate\Datatables\Column;
use Sebastienheyd\Boilerplate\Datatables\Datatable;
class SuspensionsDatatable extends Datatable
{
public $slug = 'suspensions';
public function datasource()
{
return Suspension::with('subscription');
}
public function setUp()
{
$this->order('id', 'desc');
}
public function columns(): array
{
return [
Column::add(__('First Name'))
->data('subscription.customer.first_name'),
...
because in the Model a Subscription can have multiple Suspension and belongs to one Customer, so my Suspension model has a method:
public function subscription(): BelongsTo { return $this->belongsTo(Subscription::class); }
so I thought: suspension->subscription->customer but I get Datatable error. I also tried adding 'customer' in the with statement, but same result. last try I did:
Column::add(__('Last Name'))
->data('subscription.id', function($s) {
$customer = Customer::findOrFail($s->subscription->customer_id);
return $customer->last_name;
}),
which shows me table but then I don't know how to add also first name and email which both belong to customer model. this way, also the search is not working. how to fix everything? many thanks
giorg-332048 wrote a reply+100 XP
3mos ago
giorg-332048 started a new conversation+100 XP
3mos ago
Hi,
I'm using Laravel 12 with sebastian heyd boiler plate (first day I post here so I cannot link the referring site. I'm trying to setup a datasource for a datatable, which works fine:
class SubscriptionsDatatable extends Datatable { public $slug = 'subscriptions';
public function datasource()
{
return Subscription::with('customer');
}
...
and in the blade I use:
<x-boilerplate::datatable name="subscriptions" id="subscriptions" />
all good this far, but as I try to search for example customer name it fails, I understood must something about query server side. I tried many solutions using claude or perplexity, but I'm not able to filter by customer name (which is obviously a join). How to I achieve that?
thanks a lot Andrea