Saturday, April 15, 2017

Laravel: Why is my path variable undefined?

I am trying to attach a file sent with my form request in an email however I keep getting ....

Undefined variable: filepath

... error executing the script.

Here is my code:

public function postEmail(Request $request) { // validate uploaded file $validator = Validator::make($request->all(), [ 'menu' => 'required|mimetypes:image/jpeg,image/png,application/pdf' ]);

if ($validator->fails()) {
    return redirect('signup/services')
            ->withErrors($validator)
            ->withInput();
}

$filepath = $request->menu->path();

// email file
\Mail::send('emails.service_uploaded', ['title' => 'File Uploaded', 'message' => 'Example MSG'], function ($message)
 {
    $message->from('no-reply@mysite.com', 'My Site');
    $message->to('me@mail.com');
    $message->subject('New Upload');
    $message->attach($filepath);
});

// send to next page

}



via Imran

Advertisement