Class 'Inline\PDF\PDF' not found in laravel using wemersonjanuario/laravelpdf package - php

I am trying to use this package -> http://packalyst.com/packages/package/wemersonjanuario/laravelpdf
I have installed and configured as per the website and also I had used this package couple of times which worked following the same procedure.
But now its giving the error Class 'Inline\PDF\PDF' not found
Not sure whats the mistake.
Can someone please help me sort this issue.
Below is the sample code
Composer.json file
"h4cc/wkhtmltopdf-i386": "0.12.3",
"wemersonjanuario/laravelpdf": "1.0.*"
app.php file
'providers' => [
// other providers
Inline\LaravelPDF\PDFServiceProvider::class
],
'aliases' => [
// other aliases
'PDF' => Inline\LaravelPDF\PDFFacade::class,
],
In config/laravelpdf.php file
<?php
return [
'executable' => base_path().'/vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386'
];
PHP Pdf code
use Inline\LaravelPDF\PDFFacade as PDF;
class SummaryHelper
{
public function getReport($date)
{
// Some code
$data = [ ]; // some data in it
$pdf_obj = PDF::loadView('vendor/daily-report', $data);
}
}
Github issue link

I've installed the package and got the same error. The thing is it's just a fork from another package and the guy didn't updated readme.md for correct namespaces. What you need to do it to change Inline to Novanti in config/app.php. Both for service provider and facade.
Then add this to the class where you want to use PDF facade:
use PDF;
Or just use full namespace:
$pdf_obj = \PDF::loadView('vendor/daily-report', $data);

Sorry for this.
I have changed the namespace to Novanti instead of Inline.
Please switch to 1.1.* version and change alias and provider namespaces to Novanti.
I have also updated the README.md to better document this.
Let me know if this works.
Thank you for reporting.

Related

Twitter API asatymic/twitter with Laravel 8

I followed his readme and I have done composer dump-autoload a million times, but still I receive an error. Don't know what i am making wrong. I am trying to use v2 version of twitter api. Please help me anyone.
In config/app.php:
'providers' => [
...
Atymic\Twitter\ServiceProvider\LaravelServiceProvider::class,
],
'aliases' => [
...
'Twitter' => Atymic\Twitter\Facade\Twitter::class,
],
In my controller:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Twitter;
class HomeController extends Controller {
public function index() {
$tweets = Twitter::getUserTimeline([
'screen_name' => 'xxxxxxx',
'count' => 10,
'format' => 'json'
]);
dd($tweets);
return view('home');
}
public function about() {
return view('about');
}
}
But I am getting this error:
Error
Call to undefined method Atymic\Twitter\Service\Accessor::getUserTimeline()
Look like you have to import facade
Instead of this
use Twitter;
Import this
use Atymic\Twitter\Facade\Twitter;
If you are using alias then run following command
php artisan config:clear
composer dump-autoload
php artisan optimize
Please look to the twitter api version which you have defined in the .env. you may need to use 1.1 and you are using v2
I think getUserTimeLine is available for version 1.1, and I think as the readme says you can use userTweets for v2

Laravel package config does not merge

I am developing several packages and would like to have a single config file for all of them if they are to be published.
Inside my service provider I did this:
public function boot()
{
$this->publishes([
__DIR__ . '/config/custom.php' => config_path('custom.php'),
]);
}
public function register()
{
$this->mergeConfigFrom(
__DIR__ . '/config/custom.php', 'custom'
);
}
Config:
return [
'containers' => [
...
]
];
And surely enough, if I publish it, it creates the file with values inside. But if a file already exists, having different keys:
return [
'xxxyyy' => [
...
],
];
publishing doesn't do anything. I would expect it to look like:
return [
'xxxyyy' => [
...
],
'containers' => [
...
]
];
What am I doing wrong?
In case anyone else is baffled by this, I have tested several cases and here is my explanation (official docs).
$this->publishes part enables the package config to be published by vendor:publish command. Nothing to explain here.
$this->mergeConfigFrom part enables the package config to be merged with currently published copy. Merge in this case means merged from Laravel config() scope.
This means that going to artisan tinker and running config('key') (where key is name of your config file) will return nothing if there is no published file and you don't have mergeConfigFrom. If a file is published and has other key value pairs which are not present in your package config and you have mergeConfigFrom present, config('key') will return merged array of values from a published file together with values from your config.
If a file with a same config name exists in your root config folder, and your package internally uses the same config name but you don't have mergeConfigFrom, config('key') will return only contents of a file inside root config folder, and will ignore everything from your package as you didn't provide a way for Laravel to see this as a "global" configuration. Your package will keep internally using the package config, but from app scope you will not be able to fetch it.

