Skip to content
Snippets Groups Projects
Craig Smith's avatar
Craig Smith authored
6c0825f7

Laravel Contact Form by Custom D

installation

composer require custom-d/cd-contact-form

run php artisan cdcontactform:install to install

or Manuallu Publish the Migration and optionally the translations / config file

php artisan vendor:publish --tag=cd-contact-form-migrations
php artisan vendor:publish --tag=cd-contact-form-config
php artisan vendor:publish --tag=cd-contact-form-translations

php artisan migrate

(optional) Update your user model and add a the following scope:

public function scopeContactFormNotify(Builder $query): Builder
{
    return $query->where('role' , 'admin');
}

customimize the query according to your project.

If you would rather list the mail addresses, see the CD_CONTACT_FORM_NOTIFICATION_EMAILS Environmental Variable instead.

Environmental Variables

You'll need these variables set in your .env file.

NoCaptcha is used by default, you can obtain keys from Google

Name Purpose
CD_CONTACT_FORM_NOTIFICATION_EMAILS Raw email addresses that admin notifications will be sent to (comma separated)
NOCAPTCHA_SECRET The secret for NoCaptcha
NOCAPTCHA_SITEKEY The key for NoCaptcha

Configuration File

Many things are customisable via the published config file. Refer to documentation within the file.

Validation Rules

Validation rules can be set in the config file - under the key validation_rules and the messages under the key validation_messages

Translations

The notification emails are translatable with the following values available

Admin Notifications

  • subject: 'New message received from :Name',
  • greeting: '',
  • body_before: '### The following information was supplied',
  • body_after: '',

Customising additional field display:

in your AppServiceProvider boot method add:

AdminNotification::formatFieldsUsing(fn($name) => str($name)->replace('_', ' ')->title()->toString());