Laravel 5.6: DOMPDF Doesn't Save PDF Files - laravel

I am using the DOMPDF Wrapper for Laravel 5 to create a PDF from a view.
<?php
$customer = Customer::findOrFail(Auth::user()->id);
return PDF::loadView('backend.profile.includes.pdf.pdf',
compact('customer'))->save(public_path('pdf/resume/test.pdf'));
When I access the related page, the file isn't saved in the public folder. Nothing happens.

You should use Laravel's filesystem to save the data from DOMPDF to a file. I'm not sure how your code looks that actually renders the PDF, but here is a general idea.
First, make sure to link the "public/storage" directory to "storage/app/public". Laravel can do this for you with the following command.
php artisan storage:link
Then you could do something like this to render the document with DOMPDF and save the file.
use Dompdf\Dompdf;
use Illuminate\Support\Facades\Storage;
$dompdf = new Dompdf();
$dompdf->loadHtml($view);
$dompdf->setPaper('letter', 'portrait');
$dompdf->render();
$file = $dompdf->output();
Storage::put('public/test.pdf', $file);
See this article for more details.

Related

Laravel: Uploaded image not showing

i keep getting 404 image not found when viewing the uploaded image on my project but the image is there. im using laravel's asset() helper to retrieve the image. the url in chrome shows http://127.0.0.1:8000/images/dU8oaVTAwQyTor86jvDtdGKvE7H3MYkHZuUG60gH.png and ive already done php artisan storage:link. any help is greatly appreciated.
You shouldn't use the asset helper for this, the url generated is wrong.
As you use the public storage, the url is supposed to be like this :
http://127.0.0.1:8000/storage/images/dU8oaVTAwQyTor86jvDtdGKvE7H3MYkHZuUG60gH.png
but aren't you supposed to access the image through the public folder if you do php artisan storage:link

How can i download file in Codeingiter

I want to give download file option my webpage , but the file which i want to download is present on download link of another website , how can i directly download it from my webpage ,using CODEIGNITER
If you want download a file direct to your web site root folder use this code.
file_put_contents($_SERVER["DOCUMENT_ROOT"]."/your_folder_name/add_file_name.jpg..ect", "your_file_path_want_to_download");
hope it will help you.
You can download files using download helper in codeigniter. first you need to and $this->load->helper('download'); in your constructor or method. after that use following code for download.
force_download('/path/to/photo.jpg', NULL);
You can Use download helper in Codeigniter. simple load helper in your controller where you need like this
$this->load->helper('download');
here is ex
$data = 'Here is some text!';
$name = 'mytext.txt';
force_download($name, $data);

how and where can store images with laravel?

how and where I can store images using laravel?
context:
I want display some images in my main view (these are predefined by me).
I also want to store images uploaded by users, however, do not know where to store these images.
I'd like to call these from the view...
Thank you very much for the help. :)
Basically you can save your files wherever you want within your Laravel application provided that you have permissions to create directory and file.
But I prefer saving files in the storage/app folder. Laravel provides a simple API to manipulate files on disk. See the docs.
Update:
This answer was posted when Laravel was in version 5.2.
From version 5.3 on, you can easily create symbolic links by running the artisan command php artisan storage:link. See the docs.
Make directory for images in myapp/public/images and keep images on there.
<img src="{{URL('/images/logo.jpg')}}">
If you want to display them on your site store them in your public directory. Since they are uploaded by users you will need to pass them through a form. Here is an example of a controller.
$file = Input::file('picture');
$file->move(public_path().'/images/',$user->id.'.jpg');
The user will submit a form with a picture field. The two lines above will store it in the public directory in an images folder, with the relevant user's id as its name. Your probably best off making a model in your database for images and their paths. If you do, add these lines after the two above.
$image = new Image;
$image->path='/images/'.$user->id.'.jpg';
$image->user_id = $user->id;
$image->save();
To display it in the view simply set an $image variable to the correct image model in your controller and pass it to the view. Then pop its path in the src of the image.
<img src={{$image->path}} alt={{$image->path}}>

export to pdf using codeigniter & bootstrap

i have a web project. In my project, i would like to give button to export file to pdf. i'm using bootstrap & codeigniter.
can anyone give example for export file to pdf in codeigniter ?
Found this while trying to do the same. https://davidsimpson.me/2013/05/19/using-mpdf-with-codeigniter/
In place of redirect() function used on the page, you can use the code below to force download. Note that redirect() will only open the file in some browsers like chrome.
$this->load->helper('download');
$data = file_get_contents(base_url("downloads/reports/$filename.pdf")); // Read the file's contents
$name = 'mynewfile.pdf';
force_download($name, $data);
Don't forget to add the .pdf extension to $name
I am using TCPDF to generate pdf files in codeigniter. check this out.TCPDF examples

Magento set content in action

I'm quite new to Magento
And I'm creating the payment module which redirects to PaymentController
I have redirectAction
And I need to solve a simple task:
I need to show the content from a .phtml file in
$this->loadLayout();
$cmsBlock = $this->getLayout()->createBlock('cms/block')->setBlockId('cms_block_fail');
$this->getLayout()->getBlock('content')->append($cmsBlock);
$this->renderLayout();
return $this;
And nothing is showing up
All I need is just to show some html in the main site layout
Use registry to pass data to template.
Create registry on controller and and display into phtml file.
check below link how to create registry:-
http://blog.chapagain.com.np/magento-how-to-set-and-get-registry/

Resources