"Class 'Nexmo\\Laravel\\Facades\\Nexmo' not found" Error

I am trying to send an sms once a user signs up but it keep getting:
"Class 'Nexmo\\Laravel\\Facades\\Nexmo' not found"
I have this at the top of my controller file:
use Nexmo\Laravel\Facades\Nexmo;
I also have this in my config/app.php file
'Nexmo' => Nexmo\Laravel\Facades\Nexmo::class,
Im still getting an error, does anyone or has the same problem. I know its a class type error but why if I have added the right class and im using it appropriately.
Also, here is my code implementation:
Nexmo::message()->send([
'to' => '1122334455', //not actually using this number
'from' => 'Test',
'text' => 'Hey, test this digit code',
'text' => $request->user()->activation_token
]);
Update 1:
I have done php artisan vendor:publish and published the nexmo config file but it sill gives the error above.
Add Nexmo\Laravel\NexmoServiceProvider to the providers array in your config/app.php:
'providers' => [
// Other service providers...
Nexmo\Laravel\NexmoServiceProvider::class,
],
Thanks guys for answers/suggestions
Some reason it is working now? I did all the suggestions/answers and it did not work, did some other stuff (not working on this) and it suddenly works?
Thanks guys :)
If I found out what I did to make it work I will update this answer.
Found the answer:
Found out when I run php artisan vendor:publish it gives a list to publish or something and i'm guessing I did not do the one that specifically publishes Nexmo. Still should've worked though because I did the one that will publish everything. Anyways that published the Nexmo file in config folder. Somehow that is what made everything else work, that and probably a combination of answer/suggestions
Anyways thanks guys for your help!!
First of all, the Nexmo documentation did not mention about to use with Laravel but there are as a additional package you need to use if you used with Laravel.
There are are a simple solution.You need to install a additional package that already provide by Nextmo to use with Laravel.Just install below one.I hope this will help u.
composer require nexmo/laravel
try it
$nexmo = app('Nexmo\Client');
$nexmo->message()->send([
'to' => 'yournumber',
'from' => 'yournumber',
'text' => "message"
]);

Where should I put a library in a Yii project that is not available via Composer?

