I already implemented jasper reports with laravel and it works fine for me. Now i shifted to laravel lumen for api building so i try to integrate jasper as same as i integrate in my laravel projects but in laravel lumen it throws some error as below:-
Call to undefined method Laravel\Lumen\Application::booting()
below is my connection code
class_alias(JasperPHP\JasperPHPServiceProvider::class,'JasperPHP');
$app->withFacades(); $app->withEloquent();
$app->register(App\Providers\AppServiceProvider::class);
$app->register(App\Providers\AuthServiceProvider::class);
$app->register(App\Providers\EventServiceProvider::class);
$app->register(JasperPHP\JasperPHPServiceProvider::class);
Please share your thoughts, Thanks in advance
I finally come up with a solution and it works fine with laravel lumen 5.6 below are the steps:-
1)Install JasperReports 6 library by below command
composer require cossou/jasperphp
In bootstrap/app.php uncomment this line $app->withFacades(); and add below code
$app->singleton('jasperphp', function ($app) {
return new JasperPHP;
});
$app->alias('JasperPHP\JasperPHPServiceProvider\JasperPHP', 'JasperPHP');
Controller part Changes
namespace App\Http\Controllers;
use JasperPHP\JasperPHP as JasperPHP;
use Illuminate\Http\Request;
//dd(__DIR__ . '/../../vendor/cossou/jasperphp/examples/hello_world.jasper');
class ReportController extends Controller {
public function generateReport() {
//JasperPHP::compile(base_path('/vendor/cossou/jasperphp/examples/hello_world.jrxml'))->execute();
$jasper = new JasperPHP;
$filename = 'gau';
$output = base_path('//public/reports/' . $filename);
$jasper->process(
base_path('/vendor/cossou/jasperphp/examples/LaravelIreporTest.jasper'),
$output,
array("pdf"),
array("test" => "Tax Invoice"),
array(
'driver' => 'mysql',
'username' => 'username',
'password' => 'password',
'host' => 'localhost',
'database' => 'database name',
'port' => '3306',
)
)->execute();
}
}
Related
I'm fresh beginner in Laravel 5.8 and i'm trying to develop an app with LDAP authentication.
I use this package : https://adldap2.github.io/Adldap2-Laravel/#/auth/setup
So, here is my configuration code (app.php) :
// service providers array
Adldap\Laravel\AdldapServiceProvider::class,
Adldap\Laravel\AdldapAuthServiceProvider::class
// aliases array
'Adldap' => Adldap\Laravel\Facades\Adldap::class
The LDAP configuration (ldap.php) :
'hosts' => explode(' ', env('LDAP_HOSTS', 'myserver1 myserver2'))
'port' => env('LDAP_PORT', 389),
'base_dn' => env('LDAP_BASE_DN', 'dc=mydc1,dc=mydc2,dc=mydc3'),
'username' => env('admin'),
'password' => env('admin'),
The authentication configuration (auth.php) :
// user provider fields
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'users' => [
'driver' => 'adldap',
'model' => App\User::class,
],
],
And then the UserController:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Adldap\AdldapInterface;
class UserController extends Controller
{
protected $ldap;
public function __construct(AdldapInterface $ldap) {
$this->ldap = $ldap;
}
public function index() {
$users = $this->ldap->search()->users()->get();
return view('users.index',compact('users'));
}
}
And i got this error : Authentication user provider [adldap] is not defined.
Does anyone know this error and could tell me where my configuration can be wrong ?
Thansk for your help :)
EDIT : Idk if this could help but this morning the error precise me that the problem is in the welcome.blade.php file
You need to add some basic configuration in your .env file
ACCOUNT_PREFIX = local
ACCOUNT_SUFFIX = local
DOMAIN_CONTROLLERS = "172.16.20.142"
PORT = 389
TIMEOUT = 5
BASE_DN = "dc=local,dc=local"
USER_DN = "cn=users,dc=dummy,dc=local"
ADMIN_ACCOUNT_SUFFIX = #man.local
ADMIN_USERNAME = administrator
ADMIN_PASSWORD = dsds
LDAP_USER_CUSTOM_EMAIL_DOMAIN = #man.local
and check your aldap.config once
after that please clear cache of config by following command
php artisan config:clear && php artisan cache:clear && php artisan view:clear && php artisan route:clear && php artisan config:cache
I have updated my project based on Slim Framework to Slim 4 today. I'm working with the Medoo (database framework) here.
https://medoo.in/api/collaboration
Here the Slim integration is explained:
use Medoo\Medoo;
$container = $app->getContainer();
$container['database'] = function () {
return new Medoo([
'database_type' => 'mysql',
'database_name' => 'name',
'server' => 'localhost',
'username' => 'your_username',
'password' => 'your_password'
]);
};
The Query looks like:
$datas = $this->database->select("accounts", "*");
The error message I have received since the update is the following:
Got error 'PHP message: Slim Application Error:\nType: Error\nCode:
0\nMessage: Using $this when not in object
Have any of you had the problem? I have tried everything that I have in experience. I can't get any further here
I am following Laravel office Redis guide but i am having some problem
https://laravel.com/docs/5.2/redis#pubsub
After creating the command when i run " -> php artisan redis:subscribe" in console i get following error
[Symfony\Component\Console\Exception\CommandNotFoundException]
There are no commands defined in the "redis" namespace.
I am unable to listen to Redis Chanel.
Redis Publish Channel method is working fine. To check this.
In console I typed "-> redis-cli" and then "subscribe mychannel"
On refreshing browser I am getting publish data in console.
I am unable to subscribe via Laravel.
I also tried using wild card
Route::get('/subscribe', function()
{
Redis::psubscribe(['*'], function($message, $channel) {
echo $message;
});
});
but browser keep loading and i don't get any data.
I also tried making a method in controller
public function subscribeChannel()
{
$redis = Redis::Connection();
$redis->subscribe(['channel'], function($message) {
echo $message;
});
}
This subscribeChannel method gives me following error
ErrorException in StreamConnection.php line 390:
strlen() expects parameter 1 to be string, array given
My configuration in config/database.php is folowing
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
'read_write_timeout' => 0
],
],
Looking for help
thanks
Redis::connection & then subscribe not working for Laravel 5.2.
You can use following command for the same:
Redis::subscribe(['user_online_offline'], function ($message) {
echo $message;
});
If you want to use another connection for the same then you can use following command:
Redis::subscribe(['user_online_offline'], function ($message) {
echo $message;
}, $connection = 'socket');
For some reason I cannot extend the Storage Class like the example in the docs.
I have been trying to create an FTP adapter because it is required for the project I am working on.
Here is the Service Provider I have created
<?php namespace herbals\Providers;
use Storage;
use Illuminate\Filesystem\FilesystemServiceProvider as ServiceProvider;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Ftp as FTPAdapter;
class FTPFileSystemServiceProvider extends ServiceProvider {
public function boot()
{
Storage::extend('ftp', function($app, $config)
{
$client = new FTPAdapter(array(
'host' => env('FTP_HOST') || '',
'username' => env('FTP_USERNAME') || '',
'password' => env('FTP_PASSWORD') || '',
'port' => env('FTP_PORT') || '',
'root' => env('FTP_ROOT') || '/',
'passive' => true,
'ssl' => true,
'timeout' => 30,
));
$filesystem = new Filesystem($client);
return $filesystem;
});
}
public function register()
{
//
}
}
Here is the error I keep getting
ErrorException in FilesystemManager.php line 232:
call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Filesystem\FilesystemAdapter' does not have a method 'createDriver'
in FilesystemManager.php line 232
at HandleExceptions->handleError('2', 'call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Filesystem\FilesystemAdapter' does not have a method 'createDriver'', '/home/vagrant/Code/herbals/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php', '232', array('method' => 'createDriver', 'parameters' => array(null)))
at call_user_func_array(array(object(FilesystemAdapter), 'createDriver'), array(null)) in FilesystemManager.php line 232
at FilesystemManager->__call('createDriver', array(null)) in FilesystemManager.php line 97
at FilesystemManager->createDriver(null) in FilesystemManager.php line 97
at FilesystemManager->resolve('ftp') in FilesystemManager.php line 79
at FilesystemManager->get('ftp') in FilesystemManager.php line 68
at FilesystemManager->disk('ftp') in Facade.php line 210
at Facade::__callStatic('disk', array('ftp')) in routes.php line 26
at Storage::disk('ftp') in routes.php line 26
I think you are making a little mistake here, make sure you have the ftp drivers and its details (host, username,password ) in /config/filesystem.php and reference them in your provider using $config['host'] and so on...
After playing with the api for some time , I was able to figure it out , now follow these instructions : In you /config/filesystem.php , add the new driver settings like :
'ftp' => [
'driver' => 'ftp',
'host' =>'ftp-host',
'username' => 'ftp-username',
'password' => 'ftp-pass',
'port' => 21,
'ssl' => false,
],
Next we will create an Ftp Filemanager Driver Service Provider in /app/Providers ,save the file FtpFilesystemServiceProvider.php .. Below is how mine looks like
<?php
namespace App\Providers;
use Storage;
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Ftp as FtpAdapter;
use Illuminate\Support\ServiceProvider as ServiceProvider;
class FtpFilesystemServiceProvider extends ServiceProvider {
//boot
public function boot()
{
Storage::extend('ftp',function($app, $config){
//init the client
$client = new FtpAdapter($config);
//lets now call the obj
$ftpFileSystem = new Filesystem($client);
//return
return $ftpFileSystem;
});
}//end boot
public function register()
{
//
}
}
After which we will edit /config/app.php and add the service provider to providers array so you will add the code below to the list of providers:
'App\Providers\FtpFilesystemServiceProvider',
We are done, you are off to go , yo can call the storage like this
Storage::disk("ftp");
or set ftp as your default driver , ....
I want to use Illuminate database(https://github.com/illuminate/database). Not with Laravel, use only in my php file.
I do
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]);
But it seems not working, and don't show any error message. Do I need to require any file? The illuminate directory is in the same directory with my php file.
EDIT:
I can use query now. Like this
$users = Capsule::table('users')->where('votes', '>', 100)->get();
I don't know how to use model.
User.php
class User extends Illuminate\Database\Eloquent\Model {
}
My php file
require 'vendor/autoload.php';
require 'User.php';
$users = User::where('status', '=', 1)->get();
Got error
Fatal error: Call to a member function connection() on a non-object in /Users/someone/repos/test/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php on line 2472
SOLVED:
Everything works fine. Use #majid8911 example https://github.com/mattstauffer/IlluminateNonLaravel
Thank you everyone.
take a look at here I successfully did the same with this tutorial:
https://github.com/mattstauffer/IlluminateNonLaravel