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
Related
i try to use phpqrcode library in laravel project this package is very popular , this is her link
https://sourceforge.net/projects/phpqrcode/
i use class qrCode in controller but i got this error
message
:
"Class "QRcode" not found"
error when i use phpqrcode class in laravel framework
this is my controller
public function store(Request $request)
{
$input = $request->all();
// include(app_path().'/phpqrcode/qrlib.php');
$code = $request->email ;
$filename ='test' . md5($code) . '.png';
QRcode::png($code, \public_path("temp/$filename"));
$input['qr_code']= $filename;
Participant::create($input);
return response()->json(['status'=>'success','message'=>'participant saved succefully !' ],201);
}
How did you proceed with the installation of the lib into your project?
The lib documentation has some steps that you should follow in order to get started.Please check on the INSTALL FILE.
Personally, I would recommend you use a dependency installed from composer.
Some popular ones can be found at packagist. Try out this as it is well documented
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'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.
I have upgraded my app from Laravel 4.2 to 5.5 and I am getting issues with the queue.
public function saved(Model $review)
{
if (App::runningInConsole()) {
return;
}
$data = [
'review' => serialize($review),
'action' => self::ACTION_SAVE
];
Queue::push(new UpdateReviewSummaryQueue, $data);
}
When I run this on model save, I am getting an error that the UpdateReviewSummaryQueue class does not exist. I've ran composer dump-autoload and namespacing seems to be fine. Are there any other issues I might look into?
I've also added
use SerializesModels;
as Laravel upgrade guide suggested
In laravel 5.5 you now dispatch jobs rather than push. See https://laravel.com/docs/5.5/queues#dispatching-jobs for full documentation.
Try :
dispatch((new UpdateReviewSummaryQueue($data));
The issue was actually in this line:
Queue::push(new UpdateReviewSummaryQueue, $data);
Changing it to this made it work:
Queue::push(UpdateReviewSummaryQueue::class, $data);
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.