Laravel not processing view as html - laravel

I have a Laravel application and I want to send email. It works in my application and I can receive emails however the emails I receive look like this:
#component('mail::message') # Final step... Confirm your email address to complete your Twitter account {{ $user->username }}. It's easy — just click the button below. #component('mail::button', ['url' => $company->activation_code]) Confirm now #endcomponent Thanks, {{ config('app.name') }} #endcomponent
Somehow Laravel isnt even converting the components nor the variables. It is sending the view like a string.
The code to send an email is this:
Mail::to($company->email)->send(new CompanyActivation($company));
and the code in CompanyActivation is:
return $this->subject('Account activatie')->markdown('emails.companyactivation');
How can I tell Laravel to process the view and send it as html

I found the solution. I started the file by manually creating the email blade file. I then started a new email template using the php artisan command. I pasted the content in the newly created file and everything works now.

Make sure that all indents and spaces are correct.
When using markdown spaces or wrong indents will invoke a code block.
Try:
#component('mail::message')
# Final step...
Confirm your email address to complete your Twitter account {{ $user->username }}. It is easy — just click the button below.
#component('mail::button', ['url' => $company->activation_code])
Confirm now
#endcomponent
Thanks, {{ config('app.name') }}
#endcomponent
Instead of:
#component('mail::message') # Final step... Confirm your email address to complete your Twitter account {{ $user->username }}. It's easy — just click the button below. #component('mail::button', ['url' => $company->activation_code]) Confirm now #endcomponent Thanks, {{ config('app.name') }} #endcomponent

Related

Get admin name in blade using bitfumes MultiAuth Laravel package

{{Auth::admin()->name}} this gives error, how will i retrieve the current admin name from the database using blade.
I'm getting this error, Method Illuminate\Auth\SessionGuard::admin does not exist.
This works. {{ auth('admin')->user()->name }}

How to customize a URL to reset password in an email template?

