To customize the component name used by Jetstream with Inertia without modifying the vendor files directly, you can follow these steps:
- Publish Jetstream's Controllers: First, you need to publish the Jetstream controllers to your application so that you can modify them. You can do this by running the following Artisan command:
php artisan vendor:publish --tag=jetstream-controllers
This command will copy the Jetstream controllers to your app/Http/Controllers directory.
-
Modify the Controller: Next, locate the
UserProfileControllerin yourapp/Http/Controllersdirectory (it should have been published there in the previous step). Update theshowmethod to point to your new Vue component path:
// app/Http/Controllers/UserProfileController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Laravel\Jetstream\Jetstream;
use Laravel\Jetstream\Features;
class UserProfileController extends Controller
{
// ...
public function show(Request $request)
{
$this->validateTwoFactorAuthenticationState($request);
return Jetstream::inertia()->render($request, 'profile/ProfileShowPage', [
'confirmsTwoFactorAuthentication' => Features::optionEnabled(Features::twoFactorAuthentication(), 'confirm'),
'sessions' => $this->sessions($request)->all(),
]);
}
// ...
}
-
Update the Route: If you haven't already, you may need to disable the default Jetstream routes and define your own in the
routes/web.phpfile. You can disable the default Jetstream routes by commenting out or removing the correspondingJetstream::inertiaRoutes()call in yourroutes/web.phpfile.
Then, define your own route that uses your published controller:
// routes/web.php
use App\Http\Controllers\UserProfileController;
// ...
Route::get('/user/profile', [UserProfileController::class, 'show'])
->name('profile.show');
-
Move and Rename Vue Component: Finally, move your Vue component to the desired location and rename it accordingly. In your case, move
Show.vuefromresources/js/Pages/Profiletoresources/js/pages/profileand rename it toProfileShowPage.vue. -
Update the Inertia Page Import: If you're using auto-discovery for Inertia pages (e.g., using
require.context), make sure that the new path and component name are correctly resolved. If you're manually importing components, update the import paths where necessary.
After completing these steps, you should be able to use your custom component structure with Jetstream and Inertia while still leveraging the original logic provided by Jetstream. Remember to never modify the files directly in the vendor directory, as these changes will be lost when you update your dependencies.