Laravel Excel::Import "model" function not invoke - laravel

The new ApacInstaPatientMasterImport doesn't invoke in Excel::import, I have checked the laravel log and it doesn't give any error. Does anyone know what is the problem or any way to debug this?
I have tested the same coding in the development notebook with the following, all works fine
Windows 10, with
"php": "^7.3|^8.0",
"maatwebsite/excel": "^3.1",
"laravel/framework": "^9.0",
but once I transfer to production on Ubuntu 22.04.1 LTS, nginx, and laravel and maatwebsite on the same version, it doesn't work.
maatwebsite versions : * 3.1.46
I have checked this post but I don't have ShouldQueue in the implements
function processFile(... {
Log::debug('processPatMst1'); -> able to see in log
read file
$fileRec = File::findOrFail($fileId);
$fileFullPath = $fileRec->file_path;
Log::debug('processPatMst2', [$fileFullPath]); -> able to see in log
Excel::import(new ApacInstaPatientMasterImport, $fileFullPath);
Log::debug('processPatMst3', [$fileFullPath]); -> able to see in log
}
class ApacInstaPatientMasterImport implements ToModel, WithBatchInserts, WithUpserts, WithHeadingRow
{
use Importable;
public function model(array $row)
{
Log::debug($row); --\> not showing in log file
dd('testtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt'); --\> doesn't trigger\

Related

Lavel can't load classes

I installed someone's laravel project on my machine. Im getting an error that says my controller file can not load a class. However, no one else is experiencing the same issue. Here's the files related to my issues
app/Models/Menu.php
namespace App\Models;
use ...etc....
class Menu extends Model implements Sortable
{
}
class MenuPage extends Model
{
}
app/Http/Controller/AutomobileController.php
namespace App\Http\Controllers;
use App\Models\Menu;
use App\Models\MenuPage as MenuPage;
use ...etc...
class AutomobileController extends Controller
{
public function index(Request $request)
{
// Both these lines give Class 'App\Models\MenuPage' not found
$menu_items = MenuPage::where('menu_id', 6)->get()->toArray();
//$menu_items = \App\Models\MenuPage::where('menu_id', 6)->get()->toArray();
}
}
I comment that both lines where I tried to use MenuPage gives an App\Models\MenuPage not foudn error. I looked on my other colleague's computers and those same lines work for them.
I have not modified any other code since downloading this project.
Can anyone suggest why things break on my system but not others?
NOTES
I noticed that my colleagues are on PHP7.3 and Ubuntu 18.04, and I am on PHP7.4 and Ubuntu 20.04.

PHPUnit show errors but not show successful alert

I use Laravel 5.8 and phphunit version 7.5. When I run PHPUnit with error, show me error but when not has error show me only this line
PHPUnit 7.5.0 by Sebastian Bergmann and contributors.
My test class:
use Tests\TestCase;
class leadTest extends TestCase
{
public $Array= ['lead_name' => 'Jon','lead_family'=>'Doe'];
public function test_store()
{
$this->withoutExceptionHandling();
$this->post('leads', $this->Array());
$this->assertDatabaseHas('leads', $this->Array);
}
}
That is the reason of your error:
$this->withoutExceptionHandling();
Try without it.
Look also at class name it should be: LeadTest, and the file should be named LeadTest.php

JWTGenerateCommand::handle() does not exist

I am using Laravel 5.4 and JWT Auth Library for user authentication in API development. After installation while i am running php artisan jwt:generate then it throws me error of
Method Tymon\JWTAuth\Commands\JWTGenerateCommand::handle() does not exist
Any idea what i am missing ?
This error generally display when you install jwt package in laravel 5.5 version. then after you set service providers and run following command.
php artisan jwt:generate
then you seen this error message in terminal.
how to resolve it? simple follow this step
Step - 1 Re-install package
composer require tymon/jwt-auth:dev-develop --prefer-source
or the following is a new release package use laravel 6.X
composer require tymon/jwt-auth:1.0.*
in this developement version this errors fixed.
Step - 2 Set Service Provider
'providers' => [
....
Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class to
Tymon\JWTAuth\Providers\LaravelServiceProvider::class
],
Step - 3 Generate key
php artisan jwt:secret
i found this solution from here https://laravelcode.com/post/method-tymonjwtauthcommandsjwtgeneratecommandhandle-does-not-exist
Go to JWTGenerateCommand.php file located in vendor/tymon/src/Commands and paste this method
public function handle() { $this->fire(); }
It's never a great idea to change anything in the vendor folder but the there's two ways to deal with this ...
Generate a random string yourself and just change the value in the JWT config file.
Go to Tymon\JWTAuth\Commands\JWTGenerateCommand and change the fire method to handle.
go to given file path
vendor/tymon/jwt-auth/src/Commands/JWTGenerateCommand.php
change function name
public function fire() to public function handle()
run command:
php artisan jwt:generate
I'm publishing this answer because I have crash in this error more than one time.
The only solution I found that it works with Laravel 5.6 is the following:
Add "tymon/jwt-auth": "1.0.0-rc.1" to composer.json and run composer update
Open config/app.php and add the following:
config/app.php:
'providers' => [
/*
* JWT Service Provider...
*/
Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
],
'aliases' => [
'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class,
'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class,
],
Execute:
php artisan vendor:publish --provider="Tymon\JWTAuth\Providers\LaravelServiceProvider"
Finally, execute: php artisan jwt:secret
After all that, when I hit my endpoint for login I got the following exception:
Class Tymon\JWTAuth\Providers\JWT\NamshiAdapter does not exist
This was fixed by:
Open config/jwt.php and change the following:
config/jwt.php:
'jwt' => Tymon\JWTAuth\Providers\JWT\Namshi::class,
'auth' => Tymon\JWTAuth\Providers\Auth\Illuminate::class,
'storage' => Tymon\JWTAuth\Providers\Storage\Illuminate::class,
Finally, note that in order to work your User model should be defined as follows:
class User extends Authenticatable implements JWTSubject
{
...
public function getJWTIdentifier()
{
return $this->getKey();
}
public function getJWTCustomClaims()
{
return [];
}
...
}
I can advise one solution. Go to JWTGenerateCommand.php file located in vendor/tymon/src/Commands and paste this part of code public function handle() { $this->fire(); }
I know this is not an elegant solution, but it works. I hope this might help until official fix arrive.
see here for more info
Change fire() function to handle() in this path
vendor/tymon/jwt-auth/src/commands/JWTGenerateCommand.php
In the file path: /vendor/tymon/jwt-auth/src/Commands/JWTGenerateCommand.php
Add public function
public function handle()
{
$this->fire();
}

Laravel 5.1 throws ReflectionException after upgrade from 5.0

I have recently upgraded Laravel to version 5.1 from 5.0, but whenever I send an API response to the server, it throws an exception like the following:
ReflectionException in RouteDependencyResolverTrait.php line 57: Class App\Http\Requests\User\GetRequest does not exist
Before upgrading everything was working fine.
This is the autoload section of my composer.json file:
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Bloom\\" : "library/Bloom"
}
}
Could it be that I did something went wrong during the upgrade procedure?
This is how the GetRequest class is declared:
<?php namespace App\Http\Requests\User;
use App\User;
use App\Http\Requests\Request;
use Illuminate\Support\Facades\Auth;
/**
* Class GetRequest
* #package App\Http\Requests\User
*/
class GetRequest extends Request {
Update: I just reinstalled Laravel 5.1 and moved all the old files to the new installation but I still receive the same error.
Update 2: After running php composer dump-autoload -o I can notice that the file vendor/composer/autoload_classmap.php contains the class that Laravel is unable to find:
'App\\Http\\Requests\\User\\GetRequest' => $baseDir . '/app/Http/Requests/User/GetRequest.php',
Update 3: I tried also to create a new request using
php artisan make:request TestRequest
and then using the TestRequest in the UserController.php
/**
* #param GetRequest $request
* #return \Symfony\Component\HttpFoundation\Response
*/
public function get(TestRequest $request)
{
if(!$this->userRepository->getUser()) return $this->respondOK('User not found.');
$user = $this->userRepository->getUser();
return $this->respondOK('', (new UserTransformer())->transform($user->toArray()));
}
but I still receive the same error.
OK, I found the solution.
I noticed that if in GetRequest class I swap use App\Http\Requests\Request; with use Request; then the GetRequest class is found and the ReflectionException is not thrown anymore.
So the problem is not in the App\Http\Requests\User\GetRequest class but in the abstract class App\Http\Requests\Request.
After looking at the App\Http\Requests\Request class, to which I made changes, I decided to replace it with the dist version from Laravel and then I reapplied my changes.
Long story short: The problem was in App\Http\Requests\Request because I made changes to it and something changed with the update to Laravel 5.1.
I've got the same problem. Currently I found the solution as specify "use" in the controller that used new request class.
Set "use" in controller for right path to the request files:
use App\Http\Requests\Request;
use App\Http\Requests\YOUR_NEW_REQUEST_CLASSRequest;

Class 'Eloquent' not found when mocking in Laravel

I'm following through Jeffrey Way's Laravel Testing Decoded and I've hit an issue I can't seem to fix.
I'm actually work through this tutorial: http://net.tutsplus.com/tutorials/php/testing-laravel-controllers/ Which is an excerpt from his book.
Basically I have a test like so:
class PostsTest extends TestCase {
public function __construct()
{
$this->mock = Mockery::mock('Eloquent', 'Post');
}
And that like for mocking Eloquent and Post returns:
PHP Fatal error: Class 'Eloquent' not found
When I run phpunit. Incidentally if I use Jeffrey's Laravel Generators and just generate some scaffold e.g.
php artisan generate:scaffold post --fields="title:string, body:string"
And run phpunit I get same error. He's using the same:
$this->mock = Mockery::mock('Eloquent', 'Post');
To mock the classes. Does anyone have any suggestions on what the issue could be?
I've been working through the tutorial again from scratch and am still getting the same error. I've pushed it to a public repo so people can see: https://github.com/RyanHavoc/tdd-laravel
Just pull it down, run composer install/update and phpunit.
I found a solution to the issue.
//Causes the Class 'Eloquent' not found error
public function __construct()
{
$this->mock = Mockery::mock('Eloquent', 'Post');
}
//Setting the mocks in the setUp() method instead works
public function setUp()
{
parent::setUp();
$this->mock = Mockery::mock('Eloquent', 'Post');
}

Resources