Skip to main content

HasMany Relationship: Use withCount in Table

Premium
1:31

The Full Lesson is Only for Premium Members

Want to access all of our courses? (36 h 00 min)

You also get:

61 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

exasad avatar

user table have role column, role is user and admin, login user then redirect admin/dashboard, and login user redirect user/dashboard, it's posible?

Povilas Korop avatar

In Filament 2, it is solved this way

In Filament 3, it is solved with multiple panels, this way: course tutorial or YouTube video

Mohamed Mostafa avatar

i think this didn't work with me: in my case

My $table resource:

Tables\Columns\TextColumn::make('total_shipments')->counts('shipment')

Shipments Model:

public function company()
{
return $this->belongsTo(Company::class);
}

Company Model:

public function shipment()
{
return $this->hasMany(Shipment::class);
}

shipment Database schema:

Schema::create('shipments', function (Blueprint $table) {
$table->id();
$table->foreignId('vehicle_id')->constrained('vehicles');
$table->foreignId('driver_id')->constrained('drivers');
$table->foreignId('customer_id')->constrained('customers');
$table->foreignId('company_id')->constrained('companies');
$table->string('shipment_number')->unique()->nullable();
$table->string('status');
$table->string('from');
$table->string('to');
$table->text('description')->nullable();
$table->date('shipment_date');
$table->timestamps();
});

and returning empty values