Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Contact Me Laravel Package

arindam/contact-me

A simple Laravel package that adds a “hi-arindam” route after installation. Install via Composer and, if needed, register the service provider manually. No specific PHP or Laravel version dependency claimed.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require dev-arindam-roy/contact-me
    

    Publish the package configuration (if needed):

    php artisan vendor:publish --provider="ArindamRoy\ContactMe\ContactMeServiceProvider"
    
  2. Configuration Edit config/contact-me.php to set:

    • Default email address
    • Contact form fields (name, email, message)
    • Recipient email(s)
    • Mail template (if customizing)
  3. First Use Case Add the contact form to a Blade template:

    @contactForm
    

    Or use the helper directly:

    use ArindamRoy\ContactMe\Facades\ContactMe;
    
    ContactMe::sendContactForm($request);
    

Implementation Patterns

Common Workflows

  1. Blade Integration

    • Use @contactForm directive in views for a pre-styled form.
    • Customize fields via config:
      'fields' => [
          'name' => 'Full Name',
          'email' => 'Email Address',
          'subject' => 'Subject',
          'message' => 'Your Message',
      ],
      
  2. API Endpoint Create a route:

    Route::post('/contact', [ContactMeController::class, 'store']);
    

    Controller:

    use ArindamRoy\ContactMe\Facades\ContactMe;
    
    public function store(Request $request) {
        $validated = $request->validate([
            'name' => 'required|string|max:255',
            'email' => 'required|email',
            'message' => 'required|string',
        ]);
    
        $response = ContactMe::sendContactForm($validated);
        return response()->json($response);
    }
    
  3. Custom Validation Extend validation logic via service provider:

    ContactMe::extendValidation(function ($validator) {
        $validator->after(function ($validator) {
            if (str_contains($validator->getData()['message'], 'urgent')) {
                $validator->errors()->add('message', 'Urgent messages require admin approval.');
            }
        });
    });
    
  4. Mail Template Overrides Publish and modify:

    php artisan vendor:publish --tag=contact-me-views
    

    Override resources/views/vendor/contact-me/email.blade.php.


Gotchas and Tips

Pitfalls

  1. Missing Configuration

    • If config/contact-me.php is not published, the package defaults to hardcoded values (e.g., contact@example.com).
    • Fix: Always publish config after installation.
  2. CSRF Token Mismatch

    • The Blade directive @contactForm assumes CSRF protection is enabled.
    • Fix: Ensure @csrf is present in the form or disable CSRF checks in the middleware (not recommended).
  3. Recipient Email Validation

    • The package does not validate recipient emails during runtime.
    • Tip: Add validation in your controller:
      if (!filter_var(config('contact-me.recipient_email'), FILTER_VALIDATE_EMAIL)) {
          throw new \Exception('Invalid recipient email configured.');
      }
      
  4. Queueing Delays

    • By default, emails are sent synchronously. For high-traffic sites, configure queueing:
      'queue' => true,
      
    • Note: Requires queue table and a queue worker (php artisan queue:work).

Debugging

  • Log Entries Enable debug mode in config:

    'debug' => env('APP_DEBUG', false),
    

    Logs will appear in storage/logs/laravel.log.

  • Test Mode Use ContactMe::setTestMode(true) to bypass email sending (useful for unit tests).

Extension Points

  1. Custom Fields Dynamically add fields via config:

    'custom_fields' => [
        'phone' => 'Phone Number',
        'company' => 'Company Name',
    ],
    

    Access in your controller:

    $phone = $request->input('phone', '');
    
  2. Attachment Support Extend the sendContactForm method to handle attachments:

    public function sendContactForm($data, $attachments = []) {
        // Custom logic to process attachments
    }
    
  3. Webhook Integration Trigger actions post-submission via events:

    // In ContactMeServiceProvider
    ContactMe::afterSend(function ($data) {
        // Send Slack notification, log to database, etc.
    });
    
  4. Localization Override labels via language files:

    php artisan vendor:publish --tag=contact-me-lang
    

    Edit resources/lang/en/contact-me.php.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky