Reputation: 1910
I created a Mailable called Class UserRequest I'm trying to call it from inside a controller buy this is the error I get:
Class 'App\Http\Controllers\UserRequest' not found
I also tried ->send(new \UserRequest($msgdata));
but it still doesn't work.
Controller:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Mail;
class ContactController extends Controller
{
public function index()
{
return view('contact');
}
public function sendemail(Request $request)
{
$msgdata = array('subject'=>$request->subject,'email'=>$request->email, 'name'=>$request->name,'body'=>$request->body);
try
{
Mail::to('[email protected]')
->send(new UserRequest($msgdata));
}
catch(Exception $e)
{
}
}
}
Upvotes: 0
Views: 7018
Reputation: 172
You will need to add the right path to the top as stated by other.
Also check the namespace in the UserRequest class
Upvotes: 0
Reputation: 4094
Include your class at the top like this
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Mail;
use App\Mail\UserRequest; // including your class
class ContactController extends Controller
{
public function index()
{
return view('contact');
}
public function sendemail(Request $request){
$msgdata = array('subject'=>$request->subject,'email'=>$request->email,
'name'=>$request->name,'body'=>$request->body);
try {
Mail::to('[email protected]')->send(new UserRequest($msgdata));
}catch(Exception $e){
// Log your exception
}
}
}
Upvotes: 6