I am upgrading from Laravel 5.3 to Laravel 5.4. Problem is that when I run composer update and when it comes to php artisan optimize part, I get an error:
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to undefined method Illuminate\Foundation\Application::share()
I've read a couple of questions here on StackOverflow and the answer is to replace this share method with singleton. But where can I find this share()?
EDIT
My composer.json file:
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.4.*",
"sngrl/sphinxsearch": "dev-master",
"laravelcollective/html": "5.4.*",
"aws/aws-sdk-php-laravel": "~3.0",
"league/flysystem-aws-s3-v3": "^1.0",
"mcamara/laravel-localization": "1.2.*",
"league/csv": "^8.2",
"mikehaertl/phpwkhtmltopdf": "^2.2",
"barryvdh/laravel-snappy": "^0.3.3",
"wemersonjanuario/wkhtmltopdf-windows": "dev-master",
"nesbot/carbon": "^1.22",
"uxweb/sweet-alert": "^1.4",
"laracasts/flash": "^2.0",
"guzzlehttp/guzzle": "^6.2",
"illuminate/support": "5.4.*",
"laravel/scout": "^3.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5.7",
"symfony/css-selector": "3.1.*",
"symfony/dom-crawler": "3.1.*"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist"
}
}
Project Share() method file is the Following Path:
Your Project >> Vendor >> laravel >> framework >> src >> Illuminate >> Container >> Container.php
Comment your share() method code and put below code.
public function singleton($abstract, $concrete = null)
{
$this->bind($abstract, $concrete, true);
}
Related
i am using laravel to develop an payments application for that i am using this packageas they mentioned i clone the repository and move easebuz-lib directory inside the project folder,i have created on controller called payController and in this one i included as they mentioned( include_once('easebuzz-lib/easebuzz_payment_gateway.php');) i changed according to the project folder it's working fine but it's failing inside the other easebuzz_payment_gateway.php i could not able to figure out why it's failing can you please help me to fix this issue..?
payController.php
<?php
namespace App\Http\Controllers;
use Easebuzz;
use Illuminate\Support\Facades\Request;
include_once('../easebuzz-lib/easebuzz_payment_gateway.php');
class PayController extends Controller
{
public function pay(Request $request){
$key = config('constants.easebuzz')['merchant_key'];
$salt = config('constants.easebuzz')['salt'];
$env = config('constants.easebuzz')['env'];
$easebuzzObj = new Easebuzz($key,$salt,$env);
$postData = [
"txnid" => 'TEST'.rand(0,100),
"amount" => '10.00',
"firstname" => 'sai',
"email" =>'sai',
"phone" => 'sai',
"productinfo" => 'This is for dummy test',
"surl" => "http://127.0.0.1:8000/response.php",
"furl" => "http://127.0.0.1:8000/response.php",
];
$easebuzzObj->initiatePaymentAPI($postData);
var_dump($easebuzzObj);
}
}
easebuzz_payment_gateway.php
public function initiatePaymentAPI($params, $redirect=True){
//initially it was include_once('payment.php') i changed to following way
include_once('/payment.php');
// generate transaction ID and push into $params array
// $txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
// $params['txnid'] = $txnid;
return initiate_payment($params, $redirect, $this->MERCHANT_KEY, $this->SALT, $this->ENV);
}
composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.75",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5"
},
"require-dev": {
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^5.10",
"phpunit/phpunit": "^9.5.10"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
},
"classmap": ["easebuzz-lib/"]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-update-cmd": [
"#php artisan vendor:publish --tag=laravel-assets --ansi --force"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
It would be better to not use include_once here, instead add path to this library to classmap in composer.json:
{
"autoload": {
"classmap": ["path/to/easebuzz-lib/"]
}
}
then run:
composer dump-autoload
Also you should not edit files in library, especially restore this thing:
include_once('/payment.php');
to original:
include_once('payment.php');
Go to payment.php and add line for check whether function exists
if(!function_exists('response')) {
The "view()->share(...)" I placed in the boot method of the ComposerServiceProvider file does not work. But when I put it in AppServiceProvider it works. I also added ComposerServiceProvider to "providers" section in app.php file.
The error:
ErrorException
Undefined variable: test (View: /Users/devtools/Projects/sites/laravel/resources/views/components/backend/sidebar/menu-list.blade.php)
http://localhost/tr/admin/settings
What could be the problem? Thanks for help.
They are my codes:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class ComposerServiceProvider extends ServiceProvider
{
// ...
public function boot()
{
// This code works when I put it in AppServiceProvider.php
view()->composer('*', function ($view) {
view()->share('test', 'deneme');
});
}
}
config/app.php:
// ...
'providers' => [
/*
* Application Service Providers...
*/
App\Providers\ComposerServiceProvider::class,
],
routers/web.php:
Route::prefix(LaravelLocalization::setLocale() . "/admin")
->name('admin.')
->middleware(['localeSessionRedirect', 'localizationRedirect', 'localize', 'auth', 'verified'])
->group(function ()
{
Route::get('/', function () {
return view('backend.home');
})->name('home');
});
composer.json
{
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^7.2.5|^8.0",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^6.3.1|^7.0.1",
"laravel/framework": "^7.29",
"laravel/tinker": "^2.5",
"laravel/ui": "^2.4",
"mcamara/laravel-localization": "^1.6"
},
"require-dev": {
"almasaeed2010/adminlte": "~3.0",
"facade/ignition": "^2.0",
"fakerphp/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"nunomaduro/collision": "^4.3",
"phpunit/phpunit": "^8.5.8|^9.3.3"
},
"config": {
"optimize-autoloader": true,
"preferred-install": "dist",
"sort-packages": true
},
"extra": {
"laravel": {
"dont-discover": []
}
},
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi"
],
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
]
}
}
As you can see these are the file name and paths
SOLUTION:
The problem was that I deleted the "data" folder in
"storage/framework/cache/". When I ran the "php artisan cache:clear"
command, it gave an error. I added the folder and it's okay.
try this :
View::composer('*', function($view)
{
$view->share('test', 'deneme');
});
and do not forget to add this too:
use View;
I recently made pdf reports with phpjasperxml in a web application with php 5.5.9 and laravel 5.2.0.
I made the report in ireport 5.6.0 and it works perfectly.
but when I try to show the pdf report from the web application it does not show me the images that I put in the report.
composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"laravelcollective/html": "^5.2.0",
"laracasts/flash": "^3.0",
"fzaninotto/faker": "^1.7"
},
"require-dev": {
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*",
"barryvdh/laravel-dompdf": "0.6.*",
"phpoffice/phpword": "dev-master",
"laurentbrieu/tcpdf": "dev-master",
"sergio-vilchis/laravel-phpjasperxml": "^1.0",
"jaspersoft/rest-client": "v2.0.0"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"PhpOffice\\PhpWord\\": "src/PhpWord"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist"
}
}
Controller.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Requests\ReportesRequest;
use Illuminate\Support\Facades\DB;
use PHPJasperXML;
use Response;
class ReportesController extends Controller
{
public function Reporte_planilla_dieta_prof_noDocpdf($tipo)
{
$parametros = explode(' ', $tipo);
$verdescar=$parametros[0];
$mes=$parametros[1];
$anio=$parametros[2];
$server="localhost";
$db="siarcaf";
$user="root";
$pass="";
$version="0.8b";
$pgport=5432;
$pchartfolder="./class/pchart2";
//display errors should be off in the php.ini file
//ini_set('display_errors', 0);
//setting the path to the created jrxml file
$xml =simplexml_load_file("C:/xampp/htdocs/siarcaf/resources/views/Reportes/Reporte_planilla_dieta_prof_noDocpdf.jrxml");
$PHPJasperXML = new PHPJasperXML();
//$PHPJasperXML->debugsql=true;
//dd($mes12);
$PHPJasperXML->arrayParameter=array("mes1"=>"'$mes'");
//dd($sql);
//$PHPJasperXML->sql = $sql;
$PHPJasperXML->xml_dismantle($xml);
$dbdriver="mysql";
$PHPJasperXML->transferDBtoArray($server,$user,$pass,$db,$dbdriver);
//ob_end_clean();
//dd($PHPJasperXML);
if($verdescar==1) //page output method I:standard output D:Download file
{
$PHPJasperXML->outpage("I");
//return Response::make($PHPJasperXML->outpage("I"));
}
if($verdescar==2)
{
$PHPJasperXML->outpage("D");
}
}
}
PHPJasperXML require absolute base path of image in expression. you can pass expression by parameter or fields. your image path must be live var/www/html/SITE_FOLDER/IMAGE_PATH
and evaluation type must be string.
I have this in my composer.json
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=7.0.0",
"alchemy/zippy": "^0.4.8",
"barryvdh/laravel-debugbar": "^3.1",
"fideloper/proxy": "~3.3",
"graham-campbell/exceptions": "^10.0",
"intervention/image": "^2.4",
"intervention/imagecache": "^2.3",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0",
"laravelcollective/html": "^5.5",
"symfony/dom-crawler": "^3.3"
},
"files": [
"vendor/redbutton/text-image-alpha/vendor/autoload.php"
],
"require-dev": {
"filp/whoops": "^2.1",
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~6.0"
},
"autoload": {
"classmap": [
"database/seeds",
"database/factories"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"dont-discover": [
]
}
},
"scripts": {
"post-root-package-install": [
"#php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"#php artisan key:generate"
],
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
}
}
The php files for my package are in a laravel installation:
/vendor/redbutton/text-image-alpha/src/
When I try to call a file I get the message:
Class 'Class 'RedButton\TextImageAlpha\TextImageAlpha' not found' not found
I use this to try and call the class:
$image = new \RedButton\TextImageAlpha\TextImageAlpha( 'some string' );
The file in /vendor/redbutton/text-image-alpha/src/TextImageAlpha.php looks like this:
<?php
namespace RedButton\TextImageAlpha;
use RedButton\TextImageAlpha\Exceptions;
use RedButton\Tools\Objects;
/**
* TextImageAlpha class convert a text to image.
*
* #author Tomas Rathouz <trathouz at gmail.com>
*/
class TextImageAlpha
{
// lots of code
}
This is my first composer package and I don't really have an idea of what is going wrong here. Could someone please explain to me what I'm doing wrong?
Good news. I've looked at your package at Bitbucket and you're doing it right in its composer.json:
Drop unnecessary code from composer.json
I've noticed in pasted composer.json there is manual adding of some vendor file.
"files": [
"vendor/redbutton/text-image-alpha/vendor/autoload.php"
],
/vendor nested in /vendor doesn't make sense as it might duplicate autoloading and break it.
Also I don't see redbutton/text-image-alpha in require section, where it should be.
How to add package the right way?
To install your package just call composer:
composer require redbutton/text-image-alpha
And that's it.
It should appear in require section in composer.json. Composer will autoload it by rules in composer.json of the package - here.
Test
I've tried following code and class is found correctly:
<?php
require __DIR__ . '/vendor/autoload.php';
$image = new \RedButton\TextImageAlpha\TextImageAlpha('some string');
var_dump($image);
Having composer.json:
{
"require": {
"redbutton/text-image-alpha": "^1.0"
}
}
Laravel project, simple test, only tries to load the default page '/'
SIMPLE TEST
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
/**
* A basic test example.
*
* #return void
*/
public function testBasicTest()
{
$response = $this->get('/');
$response->assertStatus(200);
}
}
ERROR MESSAGE via PhpStorm
Class 'PHPUnit\Framework\Assert' not found
/var/www/vhosts/app-native/app-app/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:52
/var/www/vhosts/app-native/app-app/tests/Feature/ExampleTest.php:21
ERROR MESSAGE via CLI
# php vendor/phpunit/phpunit/phpunit
PHPUnit 5.6.4 by Sebastian Bergmann and contributors.
EEE.. 5 / 5 (100%)
Time: 1.78 seconds, Memory: 16.00MB
There were 3 errors:
1) Tests\Feature\ExampleTest::testBasicTest
Error: Class 'PHPUnit\Framework\Assert' not found
/var/www/vhosts/app-native/app-app/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:52
/var/www/vhosts/app-native/app-app/tests/Feature/ExampleTest.php:21
2) Tests\Feature\JsonTest::testSignup
Error: Class 'PHPUnit\Framework\Assert' not found
/var/www/vhosts/app-native/app-app/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:52
/var/www/vhosts/app-native/app-app/tests/Feature/JsonTest.php:29
3) Tests\Feature\RoutesTest::testBasicTest
Error: Class 'PHPUnit\Framework\Assert' not found
/var/www/vhosts/app-native/app-app/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:52
/var/www/vhosts/app-native/app-app/tests/Feature/RoutesTest.php:21
ERRORS!
Tests: 5, Assertions: 2, Errors: 3.
Upon further investigation...
The Assert class is not found via the IDE either.
Looking into the composer autoloader, the only PHPUnit\Framework classes being loaded is the "ForwardCompatibility/TestCase ???!!!
3285'PHPUnit\\Framework\\TestCase' => $vendorDir . '/phpunit/phpunit/src/ForwardCompatibility/TestCase.php',
3825'PHPUnit\\Framework\\TestCase' => __DIR__ . '/..' . '/phpunit/phpunit/src/ForwardCompatibility/TestCase.php',
Here is my composer file, for good measure...
{
"name": "app/webapp",
"description": "app Web App (API & Frontend).",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.4.*",
"laravel/tinker": "~1.0",
"laravelcollective/html": "~5.0",
"laracasts/flash": "~1.3",
"maatwebsite/excel": "~2.1",
"guzzlehttp/guzzle": "~6.2",
"doctrine/dbal": "~2.5",
"laravel/cashier": "~7.0",
"league/flysystem-aws-s3-v3": "~1.0",
"zizaco/entrust": "1.7.0",
"barryvdh/laravel-ide-helper": "^2.2",
"blueimp/jquery-file-upload": "^9.14",
"ipunkt/laravel-analytics": "^1.3",
"braintree/braintree_php": "^3.21",
"tymon/jwt-auth": "0.5.*",
"f2m2/apidocs": "~2.0",
"barryvdh/laravel-cors": "0.8.*",
"pulkitjalan/geoip": "~2.4",
"aws/aws-sdk-php-laravel": "^3.1",
"vsmoraes/laravel-pdf": "^1.0",
"propaganistas/laravel-phone": "^2.8",
"activecampaign/api-php": "~2.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~5",
"phpspec/phpspec": "~2.1",
"ozankurt/repoist": "^1.0",
"symfony/dom-crawler": "~3.1",
"symfony/css-selector": "~3.1"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postInstall",
"php artisan ide-helper:generate",
"php artisan ide-helper:meta",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"php artisan ide-helper:generate",
"php artisan ide-helper:meta",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist",
"sort-packages": true
}
}
Upgrading to PhpSpec 3 will solve your dependency problem.
Older versions of PhpSpec can't be installed alongside very recent versions of PHPUnit, as they both require different versions of sebastian/exporter.