When calling a Method from another class that contains a named route the route is not recognised
This PHPUnit test is to check that functionality of the system still meets requirements as the system is complicated.
Testing is run from a local environment (homestead vagrant)
I am calling the method form here:
$orderLines = (new EDIProcessController())->getChanges($order['ediOrder'], $order['partnerId']);
And the named route that is causing the issue:
$orderLine->item_url = route('warehouse.products.view', $itemDetails->id);
I get the following error:
InvalidArgumentException: Route [warehouse.products.view] not defined.
/home/vagrant/vr/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:305
/home/vagrant/vr/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:790
/home/vagrant/vr/app/Http/Controllers/Warehouse/EDI/SPS/EDIProcessController.php:1575
/home/vagrant/vr/vendor/laravel/framework/src/Illuminate/Support/Collection.php:861
/home/vagrant/vr/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Collection.php:139
/home/vagrant/vr/app/Http/Controllers/Warehouse/EDI/SPS/EDIProcessController.php:1746
Route as defined in the routes file:
Route::get('/view/{id}', 'Warehouse\ProductController#viewProduct')->name('warehouse.products.view');
This route works fine when called from within Laravel app but will not work within PHPUnit test
Finally found the answer
There is a issue with using require_once for sub route files that is caused due to multiple instances of route files not all getting the required files.
Here is a dicussion here that I eventually found
switching the require_once to require at all levels of our route files solves the issue
Related
So I have installed the webfox/laravel-xero-oauth2 extension via composer and configured my xeroController and the webhook controller as defined in the docs for this (https://github.com/webfox/laravel-xero-oauth2) the connection works and I am able to show that Xero is connected.
I then started work on submitting an invoice and as per the last part of the docs i opened the link (https://github.com/XeroAPI/xero-php-oauth2-app/blob/master/example.php). To facilitate this I used a working non Laravel invoice app from inhouse and progressed well but when i run this on an environment where I can connect to Xero (I am using a staging site here rather than configuring ngrok or some such thing) and i get the error above. The code where this error has happened is as follows:
$xero = resolve(\XeroAPI\XeroPHP\Api\AccountingApi::class);
$xeroTenantId = $xeroCredentials->getTenantId();
$type = XeroAPI\XeroPHP\Models\Accounting\Invoice::TYPE_ACCREC;
$client = $this->client();
Now I searched in the api and found the reference to this in my projects vendor folder vendor/xeroapi/xero-php-oauth2/lib/Models/Accounting/Invoice.php on line 361 it is shown const TYPE_ACCREC = 'ACCREC'; So It seems I'm not referencing this correctly? On the inhouse this is being found with no issue (although the folder structure is not the same as in Laravel so not sure how helpful this is but it is in it's vendor folder and following the exact same path).
What have I missed? I use phpStorm and it is saying that this is an undefined namespace. I have also this message on the line where we connect to Xero but a dd has verified that this works, the error is shown after this line too. I have ran composer dump-autoload and I have also cleared out all caches to rule this out but same error.
I made a project and it was working absolutely fine on localhost. But when I made it online then it is showing following error in networking tab of browser while I am trying to login to my project.
{message: "Class 'App\Models\user' not found", exception: "Error",…}
All codes are same, files and directory structure are same. .env file has been updated. But still getting this error.
Note: During search I found this post (and many other articles on different sites) but it is not showing any working solution.
Laravel 7.11.0 Class '\App\Models\User' not found
Laravel uses composer to load classes and configures the autoloader as a PSR-4 autoloader. The PSR-4 spec states that
All class names MUST be referenced in a case-sensitive fashion.
and
The terminating class name corresponds to a file name ending in .php. The file name MUST match the case of the terminating class name.
In the default configuration Laravel specifies that the root namespace is App and is situated in the app folder (ironically Laravel did not make this case sensitive but composer allows this for the root namespace). So for example if you want to load App\Models\user then composer will look for the file app/Models/user.php. Note that in the default Laravel installation the file is actually named User.php.
Now I do think there is a bug in the composer autoloader or a limitation in Windows in that it only checks if the file exists and doesn't check if the file also matches the case. Since Windows is a case insensitive filesystem when composer asks it if app/Models/user.php exists then Windows will respond that it does, even if the casing is wrong. However Linux is a case sensitive filesystem therefore if you ask a Linux OS if app/Models/user.php exists it will respond that it does not. This will create a discrepancy between Windows and Linux if you're not careful.
I'm not sure if this is a composer bug or configuration or caching issue but the best course of action is to always match the case of your file names in your class names and in the way you refer to them.
Laravel project not working in cpanel faced error Target class [App\Http\Controllers\fileController] does not exist. But project completely running locally without no error.
Error image
route.php
AuthorController.php
Please help me out. Advanced thanks.
The error appears to be straight foward --You are appear to be missing the definition of the FileController and somewhere within your routes files you are calling the controller.
Route::resource('files', 'FilesController');
To fix an issue like this, make sure you had not renamed any of your controllers to a different name or you could simply run artisan
php artisan make:controller FilesController -r
to get past this issue. Also, try and stick to resourceful controllers as the verbs such as "PUT", "PATCH", "GET" etc. make decrease the readability of your code. If you don't with to expose all the method in a resourceful controller within your route you could have something like
Route::resource('files', 'FilesController')->except('index','show');
and so forth.
Hello i am try to include a PHP class (Payroll.php) found on another server since it requires the main module that has been written in pure PHP in my Laravel sub-module. I was given the url to the php file on the other server and have been tasked with using it to fetch the employees from the main module to be used in my module. Almost all the solutions i found on the internet where for cases where the laravel code and the php code exist on the same server. I tried several approaches such as including the file directly (which is giving me class not found) and using things like guzzle and so on (which failed since it is not an API). Any help would be appreciated.
I tried accessing a module controller in the $route['default_controller'] setting in routes.php but I'm getting the following error:
I have been getting this error a lot lately and don't understand entirely what exactly it means. Does anybody know what I'm doing wrong? Below is my routes statement:
$route['default_controller'] = 'contractors/routes/mainDisplay';
The error is about the language file not the routing. Apparently you have loaded a lang file in you module but pyrocms can't find the file. make sure that the language file is placed correctly and check the filename which should be contractors_lang.php.
do you have this file?
../modules/contractors/language/english/contractors_lang.php
if not, make one.