PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Question By
Solved

Adding form fields to Wave Registration view

Solved
mikemastercorp

Jul 20th, 2022 01:40 PM

Hello guys.

I am new to WAVE, and I was trying to add a few form fields to the MVC of WAVE, but am getting an error of 500. As far as I saw a very neat and simple way of adding extra fields to user profile, I would like to ask is there somewhere a video/tutorial of adding a new form field to registration page as well?

mikemastercorp

Jul 20th, 2022 04:21 PM

I've added my field to the User model after the name and added some validations to it.

I've also modified the UsersTableSeeder to apply the changes, and also added the field to my register.blade.php. I am able to find the field inside the Users bread, but submitting a registration returns error 500. What am I missing? :)

I've also modified for sure the RegisterController.php to apply the field changes there too.

Report
1
bobbyiliev

Jul 20th, 2022 11:40 PM

Best Answer

Hi there Mike,

Indeed, this should be more or less it:

  • Create a new migration to add the new columns to your users table (or do this via Voyager)
  • Add the fields to your Model
  • Then update the main/wave/src/Http/Controllers/Auth/RegisterController.php controller
  • And finally adjust the register.blade.php file

If this is still not working for you, can you enable the debug mode by setting DEBUG to TRUE in your .env file, that way you will see the actual error rather than the generic 500 error.

Feel free to share the error here so I could try to advise you further!

Best,

Bobby

mikemastercorp

Jul 21st, 2022 04:43 AM

Zdrasti, Bobby :)

Thanks for the quick reply. I was wondering how can I extend the user profile directly from Voyager as I did not find a way to add a new field via Voyager directly. Usually when I create a DB from Voyager, I am allowed to select the type of field, add it to the DB and then configure it in the BREAD, however when I navigated to the Users DB, I did not find the option of adding new fields directly there other than manipulating the existing ones. Can you share a screenshot, how can I add the field in Voyager?

EDUT: Sorry, I was editing the BNREAD but not the DB, Clicking on DB edit button to the right allowed me to get the Add New Column, Add TimeStamp or Soft delete. Let's see how it goes from there :) I just need to find what is the usual location of Models with Wave now..

mikemastercorp

Jul 21st, 2022 07:06 AM

So a quick update, I was able to add as many fields to my registration as needed by modifying the DB from Voyager (could be manually too) and then adding the validation rules as required.

My only "issue" is that I tried defining a few custom errors for the new field 'test.unique' but the error is still generic.

Here is my validation custom message inside the wave\src\Http\Controllers\Auth\RegisterController.php

'test.required' => 'Test error',

Am I on the right spoit? I was able to still add the custom message to my register.blade.php, however if there are more than 1 custom errors, it will prevent them from showing :(

mikemastercorp

Jul 21st, 2022 05:10 PM

Btw, googling a bit more in detail lead me to some earlier pulls of Voyager as the validation error messages are not overwritten by the validation defined ones but show the generic errors.

It would be great if you could provide an example of a default profile with a custom error for a REQUIRED field (email, for example).

So far, I must say that I love the symbiosis between WAVE and VOYAGER. Thanks for all the amazing PRO Perks :)

mikemastercorp

Jul 21st, 2022 09:12 PM

Seems like, after all, I got it working fine now using the same structured code:

'test.unique' => 'Your test field value is not unique'

The only question left is how can I pass some HTML/tailwind classes to the validation custom message so that it is styled and allows a URL to point to another link?

Report
1
bobbyiliev

Jul 22nd, 2022 12:36 AM

Neat! Happy to hear that you've got it all working!

I believe that it should be ok to define that directly in your blade view, for example here is how the password confirmation validation error is handled:

https://github.com/thedevdojo/wave/blob/main/resources/views/themes/tailwind/auth/register.blade.php#L103-L107

Let me know if anything else pops up!

mikemastercorp

Jul 22nd, 2022 05:24 AM

Hey Bobbyiliev,

I believe I've sorted all out, and it was again my mistake that after several code attempts, I was not echoing properly the error.

It is obvious that if I wanted the error to contain HTML markup, I should echo the error with the proper blade syntax allowing so. I got it all working correctly using:

{!! $errors->first('test') !!}

Kudo's for the spot-on help.

Report
1
bobbyiliev

Jul 22nd, 2022 06:25 AM

No problem at all! Happy to hear that it is all sorted out!