Laravel 5: Sending email with attached .pdf file generated from dynamic page - laravel

I have a job website. Job seeker users can register and build their profile (online resume), and it is used for one click application.
When job seekers logged in and click "Apply Now" button to any job, I want Laravel to send an email attached with .PDF resume (generated from their online resume building page) to employer's inbox.
Note: I do not want to send their uploaded resume (.pdf/.doc) to employer's inbox because I want to promote my website's branding / resume template.
Please tell me how to achieve this. If any source code provided, I would appreciated.
thank you.

You can use a html to pdf converter (something like http://github.com/barryvdh/laravel-dompdf). This will create the users profile in PDF format.
After the user clicked the button there will be an email sended to the employer with the attached pdf from the user.
It will look something like this:
Mail::send('emails.reminder', ['user' => $user], function ($m) use ($user) {
$m->to($user->email, $user->name)->subject('Your Reminder!');
$m->attach($pathToFile);
});
And with custom mail per email:
Mail::send('emails.reminder', ['user' => $user], function ($m) use ($user) {
$m->from('hello#app.com', 'Your Application');
$m->to($user->email, $user->name)->subject('Your Reminder!');
$m->attach($pathToFile);
});
This will create the PDF, save it to the storage directory. You can use the views for the design:
public function createCollageCron($load_id) {
$load = Loads::findOrFail($load_id);
$pdf = PDF::loadView('pdf.collage', compact('load'));
if ($pdf->save(storage_path('app/loadings/'.$load->id.'/collage.pdf'))) {
return true;
} else {
return false;
}
}
Hope this works!

Related

How can I download pdf before loading another view in laravel?

after completing a registration formular, when user clicks submit button, I want to first download a pdf and then redirect user to a view. Here is my code :
public function formularSave(Request $request) {
if(!isset($_REQUEST['token'])) {
abort(404);
}
$token = $_REQUEST['token'];
$upd_app = Application::where('token', $token)->update([
'status' => 22
]);
$result = "Registration complete.";
$html .= 'Some test code here
<br>
<p>Date: '.date('d.m.Y H:i:s').'</p>
';
$pdf = PDF::loadHTML($html);
$filename = substr(md5(uniqid().time()), 0, 17) . '.pdf';
$pdf->save(storage_path().'/app/public/uploads/rezolutii/'.$filename);
//code for download pdf HERE!!!!
return view('site.pages.registercomplete', compact('result'));
}
How can I download the pdf, after I create it?
It's impossible on Laravel.
This will not work. Your browser operates on simple requests one goes out one comes in.
There is no way for browser to know if user finished downloading the file and saved it somewhere. The final response from browser if file to be downloaded, nothing can follow that as far as I understand.
Now I'm not sure how that can be handled in javascript but in pure html requests it will not work.
Check this https://laracasts.com/discuss/channels/laravel/redirect-after-download

How to display PDF Documents on the browser using a View in Laravel 5.8

I'm working on a web application using Laravel 5.8, I'm new to Laravel framework. I would like to display PDF documents on the browser when users click on some buttons. I will allow authenticated users to "View" and "Download" the PDF documents.
I have created a Controller and a Route to allow displaying of the documents. I'm however stuck because I have a lot of documents and I don't know how to use a Laravel VIEW to display and download each document individually.
/* PDFController*/
public function view($id)
{
$file = storage_path('app/pdfs/') . $id . '.pdf';
if (file_exists($file)) {
$headers = [
'Content-Type' => 'application/pdf'
];
return response()->download($file, 'Test File', $headers, 'inline');
} else {
abort(404, 'File not found!');
}
}
}
/The Route/
Route::get('/preview-pdf/{id}', 'PDFController#view');
Mateus' answer does a good job describing how to setup your controller function to return the PDF file. I would do something like this in your /routes/web.php file:
Route::get('/show-pdf/{id}', function($id) {
$file = YourFileModel::find($id);
return response()->file(storage_path($file->path));
})->name('show-pdf');
The other part of your question is how to embed the PDF in your *.blade.php view template. For this, I recommend using PDFObject. This is a dead simple PDF viewer JavaScript package that makes embedding PDFs easy.
If you are using npm, you can run npm install pdfobject -S to install this package. Otherwise, you can serve it from a CDN, or host the script yourself. After including the script, you set it up like this:
HTML:
<div id="pdf-viewer"></div>
JS:
<script>
PDFObject.embed("{{ route('show-pdf', ['id' => 1]) }}", "#pdf-viewer");
</script>
And that's it — super simple! And, in my opinion, it provides a nicer UX for your users than navigating to a page that shows the PDF all by itself. I hope you find this helpful!
UPDATE:
After reading your comments on the other answer, I thought you might find this example particularly useful for what you are trying to do.
According to laravel docs:
The file method may be used to display a file, such as an image or PDF, directly in the user's browser instead of initiating a download.
All you need to do is pass the file path to the method:
return response()->file($pathToFile);
If you need custom headers:
return response()->file($pathToFile, $headers);
Route::get('/show-pdf/{id}', function($id) {
$file = YourFileModel::find($id);
return response()->file(storage_path($file->path));
})->name('show-pdf');
Or if file is in public folder
Route::get('/show-pdf', function($id='') {
return response()->file(public_path().'pathtofile.pdf');
})->name('show-pdf');
then show in page using
<embed src="{{ route('show-pdf') }}" type="text/pdf" >

