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? (31 h 16 min)

You also get:

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

Already a member? Login here

Comments & Discussion

E
exasad ✓ Link copied!

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?

PK
Povilas Korop ✓ Link copied!

In Filament 2, it is solved this way

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

MM
Mohamed Mostafa ✓ Link copied!

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