73 lines
1.9 KiB
PHP
Raw Normal View History

2018-04-26 16:04:27 +03:00
<?php
namespace App\Http\ViewComposers;
use App\Models\Common\Media;
use File;
use Image;
use Storage;
2021-01-29 11:04:15 +03:00
use Illuminate\View\View;
use Illuminate\Support\Facades\Log;
use Intervention\Image\Exception\NotReadableException;
2018-04-26 16:04:27 +03:00
class Logo
{
/**
* Bind data to the view.
*
* @param View $view
* @return void
*/
public function compose(View $view)
{
$logo = '';
2019-11-30 00:39:44 +03:00
$media = Media::find(setting('company.logo'));
2018-04-26 16:04:27 +03:00
if (!empty($media)) {
2021-05-30 19:28:31 +03:00
$path = $media->getDiskPath();
2018-04-26 16:04:27 +03:00
2021-05-30 19:28:31 +03:00
if (Storage::missing($path)) {
2018-04-26 16:04:27 +03:00
return $logo;
}
} else {
2020-02-28 16:16:07 +03:00
$path = base_path('public/img/company.png');
2018-04-26 16:04:27 +03:00
}
2021-01-29 11:04:15 +03:00
try {
$image = Image::cache(function($image) use ($media, $path) {
2021-01-29 11:04:15 +03:00
$width = setting('invoice.logo_size_width');
$height = setting('invoice.logo_size_height');
2019-11-30 00:39:44 +03:00
if ($media) {
2021-05-26 17:22:17 +03:00
$image->make(Storage::get($path))->resize($width, $height)->encode();
} else {
$image->make($path)->resize($width, $height)->encode();
}
2021-01-29 11:04:15 +03:00
});
} catch (NotReadableException | \Exception $e) {
2021-04-16 00:59:43 +03:00
Log::info('Company ID: ' . company_id() . ' viewcomposer/logo.php exception.');
2021-01-29 11:04:15 +03:00
Log::info($e->getMessage());
$path = base_path('public/img/company.png');
$image = Image::cache(function($image) use ($path) {
$width = setting('invoice.logo_size_width');
$height = setting('invoice.logo_size_height');
$image->make($path)->resize($width, $height)->encode();
});
}
2018-04-26 16:04:27 +03:00
if (empty($image)) {
return $logo;
}
$extension = File::extension($path);
$logo = 'data:image/' . $extension . ';base64,' . base64_encode($image);
$view->with(['logo' => $logo]);
}
}