send a mail to particular user while clicking on the button from view page in codeigniter

i have one view page called vendor view candidates page..in that page i display all the candidates details from database and i have user_id in that view page..and i gave button called release information..so when user click on the button the page will redirect to edit_candidates page with that particular candidate_id..and they will allow to insert email and phone number..
After they insert email and mobile number and then submit..i want to send mail to particular user_id..
This is my button:(edit candidates page)
<td>Release Contact Info</td>
Controller:
public function edit_candidates($id)
{
$data['editdata']=$this->CandidateModel->candidate($id);
if($this->input->post())
{
$this->CandidateModel->update_candidate($this->input->post(),$id);
redirect(base_url('index.php/Candidate/vendor_view_candidates'));
}
$this->load->view('Candidates/edit_candidate',$data);
}
Can anyone help me...i tried a lot..but i didn't get any idea on how to do this..
Thanks in advance..
Use the following code to fix your issue
public function edit_candidates($id)
{
$data['editdata']=$this->CandidateModel->candidate($id);
if($this->input->post('update_form'))
{
$userEmail = $this->CandidateModel->get_userinfo($data['editdata']->user_id);
//Pass this $userEmail into mail function it will send email
$this->CandidateModel->update_candidate($this->input->post(),$id);
redirect('index.php/Candidate/vendor_view_candidates','refresh');
}
else
{
$this->load->view('Candidates/edit_candidate',$data);
}
}
Let me know if it not fix your issue

codeigniter with MVC pattern

I am working on ci and when i am going to delete my data then i want to generate a confirm message box on click delete link and my code is this.
view.php
id);?>">Delete
controller.php
function delete($id)
{
$this->include_user->delete($id);
redirect(site_url('admin_controller/fetch'));
}
Model.php
function delete($id)
{
$this->db->delete("user",array('id' => $id));
}
If you want to show confirmation message that either user really want to delete, then you can use jquery confirm box plugin and when click on delete anchor then on delete show the confirm box.
e.g: in js code
jConfirm('Do you really want to delete?', 'Delete Confirmation', function(r) {
if (r == true) {
}
}
In my case I am using jquery confirm box.
And in case if you want to show success message then you can send back a flag when record is deleted to controller, then checking the flag, if successfully record is deleted then pas success message to your message controller or wise failure message.

How to determine the authorization in Joomla

After login i use need to set up redirect to custom page. How to catch this authorization in onAfterRoute event?
You should go to this path:
JOOMLAROOT/components/com_user/controller.php
in function register_save(), find this code:
if ( $useractivation == 1 ) {
$message = JText::_( 'REG_COMPLETE_ACTIVATE' );
} else {
$message = JText::_( 'REG_COMPLETE' );
}
after line put this code:
$this->setRedirect('/Your Custom Page Address', $message);
Why not just use the built in redirect in either the Joomla user login menu item or the standard Joomla login module. Both offer the option to redirect a user after a successful login. In the case of the module, you would need to create a menu item pointing to the custom page, but that's easy enough to do.
Is there something you need to do other than just a simple redirect? If not, then just use the system as it is designed.
I would create a small plugin that handles the redirect after login.
After a user has been logged in, the event onUserLogin is triggered, and you could simply do a redirect when the event is called.
Avoid any core hacks, since you'll allways end up having a hazzle during updates.
The code for a plugin like this could look like this:
class plgAuthenticationMyredirect extends JPlugin{
function onUserLogin ($user, $options){
$link = 'index.php?option=.....';
$msg = 'Message to show after login';
$app = JFactory::getApplication();
$app->redirect($link, $msg);
}
}

Resources