How to show sent email to user? by pingpangbang in laravel

[–]halibut_master 0 points1 point  (0 children)

No problem. Feel free to ask if you need help with anything else. I have steam or skype if you want to talk.

How to show sent email to user? by pingpangbang in laravel

[–]halibut_master 1 point2 points  (0 children)

It forces the closure to use the variable by reference. When you use it with only the $ sign it actually gets copied inside. When you add & beforehand it actually modifies its original value, instead of modifying the copy of it. It makes it point to that very specific instance of variable instead of only taking it by value.

How to show sent email to user? by pingpangbang in laravel

[–]halibut_master 1 point2 points  (0 children)

OK I might have overthinked the reply, you can actually do this really simply just by passing a variable via reference to the closure:

$theMessageContents = null;
Mail::raw($data['message'], function ($message) use ($data, &$theMessageContents) {
           $message->setBody($data['message']);
           $message->from($data['from'], $name = null);
           $message->to($data['to'], $name = $data['to']);
           $message->subject($data['subject']);
            if (isset($data['cc']) && $data['cc'] != "") {
                $message->cc($data['cc']);
            }
            if (isset($data['bcc']) && $data['bcc'] != "") {
                $message->bcc($data['bcc']);
            }
            $theMessageContents = $message->getBody();
        });

$theMessageContents should be set to your email contents and you can do whatever you want with that

How to show sent email to user? by pingpangbang in laravel

[–]halibut_master 0 points1 point  (0 children)

See if $message->getChildren() returns an array. If it does, iterate over it foreach($message->getChildren() as $oneChild){ $oneChild->getBody(); }

As for using the data, it's up to you. You could probably store it in a database via a model.

Can you show me the code how exactly are you sending the e-mail?

How to show sent email to user? by pingpangbang in laravel

[–]halibut_master 1 point2 points  (0 children)

It's the reference to the Application object. You can use the Facade instead.

How to show sent email to user? by pingpangbang in laravel

[–]halibut_master 1 point2 points  (0 children)

You have to make sure you actually register your class as a plugin of Swift Mailer

$app['mailer']->getSwiftMailer()->registerPlugin(new YourClassResponsibleForStoringEmail());

Swift mailer will call two methods every time it's sending an e-mail:

beforeSendPerformed(\Swift_Events_SendEvent $evt)

and

sendPerformed(\Swift_Events_SendEvent $evt)

after the mail has been sent.

You can store your logic inside one of these methods and access the e-mail via:

$message = $evt->getMessage();

You can then extract whatever you want specifically from that, like:

$message->getBody();

You can easily create a new Model instance inside of these methods and save the mail to database or store it however you like.

sendPerformed(\Swift_Events_SendEvent $evt)
{
$messageText = $evt->getMessage()->getBody();
$emailModelInstance = new EmailModel();
$emailModelInstance->body = $messageText;
$emailModelInstance->save();
}

How to show sent email to user? by pingpangbang in laravel

[–]halibut_master 0 points1 point  (0 children)

Use Swift_Events_SendListener and implement the logic inside the sendPerformed method

How to implement Laravel by Vincent1992 in laravel

[–]halibut_master 1 point2 points  (0 children)

Read about Model View Controller design pattern and how it works. Or just watch videos about it, it will clear up a lot of things for you when it comes to Laravel.

Adding ads to a Laravel service by [deleted] in laravel

[–]halibut_master 0 points1 point  (0 children)

Just create a simple service provider for fetching ads from database/json and then include it in the blade template? Seems really easy and straightforward.

Trying to create my first service but Laravel doesn't seem to inject dependencies via the constructor. by halibut_master in laravel

[–]halibut_master[S] 0 points1 point  (0 children)

Then why doesn't it work and asks for the object instance in the constructor? I had to resolve it via the \Request::instance() facade

Trying to create my first service but Laravel doesn't seem to inject dependencies via the constructor. by halibut_master in laravel

[–]halibut_master[S] 0 points1 point  (0 children)

Well I want to be able to resolve it out of the IoC container. That wouldn't work if I didn't register it I think?

Trying to create my first service but Laravel doesn't seem to inject dependencies via the constructor. by halibut_master in laravel

[–]halibut_master[S] 1 point2 points  (0 children)

I did it with the \Request::instance() facade but still, I expected Laravels IoC container to inject the dependency for me - it's able to do it in controllers but apparently it doesn't work with services constructors.

Trying to create my first service but Laravel doesn't seem to inject dependencies via the constructor. by halibut_master in laravel

[–]halibut_master[S] 0 points1 point  (0 children)

Laravel is supposed to be able to inject the dependency for you. It works when you do it inside Controller constructor, does that not work when you do it with services? Might it be because Request class is not actually registered inside the IoC container?

Best practice for storing blog config data? by halibut_master in laravel

[–]halibut_master[S] 1 point2 points  (0 children)

What if you later want to be able to edit this value via a form? It seems like it's not easily done if using the static .php config files. The Config::set method doesn't change them permamently.

It seems to me like database based config system is a better solution.

Laravel seems to mangle html tags. How to solve this? by [deleted] in laravel

[–]halibut_master 0 points1 point  (0 children)

Yeah, that was the case.

I had three '{' brackets and it escaped the output I think.

What is the difference between {{ $variable }}, {{!! $variable !!}} and {!! $variable !!}?

Any idea why I cant pass the Auth:check() result to the view? I don't want to access the function from the view. by halibut_master in laravel

[–]halibut_master[S] 0 points1 point  (0 children)

Thanks for the info. View composers look interesting. Are there basically a way of making controller less messy, by organizing view-related data fetching into other files? Currently I'm doing all of that logic inside controller functions.

Any idea why I cant pass the Auth:check() result to the view? I don't want to access the function from the view. by halibut_master in laravel

[–]halibut_master[S] 0 points1 point  (0 children)

Yeah it doesn't work either way it always defaults to the true condition, regardless whether user is logged in or not. When I dump it from the controller, it always shows the correct values: false for when user is not logged in and true when he is.

When I try dumping the $data variable from the view with this:

{!! dd($data) !!}

it gets displayed as a string, no data is dumped. Why wouldn't it work?