How to write rule in laravel version 5+ - laravel-5

I am using laravel 5+ and I wrote a rule in web.php file
Route::get('cms/about-us', 'CmsController#index');
to access the index method on CmsController. But this rule does not work and gives error
Missing argument 1 for App\Http\Controllers\CmsController::index()

Related

i cant run php artisan make:controller FallbackController

It gives me this error
ArgumentCountError
Too few arguments to function Illuminate\Routing\Router::fallback(), 0 passed in C:\xampp\htdocs\gmvcc\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 338 and exactly 1 expected
im using laravel 9.
I suggest a combination of suggested places to check, based on the provided error response you pasted above:
First, check your web.php or api.php in routes folder and verify if you have unexpected additional parameters. For example, Route::post('/foo/{hello}/bar/{world}', [FallbackController::class, 'testFunction']); and we see that you'll next have to declared $hello and $world shortly.
Next, does your function looks like this? (following the example from #1) Such as public function testFunction($hello, $world, Request $request).
Third, based on the HTTP method used, and for the route defined using FallbackController, were you able to simplify it to test your HTTP method with the route again? For this, I still assume it is a route in api.php correct?
Lastly, if any of above fails to help, I recommend implementing a simple route to test with (GET or POST) first. This will help you trace back what you missed.
Using Docker (and a fresh Laravel 9) to help fill in other clues, like incorrect php or composer version and more - using a template like this might help, https://github.com/k90mirzaei/laravel9-docker.
Please note, I am answering based on the provided error first. Hope my checklist above helps.

Find exact value of VUE_APP_API_BASE_URL for laravel project

I have a laravel + Vue.js project template downloaded from Creative Tim. Its login and register is not proceeding, giving the catch error whereas in the template demo its working fine. I think so the instructions said to write the VUE_APP_API_BASE_URL in Vue .env file and I didn't wrote it correct. Can anyone pls tell me how can I locate the exact address and what syntax it would be?
Since you are using vue with laravel, you need to prefix MIX_ before the variable. Eg:
MIX_VUE_APP_API_BASE_URL=http://localhost:8000
Here is the reference: https://laravel.com/docs/8.x/mix#environment-variables

Routes stopped working after updating Laravel. All

I know that the route system in Laravel 5 and later is different, but I was not ready for that. Upgraded to Laravel 7 and all routes stopped working for me.
The problem is in my views, in my project the route looks like this:
href="{{route('profile', ['id' => Auth::user()->nickname])}}"
And an error is returned to me that I did not pass an argument, although I did pass an argument.
Everything starts working if I fix it like this:
href="{{route('profile', Auth::user()->nickname)}}"
How do I fix this problem? It is very difficult to rewrite all the routes by hand, since there are thousands of them and most of the routes are of the form/{param1}/{param2}/...
In Laravel 7 it should also work with the key. I think something else is the problem, did u follow the Laravel upgrade guides?

All test failing after update from laravel 7 to laravel 8

After update from laravel 7 to version 8 all test failing with same error:
Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such index: IDX_426EF39216FE72E1 (SQL: DROP INDEX IDX_426EF39216FE72E1)
I am also using legacy-factories package for old factories approach
I finally solve this problem using laravel shift because there is lot of things to be done after upgrade and list in my case is huge because I use custom namespace and I must handle that in AppServiceProvider. Shift also refactor all of mine factories that I have

Named Routes Not Recognised in Method When Called From PHPUnit Test

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

Resources