fernandoAlco wrote a comment+100 XP
5mos ago
Hi, I really enjoyed this course, thank you!
If you're using the latest version of the Starter Kit with Wayfinder, I like this way of handling forms. We avoid using useForm, specify the PUT method, and the images are handled automatically. Just import Form from Inertia and PuppyController from actions.
<Form
{...PuppyController.update.form.put(puppy)}
options={{
preserveScroll: true,
}}
onSuccess={() => setOpen(false)}
className="space-y-6"
>
{({ processing, errors }) => (
<>
<Label htmlFor="name">Name</Label>
<Input
id="name"
name="name"
className="mt-1 block w-full"
defaultValue={puppy.name}
required
autoComplete="name"
placeholder="Full name"
/>
{errors.name && (
<p className="mt-1 text-xs text-red-500">
{errors.name}
</p>
)}
<Label htmlFor="trait">Personality trait</Label>
<Input
id="trait"
name="trait"
className="mt-1 block w-full"
defaultValue={puppy.trait}
required
placeholder="Personality trait"
/>
{errors.trait && (
<p className="mt-1 text-xs text-red-500">
{errors.trait}
</p>
)}
<Label htmlFor="image">Change image</Label>
<Input
id="image"
name="image"
type="file"
className="mt-1 block w-full"
placeholder="Profile picture"
/>
{errors.image && (
<p className="mt-1 text-xs text-red-500">
{errors.image}
</p>
)}
<DialogFooter className="gap-2">
<DialogClose asChild>
<Button variant="secondary">Cancel</Button>
</DialogClose>
<Button
className="relative disabled:opacity-100"
disabled={processing}
type="submit"
>
{processing && (
<div className="absolute inset-0 grid place-items-center">
<LoaderCircle className="size-5 animate-spin stroke-primary-foreground" />
</div>
)}
<span
className={clsx(
processing && 'invisible',
)}
>
Update
</span>
</Button>
</DialogFooter>
</>
)}
</Form>
fernandoAlco wrote a comment+100 XP
5mos ago
fernandoAlco liked a comment+100 XP
5mos ago
In order to implement versioning in Laravel 11 you need to update bootstrap\app.php
->withRouting(
web: __DIR__ . '/../routes/web.php',
api: __DIR__ . '/../routes/api.php',
commands: __DIR__ . '/../routes/console.php',
health: '/up',
then: function () {
Route::middleware('api')
->prefix('api/v1')
->group(base_path('routes/api_v1.php'));
Route::middleware('api')
->prefix('api/v2')
->group(base_path('routes/api_v2.php'));
// ... and so on
}
)