I am using Django Rest Auth with Django All Auth.
When I hit an endpoint /rest-auth/password/reset/ (POST) I receive an email includes a URL to reset a password.
But the URL doesn't work, because a domain is always example.com and uid token don't work well like below...
http://example.com/password/reset/confirm/(%3FPMzQ%5B0-9A-Za-z_%5C-%5D+)/(%3FP5ku-afb8832e99157c02f452%5B0-9A-Za-z%5D%7B1,13%7D-%5B0-9A-Za-z%5D%7B1,20%7D)/$
I've overridden a PasswordResetSerializer to use my email template referring to this article
How can I solve this situation?
Here are the codes:
serializers.py
from rest_auth.serializers import PasswordResetSerializer
class CustomPasswordResetSerializer(PasswordResetSerializer):
def get_email_options(self):
print("check override")
return {
'email_template_name': 'password_reset_key_message.txt',
}
password_reset_key_message.txt
A password reset has been requested.
Click the link below to continue.
{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}
If I change a part of {{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %} to {{ password_reset_url }} the email doesn't include any URL
When I add 'domain_override' in def get_email_options(self) like berow,
from rest_auth.serializers import PasswordResetSerializer
class CustomPasswordResetSerializer(PasswordResetSerializer):
def get_email_options(self):
print("check override")
return {
'domain_override': 'localhost:8000',
'email_template_name': 'password_reset_key_message.txt',
}
The URL became like below,
http://localhost:8000/password/reset/confirm/(%3FPMzQ%5B0-9A-Za-z_%5C-%5D+)/(%3FP5ku-afb8832e99157c02f452%5B0-9A-Za-z%5D%7B1,13%7D-%5B0-9A-Za-z%5D%7B1,20%7D)/$
In this case, I can specify a domain, but uid and token still don't work...
python: 3.7.5
Django:2.2.2
django-allauth:0.41.0
django-rest-auth:0.9.5
djangorestframework:3.12.1
If you meant to change the example.com to another domain you will need to change the domain on the database. To do that create a superuser by python manage.py createsuperuser and then go to the /admin page. Then click on the change button on the Sites option. And then you will see 'example.com' just click on it and change it to your expected domain. And yes, you don't need the so critical way you specified.
UPDATE
The actual answer that worked for the questioner is to do the things mentioned above and also replace path('accounts_api/password/reset/confirm/(..... to re_path(r'^accounts_api/password/reset/confirm/(.....
in urls.py

Laravel display a custom message in Maintenance Mode

I'm checking out Laravel docs for Maintenance Mode:
https://laravel.com/docs/5.3/configuration#maintenance-mode
When you execute the command php artisan down, it will put the application under maintenance mode, and return the 503.blade.php view.
Works good, but there is an option I can't really make work.. when I do:
php artisan down --message='Upgrading Database' --retry=60
I want to display the message in the view, I tried accessing the obvious choice with {{ $message }} without success, returns undefined variable.
My question is: how to access it?
Actually you don't need that "json_decode" stuff, as all the "error" views (including 503.blade.php) have $exception variable.
So you may just use {{ $exception->getMessage() }} in your view and you will get the exact value that you have passed to artisan down --message command.
By default 503.blade.php view doesn't use this message.
This message is available in a JSON formatted file named storage/framework/down generated by php artisan down command.
You could do something like this to access the directly the message in your view:
{{ json_decode(file_get_contents(storage_path('framework/down')), true)['message'] }}
A cleaner way is to use the $exception variable and include in your view {{ $exception->getMessage() }} like suggested in this answer.
Under the hood, the CheckForMaintanceMode middleware reads the message and other data from the file and thrown a MaintanceModeException with this data.
Edit: After Laravel 8, the payload that creates the storage/framework/down command has changed and doesn't include the exception message. You should use the {{ $exception->getMessage() }} instead on Laravel 8+.
If you want detailed information (not just message) on your maintenance page, you can also use $exception->retryAfter(Int), $e->willBeAvailableAt(Carbon) and $e->wentDownAt(Carbon).
Of course you need to set --retry parameter in artisan command.

Unable to get complete URL in Password Reset in Laravel

I am using the Laravel 5 ResetsPasswords trait to implement password reset. In the file resources/views/emails/password.blade.php., I have the following code.
Click To Reset Password
I am using a queue to send the email to the user. When the user clicks the link received in email, I get something like below:
http://localhost/password/reset/2aafe5381baa67f9d1fe2f476c0f1395b21e71fafe181b2980fb838fc9e0b2fc
I was rather expecting:
http://localhost/oap/public/password/reset/2aafe5381baa67f9d1fe2f476c0f1395b21e71fafe181b2980fb838fc9e0b2fc
Why is oap/public/ not in the url? I have used the url() function in other views and they have worked just well except for this email view where I am using queue to send the message. When a queue is not used to send the message, the link is okay. Any idea how I can resolve this issue.
Use URL::to. Like,
Click To Reset Password
for the url helpers it will generate the full path for your inputs
{{ url('/password/reset/'.$token) }}
will generate
http://localhost/password/reset/2aafe5381baa67f9d1fe2f476c0f1395b21e71fafe181b2980fb838fc9e0b2fc
and
{{ url('/oap/public/password/reset/'.$token) }}
will generate
http://localhost/oap/public/password/reset/2aafe5381baa67f9d1fe2f476c0f1395b21e71fafe181b2980fb838fc9e0b2fc
you can also get around this
Route::get('oap/public/password/reset/{confirmcode}', ['as' => 'resetpassword', 'HomeController#resetmethod']);
then using this like that
{{route('resetpassword', ['confirmcode' => $token])}}

Laravel 4.2 Email::queue with assets

Simple, I am trying to queue an email using services beanstalkd and supervisord like so:
Mail::queue('emails.congratulations', $user, function($message) use($user) {
$message->to($user['email'], $user['name'])
->subject('Congratulations!');
});
My supervisor program config:
[program:emailservice]
command=php /path/to/laravel/artisan queue:listen
stdout_logfile=/path/to/laravel/app/storage/logs/emailservice_supervisord.log
redirect_stderr=true
In my blade file I am trying to access an asset, an image:
<p>
<img src="{{ asset('assets/img/logo.png') }}" />
</p>
When the email is sent and received, the image is broken and the URL to the image looks like this:
<img src="http://:/assets/img/logo.png"/>
I cannot figure out why the domain is :
If anyone else as experienced this behavior it would be good to get this out in the open because I have scoured Google and StackOverflow for answers to this issue without any mention of the issue.
A question I ask myself... when queuing, is Laravel/Supervisor/Beanstalk smart enough to remember the domain for the job?
You have to set application url to your domain (http://localhost by default) in config/app.php.

Resources