Embed an Image in a Mailview doesnt work anymore - laravel

After upgrade to 5.4 we have a problem with the Notifiy mailables, we embed the Application logo via
{{ $message->embed($path) }}
and it doesnt work anymore, i have a 5.3 copy where it works.. it looks like the $message variable is not injected automaticly anymore. we tried without the embedded image and the mailview is working.
Is there anything missing during our upgrade? i checked the upgradeguide twice.. we not using markdown.
Error:
Undefined variable: message (View: W:\project\resources\views\vendor\notifications\email.blade.php)
Codeexample:
User::find(1)->notify(
new EmailCredentialsTest(User::find(1))
);

Related

PHP / Laravel 8.0 : UI of link method on Paginator instance is broken after upgrading from version 7.25

I switched my laravel app from 7.25 to 8.0. Now I am facing pagination problem.
{{ $download->links() }}
in controller
$download = Download::paginate(2);
Yes, it is working well but the UI is broken now.
image error ui
In Laravel 8 more options were added how pagination can be displayed.
This instruction https://laravel.com/docs/8.x/pagination#using-bootstrap should help.
Go to App\Providers\AppServiceProvider
add
public function boot() { Paginator::useBootstrap(); }
and import
use Illuminate\Pagination\Paginator;
Seems like they have made changes to the UI (bootstrap) in the latest, version.
I would suggest you to create a custom UI for that links by yourself. Use the following commands to publish the pagination views to resource directory and make some changes accordingly.
php artisan vendor:publish --tag=laravel-pagination
and points to your custom view with the following line of code:
{{ $paginator->links('view.name') }}
which is in your case {{$download->links('view.name')}}

unable to generate PDF from spatie bowsershot

i have installed browsershot in my laravel project
I have installed puppeteer, installed chromium , my npm version is updated, but still i am unable to get the PDF of my simple html input , i have tried to take screenshot by URL method and save as image(It works), but my requirement is to generate PDF of my html.
This is my code in controller
$output=Browsershot::html($html)
->setNodeModulePath("/var/www/html/ProjectName/node_modules/")
->setChromePath("/usr/bin/chromium-browser")
->setNodeBinary('/usr/local/bin/node')
->setNpmBinary('/usr/local/bin/npm')
->showBackground()
->noSandbox()->timeout(60)
->save(public_path("DevTest.pdf");
Error Message:
"message": "The process "PATH=$PATH:/usr/local/bin NODE_PATH='/var/www/html/ProjectName/node_modules/' /usr/local/bin/node '/var/www/html/benesprint/vendor/spatie/browsershot/src/../bin/browser.js' '{"url":"file:\/\/\/tmp\/1933874416-0068512001600765779\/index.html","action":"pdf","options":{"path":"\/var\/www\/html\/ProjectName\/public\/DevTest.pdf","args":["--no-sandbox"],"viewport":{"width":800,"height":600},"displayHeaderFooter":false,"executablePath":"\/usr\/bin\/chromium-browser","timeout":60000,"printBackground":true}}'" exceeded the timeout of 60 seconds.",
**i would be grateful if you can help me out.**
i have similiar problem when browsershot inside container. and my step to resolve is like this:
Manual generate PDF from html using laravel tinker. if there is an error, try reinstall chromium and puppeteer library.
If success, then try remove all css and javascript links from html, and check for the result.
If success, then add --proxy-server="direct://" and --proxy-bypass-list=* into browsershot args
If step 3 is not working, then you can put css and javascript directly into view template or using php code to inclue those files like
<?php include public_path('css/styles.css') ?>

Call to undefined function _()

I am having trouble with this error,
ErrorException (E_ERROR)
Call to undefined function _() (View: C:\Codes\web-is\resources\views\layouts\client.blade.php)
and it is pointing in this code
<title><?php echo e(_('This is title')); ?></title>
I think it is in the _() of Laravel helper, but it should be working right.
I really do not know what is going on, there is a live server that working fine with the code. I just tried to clone the repo to my laptop and install necessary requirements such as PHP, IIS is my web server. I also sure that PHP extensions are installed, I can see it in phpinfo().
Any help will be appreciated. Thank you.
The default Laravel helper function to get translation string is __(), not _(). Note the two, double underscores __.
See this link; https://github.com/laravel/framework/blob/8.x/src/Illuminate/Foundation/helpers.php#L820

How to get full URL of image after Amazon S3 upload?

I need to get full URL of an image which is uploaded to amazon s3. I tried following functions. I am using Laravel 5.1.
Storage::disk("s3")->url($filename);
Storage::url($filename);
Storage::temporaryUrl('file1.jpg', Carbon::now()->addMinutes(5));
$filesystem->getAdapter()->getClient()->getObjectUrl($bucket, $key);
all are showing undefined function url(or) temporaryUrl (or) getObjectUrl.
The url() and temporaryUrl() methods aren't available in Laravel 5.1 (FileSystemAdapter - API Reference 5.1). They became available as of version 5.4 (FileSystemAdapter - API Reference 5.4).

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.

Resources