I can't put the library under vendor/ because that directory is ignored in .gitignore. I put it under bing-ads/ and I have
<?php
namespace app\models;
include 'bing-ads\v10\bingads\ClientProxy.php';
use \Yii;
use BingAds\Proxy\ClientProxy;
to access it. It works for console commands/actions, but I have a feeling it will not work during a web call because the root directory will be web/. Where should I put this library and how can I access it via both console actions and web actions?
The Microsoft PHP library is located here.
I found a way by adding the file paths to the autoload section of composer.json. I remembered that I had to do that for some of the other libraries as well, even the ones available via Composer.
"autoload": {
"classmap": [
"vendor/googleads/googleads-php-lib/src/Google/Api/Ads/Common/Util",
"vendor/googleads/googleads-php-lib/src/Google/Api/Ads/AdWords/Util/v201605",
"bing-ads/v9/bingads/CustomerManagementClasses.php",
"bing-ads/v10/bingads/v10/CampaignManagementClasses.php",
"bing-ads/v10/bingads/v10/BulkClasses.php",
"bing-ads/v10/bingads/ClientProxy.php"
]
}
Then I ran
$ composer install
...
Generating autoload files
I'm not sure this is the best way though.
You could store them wherever you want e.g. in a folder named "BingAds".
Just add the alias as example in a common base config file /common/config/base.php which is included in your console as well as in your web application e.g. for your /web/index.php
$config = \yii\helpers\ArrayHelper::merge(
require(__DIR__ . '/../common/config/base.php'),
require(__DIR__ . '/../common/config/web.php'),
require(__DIR__ . '/../config/base.php'),
require(__DIR__ . '/../config/web.php')
);
Inside this common/config/base.php you could add your settings, extensions etc. which are valid for both the console and your web application
<?php
$config = [
...
'aliases' => [
'#BingAds' => '#app/BingAds/v10',
'#BingAds/Proxy' => '#app/BingAds/v10/bingads',
],
];
Your Clientproxy.php is stored as example in the directory /BingAds/Proxy/.
Then you don't have to include your files every time you want to use them and just write.
use BingAds\Proxy\ClientProxy;
I have unpacked your linked zip file and stored the files of the directory Bing Ads API in PHP\PHP\Bing Ads API in PHP to my application root directory BingAds whith the aliases mentioned above.
I have tested it by creating a clientProxy object in both a console and web application.
$test = new ClientProxy('test');
var_dump($test);
Both Printed out
object(BingAds\Proxy\ClientProxy)[140]
private 'authenticationToken' => null
private 'username' => null
private 'password' => null
private 'developerToken' => null
private 'wsdlUrl' => string 'test' (length=4)
private 'accountId' => null
private 'customerId' => null
private 'service' => null
private 'namespace' => null
I haven`t tested out other classes but I guess you get how it works.
Add this to your composer.json:
{
"repositories": [
{
"type": "package",
"package": {
"name": "microsoft/bing-ads",
"version": "9.0.0",
"dist": {
"url": "https://code.msdn.microsoft.com/Bing-Ads-API-Version-9-in-fb27761f/file/159208/2/Bing%20Ads%20API%20in%20PHP.zip",
"type": "zip"
},
"autoload": {
"classmap": [
"PHP/Bing Ads API in PHP/v10/bingads/"
]
}
}
}
],
"require": {
"microsoft/bing-ads": "9.0.0"
}
}
Then add composer generated autload.php file if you haven't already.
Then you can call the BingAds\Proxy\ClientProxy() without includes.
There's no better way:)
It's best to place external library to extensions directory.
And in config do
return [
'import' => [
'application.extensions.bing-ads.v10.bingads.ClientProxy',
],
...
];
in main and in console configs.
I usually just put the code in a components folder. If you're using the basic template, this folder can be under your application root; if you're using the advanced template, this folder can be under the necessary app: frontend, backend, console, or common. I recommend putting it under common for reasons I shall explain later
Under every app config, Yii 2 uses the ::setAlias method to assign different aliases to the key folders. In the basic app template, #app refers to the application root. While in the advanced template #app may refer to any of backend, frontend, or console.
If your library code is under backend, you can access it like so
namespace backend\controllers;
use yii\web\Controller;
use backend\components\MyLibCode;
class SiteController extends Controller
{
public function actionIndex()
{
$mlb = new MyLibCode();
// ...
}
}
However, it is good Yii 2 practice to have common library code in the common folder. So if this library code is to be used across apps, I suggest you put it into the common\components folder and replace backend with common in the use statement in the code above.
p.s: Justinas method also works; it's borrowed from Yii 1. But this may become cumbersome because this asks Yii to load the class when the application starts. If there is some heavy-lifting in that file, it may be detrimental to the app's performance.

Unable to generate a Cashier PDF in Laravel

I am using Laravel 5 to generate a PDF from a subscription generated from Cashier. The docs say this is as simple as calling:
return $user->downloadInvoice($invoice->id, [
'vendor' => 'Your Company',
'product' => 'Your Product',
]);
Unfortunately I'm getting an odd error:
No hint path defined for [cashier]
The code I am actually using is as follows:
Route::get('billing/invoices/download/{id}', function($id){
$user = Auth::user();
//$invoice = $user->invoices()->find($id);
return $user->downloadInvoice($id, [
'vendor' => 'Certify Me',
//'product' => $invoice->lines->data[0]['plan']->name,
'product' => 'Subscription',
]);
});
The docs make me assume that the PDF is automatically generated. I'd then assume I could override the PDF layout if I chose to.
I just ran into this (L5.1, Cashier 6.0). This seems to be caused by the service provider not being correctly loaded.
Here is how I fixed it:
Check that you have added the correct service provider, at the time of writing that is Laravel\Cashier\CashierServiceProvider to your config/app.php
If it still doesn't work, go run php artisan config:clear to make sure that the service provider is picked up.
Happy invoicing!
I'm going to resurrect this beast.
I had a similar issue because the service provider was not loaded. If you checkout CashierServiceProvider you'll see it adds the necessary 'namespace' for the 'cashier' prefixed views.
public function boot()
{
$this->loadViewsFrom(__DIR__.'/../../views', 'cashier');
$this->publishes([
__DIR__.'/../../views' => base_path('resources/views/vendor/cashier'),
]);
}
Add Laravel\Cashier\CashierServiceProvider to your config/app.php file and inside the providers key.
For anyone who runs across this like we did.

Categories