Laravel 5.1 - barryvdh/laravel-dompdf PDF Generation Error - laravel-5

In my composer:
"barryvdh/laravel-dompdf": "0.6.*",
Here is My config/app Setup:
Providers Array: 'Barryvdh\DomPDF\ServiceProvider',
Aliases Array: 'PDF' => 'Barryvdh\DomPDF\Facade',
Here is My route Setup:
$pdf = App::make('dompdf.wrapper');
Route::get('/dompdf', function() {
$html='<p>Foo Bar</p>';
PDF::loadHTML($html)->setPaper('a4')
->setOrientation('landscape')
->setWarnings(false)
->save('myfile.pdf');
});
While I hit /dompdf url. I got this Error.
My another Question is if I want to use DOM PDF library in My Controller Method. What setup or Step I Need To Follow??

You can run the below command and try
composer require barryvdh/laravel-dompdf

Related

Laravel 9 Inertia pagination use correct base url with port

I'm using Laravel 9 with Inertia and VueJs. I'm trying to paginate my invoices, and the links display as expected when I load the page (http://localhost:3000). However, when I click on a button to go to the next page (or any other page from the pagination), all the links change to:http://localhost/. I don't know how to solve this.
InvoiceController
$invoices = Invoice::latest()
->with('customer:id,name')
->orderByDesc('invoice_date')
->paginate(10);
return Inertia::render('Invoices', ["invoices" => $invoices]);
.env
APP_URL=http://localhost:3000
DEV_URL=http://localhost:3000
webpack.mix.js
// ...
.browserSync("localhost");
config/app.php
'url' => env('APP_URL', 'http://localhost:3000'),
Update
A github issue is opened: https://github.com/inertiajs/inertia/issues/811

Class not found after ajax request - October cms

For my application in october cms I'd like to be able to send a mail with the click of a button. I call the php file with an ajax request, however when the button gets clicked I get the error 'class not found' for whichever class I use, doesn't matter which. I already added the file to .htaccess to be able to run it on the button click. I included all classes at the top of the file. Also when I turn it into an artisan command and run it with php artisan now:send:mail it works without any issues. I already tried to run composer dump autoload and composer dump autoload -o. Code is down below, Any idea what I can do to make this work, or in what other way it could be done?
Thanks in advance!
Part of theme.js:
$.ajax({
url : '/plugins/test/notifications/ondemand/OnDemand.php'
}).done(function(data) {
console.log(data);
});
OnDemand.php:
<?php
namespace Test\Notifications\OnDemand;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use Test\Poles\Components\Metrics;
use October\Rain\Argon\Argon;
class OnDemand
{
public function send()
{
$date = Argon::now(config('app.timezone'))->format('Y-m-d');
// get some data
$array = ['date' => $date, 'score' => $score, 'CO2' => $CO2, 'scorecar' => $scorecar, 'scorebike' => $scorebike];
$email = "test#test.nl";
Mail::sendTo($email, 'daily.mail', $array);
}
}
$mail = new OnDemand;
$mail->send();
I'm not sure whether you want to do this as part of a custom October plugin you've developed or simply inside a regular October template. However, the absolutely simplest way of having an ajax button to send an email would be as follows:
1) Create a new mail template in the October backend in Settings | Mail Templates
2) In the "CMS" section of October, create a new blank Page
3) For the "Markup" section of the new page, the button HTML:
<button data-request="onPressButton">Send</button>
4) For the "Code" section of the new page, the following PHP:
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;
use Test\Poles\Components\Metrics;
use October\Rain\Argon\Argon;
function onPressButton()
{
$date = Argon::now(config('app.timezone'))->format('Y-m-d');
// get some data
$array = ['date' => $date, 'score' => $score, 'CO2' => $CO2, 'scorecar' => $scorecar, 'scorebike' => $scorebike];
$email = "test#test.nl";
Mail::sendTo($email,'daily.mail', $array);
}
That's it. As long as you include JQuery and {% framework extras %} in your October page layout, the above will work.
The principal is the same if you're adding this within a custom plugin that you've developed, but the HTML and PHP would obviously go into their individual files within a component if you did it that way.

