Level 51
May 31, 2016
2
Level 1
Call to a member function embed() on null
Hi. Trying to embed an image to the email, but getting the above error.
Here is my controller
public function update($id)
{
$data = Input::all();
$user = User::find($id);
$file = array('img' => Input::file('img'));
$rules = array(
'img' => 'required',
'performer_name',
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
else {
if (Input::file('img')->isValid()) {
$destinationPath = 'img/uploads/artist';
$extension = Input::file('img')->getClientOriginalExtension();
$fileName = rand(11111,99999).'.'.$extension;
Input::file('img')->move($destinationPath, $fileName);
$user->img = '/'.$destinationPath.'/'.$fileName;
$pathToFile = public_path().$user->img;
Session::flash('success', 'Upload successfully');
Mail::send('emails.fb16', $data, function($message) use ($data, $pathToFile)
{
$message->from($data['leader_email'] , $data['leader_name']);
$message->to('xxx', 'xxx')->cc('xxx')->subject('xxx');
$message->attach($pathToFile);
});
}
else {
Session::flash('error', 'uploaded file is not valid');
}
}
$user->fill($data);
$user->save();
return Redirect::route('fb16id', array(Auth::user()->id));
}
Here is my view
<?php
$pathToFile = Input::get('pathToFile');
$performer_name = Input::get('performer_name');
$profile = Input::get ('profile');
$leader_name = Input::get ('leader_name');
$leader_email = Input::get ('leader_email');
$message = Input::get ('message');
$date_time = date("F j, Y, g:i a");
?>
<p>
<img src="<?php echo $message->embed($pathToFile); ?>">
<?php echo ($performer_name); ?><br>
<?php echo ($profile); ?><br>
<?php echo ($leader_name); ?><br>
<?php echo ($leader_email); ?><br>
<?php echo ($message); ?><br>
Date: <?php echo($date_time); ?><br>
</p>
Thanks for any help.
Please or to participate in this conversation.