Tabs

Good evening, i have a question about customizing tabs. I have a relationship between projects and services table. Here is the table.
Project Table
Schema::create('projects', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->uuid('service_id')->nullable();
$table->string('name');
$table->string('slug')->unique();
$table->string('image')->nullable();
$table->string('description');
$table->timestamps();
});

Schema::table('projects', function (Blueprint $table) {
$table->foreign('service_id')
->references('id')
->on('services');
});
Project Table
Schema::create('projects', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->uuid('service_id')->nullable();
$table->string('name');
$table->string('slug')->unique();
$table->string('image')->nullable();
$table->string('description');
$table->timestamps();
});

Schema::table('projects', function (Blueprint $table) {
$table->foreign('service_id')
->references('id')
->on('services');
});
Service Table
Schema::create('services', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('name');
$table->string('slug')->unique()->nullable();
$table->string('description')->nullable();
$table->string('icon');
$table->timestamps();
});
Service Table
Schema::create('services', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('name');
$table->string('slug')->unique()->nullable();
$table->string('description')->nullable();
$table->string('icon');
$table->timestamps();
});
My goal is to show all projects for each service and the total projects. I managed to implement the tabs but without the total projects of each service.
1 Reply
einnlleinhatt_
einnlleinhatt_9mo ago
This is my tabs code.
public function getTabs(): array
{
return [
'all' => Tab::make('All Projects')
->badge(Project::count()),

'mobile' => Tab::make('Android & iOS')
->modifyQueryUsing(function ($query) {
$query->whereHas('service', function ($subQuery) {
$subQuery->where('name', 'Android & iOS');
});
}),

'code' => Tab::make('Web Development')
->modifyQueryUsing(function ($query) {
$query->whereHas('service', function ($subQuery) {
$subQuery->where('name', 'Development');
});
}),

'design' => Tab::make('Website Design')
->modifyQueryUsing(function ($query) {
$query->whereHas('service', function ($subQuery) {
$subQuery->where('name', 'Website Design');
});
}),
];
}
public function getTabs(): array
{
return [
'all' => Tab::make('All Projects')
->badge(Project::count()),

'mobile' => Tab::make('Android & iOS')
->modifyQueryUsing(function ($query) {
$query->whereHas('service', function ($subQuery) {
$subQuery->where('name', 'Android & iOS');
});
}),

'code' => Tab::make('Web Development')
->modifyQueryUsing(function ($query) {
$query->whereHas('service', function ($subQuery) {
$subQuery->where('name', 'Development');
});
}),

'design' => Tab::make('Website Design')
->modifyQueryUsing(function ($query) {
$query->whereHas('service', function ($subQuery) {
$subQuery->where('name', 'Website Design');
});
}),
];
}