php - Cant get Beautymail to work for Laravel 5.2 -
i'm trying use beautymail project send receipt after customer ordered something. problem i'm using beautymail in function not in route documentation states.
this how im using in function:
class ordercontroller extends controller { public function postorder(request $request) { // more stuff here, shortned question purposes // instance of authenticated user $user = auth::user(); // send email conformation user bought product or products. $beautymail = app()->make(snowfire\beautymail\beautymail::class); $beautymail->send('emails.welcome', [], function($message) { $message ->from('example@admin.com') ->to($user->email, $user->username) ->subject('your receipt'); }); // return redirect success message flash()->success('success', 'your order processed successfully. receipt has been emailed you'); return redirect()->route('cart'); } }
and error when "checkout":
is there have add? did composer.json file along adding providers array, , publishing assets folder in documentation.
$beautymail = app()->make(\snowfire\beautymail\beautymail::class);
note \
before snowfire\beautymail\beautymail::class
.
or, @ top of controller:
use snowfire\beautymail\beautymail;
and in method can have laravel automatically resolve through ioc container, like:
public function postorder(request $request, beautymail $beautymail) { $beautymail->send('emails.welcome', [], function($message) { // etc... }
extra info on namespaces in php:
when reference class outside of use
, need declare if class in global namespace or not. when had:
app()->make(snowfire\beautymail\beautymail::class);
without leading \
, php assume you're looking requested in current namespace, \app\http\controllers
.
by adding leading \
you're telling php path class relative global namespace.
here's more info: http://php.net/manual/en/language.namespaces.basics.php
Comments
Post a Comment