dimanche 29 mars 2020

Contact Form With Google reCaptcha - Laravel 7

I have a form and Google Captcha in Laravel 7

enter image description here

I already include

use Request;

I still get this error after submitting my form

message: "Argument 1 passed to App\Http\Controllers\Controller::validate() must be an instance of Illuminate\Http\Request, instance of Illuminate\Support\Facades\Request given,

If I tried include

use Illuminate\Http\Request;

I will get

Class App\Http\Controllers\Request does not exist


This is what I have

public function store(Request $request)
{

    $inputs           = Request::all();
    $name             = str_replace('SELECT', '', $inputs['name']);
    $message          = str_replace('SELECT', '', $inputs['message']);
    $email            = str_replace('SELECT', '', $inputs['email']);

    $this->validate($request, [
        'name'    => 'required|max:255',
        'email'   => 'required|email',
        'message' => 'required',
        'captcha' => 'required|captcha',
    ]);

    $contact          = new Contact;
    $contact->name    = str_replace('*', '',$name);
    $contact->message = str_replace('*', '',$message);
    $contact->subject = str_replace('*', '',$message);
    $contact->email   = str_replace('*', '',$email);
    $contact->save();

    // dd($contact,$inputs);

    $mail = Mail::send('layouts.share.emails.contact', array(
        'message' => $message,
        'input' => $inputs
    ) , function ($message)
    {
        $message->from(env('MAIL_FROM') , 'www.jdoe.com');
        if(env('APP_ENV') == 'local'){
            $message->to(env('MAIL_TO') , 'John Doe')->subject(' Contact from '.env('APP_URL'));
        } else {
            $message->to(env('MAIL_TO') , 'John Doe')->subject(' Contact from www.jdoe.com ');
        }

    });

    return $contact;


}

How do I fix that ?

  • Should I use pass all my $inputs into it ?
  • How should I properly use the validate functions with the Google Captcha ?


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire