Target class error [Sendmailnewsletter] does not exist

Asked

Viewed 201 times

0

I am a beginner in Latin and I have a difficulty that I cannot solve. You are returning the following error:

Target class [SendMailNewsLetter] does not exist.

What should I do? I have searched the net, but without success. Thanks for your attention.

For better understanding, the following is the code.

HTML:

<form action="enviar" method="post">
     {{csrf_field()}}
     <div class="form-row">
         <div class="col-lg-8 form-group">
             <input type="email"
                    class="form-control input"
                    name="email"
                    id="email"
                    placeholder="Seu email"
                    data-msg="Por favor digite um email válido" />
             <div class="validate"></div>
         </div>
         <div class="col-lg-2 form-group">
             <div class="text-center">
                 <button class="btn-cor-especial" type="submit">Ok</button>
             </div>
         </div>
         <div class="mb-3">
             <div class="sent-message">Sua mensagem foi enviada. Obrigado!</div>
             <div class="loading">Carregando</div>
         </div>
     </div>
 </form>

Route:

 Route::post('enviar','SendMailNewsLetter@mailNewsLetter');

Controller:



class SendMailNewsLetter extends Controller
{
    public function mailNewsLetter(Request $request)
    {
        dd("ok");
    }
}
  • error happens while displaying or submitting the form? maybe it makes it easier if you put the entire controller

3 answers

4

Probably the file name inside the folder app\Http\Controllers this with different name in case of upper and lower case letters, for example, the class you wrote

SendMailNewsLetter

And in the file you accidentally wrote:

SendmailNewsLetter.php

Note that in the file the "M" in this tiny mail, in operating systems like Linux the file names, folders, etc, are case-sensitive, so have to use properly, in Windows is not case sensitive.

The other possibilities are:

  • You confused and spelled the wrong name anyway
  • Put the file in a wrong folder
  • You put the route in one group on namespaced routes, which is based on the folder path and must not have placed in the folder as such.

0

I managed to do it this way:


Route::get('envio-email', function () {

    $user = new stdClass();
    $user->name = 'Ricado Santana';
    $user->email = '[email protected]';

    /*Visão do navegador*/
    return  new \App\Mail\SendMail($user);
 //   \Illuminate\Support\Facades\Mail::send( new \App\Mail\SendMail($user));
});

When executing the command: php artisan route:list, is listed the route

C: xampp htdocs erpsistemas Teencoachlaravel>php Artisan rout:list

+--------+----------+-------------+--------------+---------+------------+
| Domain | Method   | URI         | Name         | Action  | Middleware |
+--------+----------+-------------+--------------+---------+------------+
|        | POST     | envio-email |              | Closure | web        |
+--------+----------+-------------+--------------+---------+------------+

But, I would like to add a control to capture user email with Request.

0

I managed to solve the problem. In the route file, I changed

Of:

Route::post('envio-email','SendMailNewsLetter@mailNewsLetter');

To:

Route::post('envio-email', 'App\Http\Controllers\SendMailNewsLetter@mailNewsLetter');

Browser other questions tagged

You are not signed in. Login or sign up in order to post.