I'm trying to import excel file (.xlsx) using maatwebsite 3.0. How to fix This error
Call to undefined method Maatwebsite\Excel\Excel::load()
My controller
public function importsave(Request $request)
{
if($request->hasFile('excel'))
{
$path = $request->file('excel')->getRealPath();
$data= Excel::load($path, function($reader) {})->get();
if(!empty($data) && $data->count())
{
foreach($data->toArray() as $key=>$value)
{
if(!empty($value))
{
Employee::insert($value);
}
}
}
}
}
Version 3.0 of that package doesn't handle imports yet. Release date for this feature is unknown. See this post for more details: https://medium.com/#maatwebsite/laravel-excel-lessons-learned-7fee2812551
I suggest you switch to version 2.*.
Else you want to continue further
ALL Laravel Excel 2.* methods are deprecated and will not be able to use in 3.0 .
Excel::load() is removed and replaced by Excel::import($yourImport)
Excel::create() is removed and replaced by Excel::download/Excel::store($yourExport)
Excel::create()->string('xlsx') is removed an replaced by Excel::raw($yourExport, Excel::XLSX)
3.0 provides no convenience methods for styling, you are encouraged to use PhpSpreadsheets native methods.
Hi there in version 3 the load method was remove so switch back to version two like so try using this command,
composer require "maatwebsite/excel:~2.1.0"
ALL Laravel Excel 2.* methods are deprecated and will not be able to use in 3.0 .
Excel::load() is removed and replaced by Excel::import($yourImport)
Excel::create() is removed and replaced by Excel::download/Excel::store($yourExport)
Excel::create()->string('xlsx') is removed an replaced by Excel::raw($yourExport, Excel::XLSX)
3.0 provides no convenience methods for styling, you are encouraged to use PhpSpreadsheets native methods.
^3.0 versions of maatwebsite/excel does not support loads.
Delete the config/excel.php file first .
Downgrade the maatwebsite/excel version by changing your composer.json file from
"maatwebsite/excel": "^3.1", to "maatwebsite/excel": "~2.1.0", and performing 'composer update'.
And if you get an error:
Undefined class constant 'XLSX' in 2.1 version
this is what you have to do.
Delete the config/excel.php before downgrading then perform the composer update.
Dont panic :) Just do like this
Excel::toArray([],$filePath);
Just pass an empty array as the first parameter
Version 3.0 of Laravel Excel doesn't handle imports.
You could also use an alternative package that works with import such as:
https://github.com/Cyber-Duck/laravel-excel (Laravel Excel Fork)
https://github.com/rap2hpoutre/fast-excel (Faster alternative to Laravel Excel)
Both handles import.
You could also switch to version 2, but it means use an old version of a lib.
Related
I am using
travoltron/plaid
for laravel(5.6).
Plaid package version is "travoltron/plaid": "^2.0" and guzzle version is "guzzlehttp/guzzle": "6.0".
I have followed the documentation and placed
PLAID_CLIENT_ID=**********************
PLAID_SECRET=**************************
in .env file.
now when i use
use Plaid;
public function auth() {
$authUser = Plaid::addAuthUser('user_good', 'pass_good', null, 'chase');
return $authUser;
}
it show me an error "count(): Parameter must be an array or an object that implements Countable".
If my approach regarding using this package is wrong please suggest me better way
or guide me.
So, the Plaid package you're using is from an unofficial (community-maintained) package that hasn't been updated in 3 years.
While we can't really support community packages, I'd at least suggest using a more actively maintained library, like this one by TomorrowIdeas: https://github.com/TomorrowIdeas/plaid-sdk-php
Am running Laravel 5.8 and getting this error when seeding
Seeding: CategoriesTableSeeder
ErrorException : implode(): Passing glue string after array is deprecated. Swap the parameters
at /Users/saly/Sites/Saly/vendor/fzaninotto/faker/src/Faker/Provider/Lorem.php:95
91|
92| $words = static::words($nbWords);
93| $words[0] = ucwords($words[0]);
94|
95| return implode($words, ' ') . '.';
96| }
97|
98| /**
99| * Generate an array of sentences
Exception trace:
1 implode(" ")
/Users/saly/Sites/Saly/vendor/fzaninotto/faker/src/Faker/Provider/Lorem.php:95
2 Faker\Provider\Lorem::sentence()
/Users/saly/Sites/Saly/vendor/fzaninotto/faker/src/Faker/Generator.php:222
> Please use the argument -v to see more details.
The app is passing tests just fine in CI using PHP 7.3 and 7.2 so the problem might be PHP 7.4 in my local machine "OSX"
Here's my seed file
<?php
use Saly\Category;
use Illuminate\Database\Seeder;
class CategoriesTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* #return void
*/
public function run()
{
factory(Category::class, 3)->create();
}
}
And the factory
<?php
use Saly\Category;
use Faker\Generator as Faker;
$factory->define(Category::class, function (Faker $faker) {
$name = $faker->sentence(4, true); // Here maybe?
return [
'name' => $name,
'slug' => sluggify($name),
];
});
I think the problem is in the line where sentence() is used but I can't tell how to solve it because I just copied that line from the Faker docs
What does this error mean and how can I solve it?
This has already been fixed in the most recent version of Faker. In your error it says
> 95| return implode($words, ' ') . '.';
but if we look at line 95 of the source we see:
> 95| return implode(' ', $words) . '.';
So, all you need to do is pull the latest version of Faker, probably by doing
composer update fzaninotto/faker
You can swap (in affect lines with implode command) glue and array.
Example:
return implode($words,' ') . '.';
to
return implode(' ',$words) . '.';
also, The newest version of the fzaninotto/faker package solves this issue.
I am using php 7.4 with apache2,mariadb 10,yii2 advanced. Update your faker using below command
composer update fzaninotto/faker
and
sudo service apache2 reload
then it:this error and
Error (#32)
An internal server error occurred.
The above error occurred while the Web server was processing your request.
Please contact us if you think this is a server error. Thank you.
Fixes the issue.
This is happend for backward version of fzaninotto/faker. Update your faker using below command
composer update fzaninotto/faker
I am using php 7.3 and 7.4 using homebrew.
I have two projects one is using 7.3 and other is using 7.4.
If I run project with 7.4 which requires 7.3 then same issue occures. when I change php version to required version (7.3) then it fixes the issue.
It is not Laravel related issue. It is due to new versions of PHP disallowed the use of previously used implode method.
Here is how I fixed it in PHP:
Create a function:
function HA_implode($value1,$value2){
if (is_array($value1)) {
return implode($value2, $value1);
} else {
return implode($value1, $value2);
}
}
Now simply rename all functions in the PHP script from implode to HA_implode and you are done
This is useful in scripts where impode is commonly used as per the previous method and changing all the code can be a time wasting problem. So simply rename all implode functions using find / replace option of any PHP or text editor.
I am using Maatwebsite/Excel in my application and when i get the error
Call to undefined method Maatwebsite\Excel\Excel::create()
from one of my controllers. I am using laravel 5.6 and i have followed the documentation strictly and other very few related discussions online to solve this, but i still get the error.
How do i solve this error please
app.php
'provider' => 'Maatwebsite\Excel\ExcelServiceProvider',
'alias' => 'Excel'=> 'Maatwebsite\Excel\Facades\Excel',
Controller
$cl = ClassModel::Select('name')->where('code',$input->class)->first();
$input->class=$cl->name;
$fileName=$input->class.'-'.$input->section.'-'.$input->session.'-'.$input->exam;
// return $students;
Excel::create($fileName, function($excel) use($input,$subjects,$students) {
$excel->sheet('New sheet', function($sheet) use ($input,$subjects,$students) {
$sheet->loadView('app.excel',compact('subjects','input','students'));
});
})->download('xlsx');
You are using 2.* syntax while using 3.* package. Please refer to the correct documentation over here: https://laravel-excel.maatwebsite.nl/docs/3.0/export/basics
Try to decrease the version using :
composer require "maatwebsite/excel=2.1.0"
There have been many changes in the new version of the package.
In your composer.json file inside the require array replace your package with this:
"maatwebsite/excel": "~2.1.0",
and then run composer update
This should work fine.
Please switch to version 2*
Version 3.0 of that package doesn't handle imports yet. Release date for this feature is unknown. See this post for more details: maatwebsite
I have worked it around but I know it's not a perfect solution. It will really help you if you only have concerns with the uploading not adjusting Crudbooster features.
I removed the extra features from the importing screen of the Crudbooster by applying the following CSS in the crudbooster-controller.
$this->style_css = "ul.nav li:not(:first-child) {
display: none;
}";
I copied the getImportData() method from Crudbooster CBController and overridden it in the crudbooster-controller by the following code.
//PHP
//By the way, you can still create your own method in here... :)
public function getImportData()
{
$this->cbLoader();
$data['page_menu'] = Route::getCurrentRoute()->getActionName();
$data['page_title'] = 'Import Data';
if (request('file') && ! request('import')) {
$file = base64_decode(request('file'));
$file = storage_path('app/'.$file);
$data = Excel::import(new ProductImport, $file);
CRUDBooster::redirect('/admin/products', cbLang("alert_add_data_success"), 'success');
}
return view('crudbooster::import', $data);
}
Importing is working fine now
I'm using Twig template engine with slim framework 3
i have a simple function inside my controller
public function test_twig($request, $response, $args) {
return $this->view->render($response, "login.phtml");
}
When i run this code in the locahost it works perfectly, but i tried it in my server it shows an empty page, very wierd behavior the page has no dynamic variables it's just HTML
I've tried this also :
$str = $this->view->fetchFromString('<p>Hi, my name is {{ name }}.</p>', [
'name' => "oussama"
]);
$response->getBody()->write($str);
return $response;
It worked in the localhost and not in my server ( i have PHP 5.6 in my server )
After following the execution i ended up here the compile function can not compile a simple HTML file !!!
/**
* Compiles a template source code.
*
* #return string The compiled PHP source code
*
* #throws Twig_Error_Syntax When there was an error during tokenizing, parsing or compiling
*/
public function compileSource(Twig_Source $source)
{
try {
return $this->compile($this->parse($this->tokenize($source)));
} catch (Twig_Error $e) {
$e->setSourceContext($source);
throw $e;
} catch (Exception $e) {
throw new Twig_Error_Syntax(sprintf('An exception has been thrown during the compilation of a template ("%s").', $e->getMessage()), -1, $source, $e);
}
}
I did follow the code till Twig_Lexer Class Inside the Constructor
Exactly in this line :
'operator' => $this->getOperatorRegex(),
Twig since version v2.0.0 has required PHP version 7.0 or above. As you have stated that you have PHP 5.6 on the remote server, they will not work together. You can either upgrade to PHP 7 on the remote (if possible), or downgrade twig to v1.35.0, which still supports PHP 5.
Source:
https://packagist.org/packages/twig/twig#v2.2.0
https://github.com/twigphp/Twig/blob/29bb02dde09ff56291d30f7687eb8696918023af/composer.json
Twig 2.4 requires PHP 7 and above. Your server does not satisfy that requirement and Twig fails.
We need to override the default Twig dependency by setting our own. Add a Twig dependency in your project conposer.json file:
"twig/twig":"^1.18"
Tell composer to run the new configuration and apply the changes:
composer update
I just made this working by changing my composer.json requires:
"slim/twig-view": "2.0", change the version to 2.0 since it works with PHP 5.6
Also there was and issue with Eloquent if you use the version "~5.1" it won't work i just putted a strict version "5.4.36" for Database Dependency like this :
"illuminate/database": "5.4.36"
I have two function in my controller and service. I want to call a function in service. Here is my code :
Controller:
public function findNeighborhoodGet(): array
{
$regionCenter = Request::get('region_center');
$distanceService = \App::make('App\web\one\Infrastructure\Service\Google\Map');
try {
$userPoint = $distanceService->getOriginPoint($regionCenter);
}
.
.
.
return $result
}
my service (Map.php) :
public function getOriginPoint(string $origin):Point
{
dd($origin);
return $this->getPointObject($origin);
}
Actually , I get an error :
A non well formed numeric value encountered
at this line:
public function getOriginPoint(string $origin):Point
How to solve it?
This is a bug in the symfony/var-dumper package when using PHP7.1. It was fixed in version 2.7.16, 2.8.9, 3.0.9 and 3.1.3. See the pull request: https://github.com/symfony/symfony/pull/19379
In my case, I needed to composer update my laravel framework packages, as my vendor directory copy of that package was at 2.7.9. (I'm using Laravel 5.1; later versions use 2.8 and 3.0 of symfony, which also had the bug)
I had the same issue on Laravel 5.2 PHP 7.1. If you don't want to update the entire framework, you can do:
composer update symfony/var-dumper
as stated here.