I am trying to send an email from my Laravel project. Upon entering the store I get this error:
Call to a member function getRealPath () on string
The email is sent with an attachment, when it is sent without taking into account the attached file, it is sent well.
Here I put the driver:
<?php
namespace proyecto\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use Storage;
use Mail;
use Config;
use Illuminate\Validation\Rule;
class EmailController extends Controller {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function index() {
return view('administracion.email.email')
->with('method','POST');
}
public function store(Request $request) {
$data = array(
'destino' => $request['destino'],
'asunto' => $request['asunto'],
'contenido' => $request['contenido'],
'a_file' => $request['a_file']
);
Mail::send('administracion.email.email_body', $data, function($message) use ($data) {
$message->to($data['destino']);
$message->subject($data['asunto']);
$message->from(Config::get('mail.username'));
$message->attach($data['a_file']->getRealPath(), array(
'as' => 'a_file' . $data['a_file']->getClientOriginalExtension(),
'mime' => $data['a_file']->getMimeType())
);
});
return Redirect::to('email');
}
}