Laravel 5.2 quickstart guide gives Not Found Error

Edit: I think this problem is due to not setting up apache properly, these two links helped me.
Solution:
http://laravel.io/forum/06-11-2014-not-found-but-route-exists
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts
End Edit
I'm following the Laravel 5.2 quickstart guide. https://laravel.com/docs/5.2/quickstart
I'm running ubuntu 14.04.2
The website runs initially, but then when I click on the add Task button
I run into a 404 Not Found error.
As per the guide I run the following commands to setup the complete quickstart project.
git clone https://github.com/laravel/quickstart-basic quickstart
cd quickstart
composer install
php artisan migrate
Additionally I run the following commands because I'm on an ubuntu server:
sudo chown -R www-data.www-data quickstart
sudo chmod -R 755 quickstart
sudo chmod 777 quickstart/storage
The routes.php file looks like:
<?php
use App\Task;
use Illuminate\Http\Request;
Route::group(['middleware' => ['web']], function () {
//
Route::get('/', function () {
$tasks = Task::orderBy('created_at', 'asc')->get();
return view('tasks', [
'tasks' => $tasks
]);
});
Route::post('/task', function (Request $request) {
$validator = Validator::make($request->all(), [
'name' => 'required|max:255',
]);
if($validator->fails()) {
return redirect('/')
->withInput()
->withErrors($validator);
}
$task = new Task;
$task->name = $request->name;
$task->save();
return redirect('/');
});
//
Route::delete('/task/{task}', function (Task $task) {
$task->delete();
return redirect('/');
});
});
I tried changing some code in the resources/view/tasks.blade.php from:
<!-- New Task Form -->
<form action="/task" method="POST" class="form-horizontal">
To the location of the actual public folder of the laravel project :
<!-- New Task Form -->
<form action="/learninglaravel/laraquickstart/quickstart/public/task" method="POST" class="form-horizontal">
So my problem is only when I press the button I get a 404 Error
//***** Edit:
I have tried having editing the post route but that doesn't fix the problem.
Route::post('/learninglaravel/laraquickstart/quickstart/public/task', function (Request $request) {
$validator = Validator::make($request->all(), [
'name' => 'required|max:255',
]);
if($validator->fails()) {
return redirect('/')
->withInput()
->withErrors($validator);
}
$task = new Task;
$task->name = $request->name;
$task->save();
return redirect('/');
});
The error is:
Not Found
The requested URL /learninglaravel/laraquickstart/quickstart/public/task was not found on this server.
Instead of:
Not Found
The requested URL /task was not found on this server.
I did what you suggested James and you were right, it makes the URL change to
/learninglaravel/laraquickstart/quickstart/public/task
but I still get the error of page not found. The only difference is the error message changed from the bellow error to the above. (I also tried manually changing both the url in the route.php file and the tasks.blade.php to reflect the same url. So the above URL would be both in the routes.php and the tasks.blade.php
I'm running on an ubuntu AWS server maybe I made a mistake on that end? I think the quickstart tutorial was written for homestead as I ran into problems with the database.(I just had to manually create one. The guide never specified that. I think it might be pre-configured in homestead to automatically use a database)
Cheers
From the guide on Quickstart, you can generate your form action URLs using the url helper, which:
generates a fully qualified URL to the given path.
As such you can use it like so on your form:
<!-- New Task Form -->
<form action="{{ url('task') }}" method="POST" class="form-horizontal">
This will ensure you are always posting to the correct URL for your domain, without you having to specify this yourself manually.
Give it a go and see what I mean, but in your case it would generate a url for you to your task route along the lines of this (based off your comment); 52.60.22.45/learninglaravel/laraquickstart/quickstart/public/task
When you change your form action parameter to
/learninglaravel/laraquickstart/quickstart/public/task
You are going to make HTTP POST request to
{scheme}://{domain}//learninglaravel/laraquickstart/quickstart/public/task
So laravel is going to look for this route and obviously it won't find it.
Just enabled mod_rewrite engine and it will work perfectly.
I have spend more then 2 hrs to find the solution and the solution. So don't wast your time and just enable the mod_rewrite engine by following command and try again:
sudo a2enmod rewrite
And dont forget to restart the apache server
sudo /etc/init.d/apache2 restart
or
sudo service apache2 restart

Class Html not found error in laravel 5

I add these packages in my laravel composer.json:
"laravelcollective/html": "~5.0"
and i add these
'Collective\Html\HtmlServiceProvider',
in providers and these
'Form'=> 'Collective\Html\FormFacade','Html=>'Collective\Html\HtmlFacade',
in aliases..
But i cant make change like this in my HTML file {{ html::style('/css/AdminLTE.min.css') }} its show HTML Class Not Found.
i checked in tinker
>>> Form::text('foo')
=> "<input name=\"foo\" type=\"text\">"
but its working..any help??
Html and Form classes were deprecated from Laravel 5. You can access similar functionality using Laravel Collective.
You have a typo error. Try this:
{{ Html::style('/css/AdminLTE.min.css') }}
Check this link, or try this:
Add this in composer.json require section
"illuminate/html": "5.*"
and run composer update.
Open your config/app.php
add under 'providers' array add this
Illuminate\Html\HtmlServiceProvider::class,
add under 'aliases' array add this
'Form' => Illuminate\Html\FormFacade::class,
'Html' => Illuminate\Html\HtmlFacade::class,
and under your blade templates, use like this
{!! Html::image('uploads/zami.jpg') !!}

Laravel EXCEL and PDF export

I am new in Laravel and I am using Laravel 4.2
I like to export some data in PDF and excel.
Is there any way in Laravel?
Use FPDF to do what u need. You must create a pdf file from scratch and fill it in the way u want.
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage(); // add page to PDF
$pdf->SetFont('Arial','B',16); // Choose a font and size
$pdf->Cell(40,10,'Hello World!'); // write anything to any line you want
$pdf->Output("your_name.pdf"); // Export the file and send in to browser
?>
And for Excel a simple way is to add PHPExcel to laravel. Add this line to your composer.json:
"require": {
"phpexcel/phpexcel": "dev-master"
}
then run a composer update. So use it like this:
$ea = new PHPExcel();
$ea->getProperties()
->setCreator('somebody')
->setTitle('PHPExcel Demo')
->setLastModifiedBy('soembody')
->setDescription('A demo to show how to use PHPExcel to manipulate an Excel file')
->setSubject('PHP Excel manipulation')
->setKeywords('excel php office phpexcel')
->setCategory('programming')
;
$ews = $ea->getSheet(0);
$ews->setTitle('Data');
$ews->setCellValue('a1', 'ID'); // Sets cell 'a1' to value 'ID
$ews->setCellValue('b1', 'Season');
Use maatwebsite to Create and import Excel, CSV and PDF files
Add this lines to your composer.json:
"require": {
"maatwebsite/excel": "~2.1.0"
}
After updating composer, add the ServiceProvider to the providers array in config/app.php
Maatwebsite\Excel\ExcelServiceProvider::class,
You can use the facade for shorter code. Add this to your aliasses:
'Excel' => Maatwebsite\Excel\Facades\Excel::class,
To publish the config settings in Laravel 5 use:
php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider"
simple use of this package:
$users = User::select('id','name' ,'username')->get();
$Info = array();
array_push($Info, ['id','name' ,'username']);
foreach ($users as $user) {
array_push($Info, $user->toArray());
}
Excel::create('Users', function($excel) use ($Info) {
$excel->setTitle('Users');
$excel->setCreator('milad')->setCompany('Test');
$excel->setDescription('users file');
$excel->sheet('sheet1', function($sheet) use ($Info) {
$sheet->setRightToLeft(true);
$sheet->fromArray($Info, null, 'A1', false, false);
});
})->download('xls'); // or download('PDF')

Resources