mrkarma4ya
1 month ago
219
7
Laravel

Class 'App\Http\Controllers\Contact' not found

Posted 1 month ago by mrkarma4ya

I'm trying to send email following the latest Laravel 6 videos, but I'm getting this:

Class 'App\Http\Controllers\Contact' not found

Here's my ContactController.php:

<?php

namespace App\Http\Controllers;

use App\Contact;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;

class ContactController extends Controller
{
      /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //

       
        request()->validate([
            'fullname' => 'required:max:50',
            'email' => 'required|email',
            'subject'=>'required|max:100',
            'message'=>'required|max:500'
        ]);
        
        Mail::to(request('email'))
            ->send(new Contact());
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Contact  $contact
     * @return \Illuminate\Http\Response
     */
    public function show(Contact $contact)
    {
        //
        return view('pages.contact');
    }

    
}

I already have a 'Contact.php' in Mail folder, generated through

php artisan make:mail Contact

that looks like this:

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class Contact extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('email.contact');
    }
}

The only different thing I did from the tutorial was make a Contact model too like this:

php artisan make:model -mcr

Because I want to store it in the database too.

How do I solve this error? It looks like its looking for a Contact.php in the 'App\Http\Controllers\ directory instead of the 'App\Mail' directory

Please sign in or create an account to participate in this conversation.