Create a TabsLayout with a slot like you already mentioned.
Apr 1, 2024
3
Level 1
Laravel, Inertia - How make tabs logic
I have laravel10 prject, with vue3 and inertia
I have routers in web.php:
Route::resources([
'roles' => RoleController::class,
'users' => UserController::class,
]);
For example RoleController , index action:
public function index()
{
return inertia('Roles/Index', [
'roles' => Role::orderBy('id','ASC')->get()
]);
}
I also have settings page:
Route::get('settings', [SettingsController::class, 'index'])->name('settings');
class SettingsController extends Controller
{
public function index(){
return inertia('Settings/Index');
}
}
I want on settings page have tabs, like this
<div class="flex flex-col border rounded-md">
<ul class="flex overflow-x-auto px-4 py-2 rounded-t-md bg-gray-200">
<li class="cursor-pointer relative mr-2 px-3 py-2 text-sm font-medium text-gray-700 rounded-t-md"
:class="{ 'bg-white font-bold text-gray-900': activeTab === 'roles' }"
>
<Link :href="route('roles.index')">Roles</Link>
</li>
<li class="cursor-pointer relative mr-2 px-3 py-2 text-sm font-medium text-gray-700 rounded-t-md"
:class="{ 'bg-white font-bold text-gray-900': activeTab === 'users' }"
>
<Link :href="route('users.index')">Users</Link>
</li>
</ul>
<div class="px-4 py-6 border-t">
<div class="space-y-4">
Active tab content....
</div>
</div>
</div>
And i want if I click on 'Roles' - will show on 'Active tab content...' content from route('roles.index') ,if click on 'Users' - show content from route('users.index')
Is it possible? Tried to find solution like with <router-view>...
Or I need to use <slot> logic? And create like 'TabsLayout' and on pages 'Roles/Index , 'Users/Index'use that layout
What is best solution? Thanks
Please or to participate in this conversation.