i cant run php artisan make:controller FallbackController - laravel

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.

Related

Laravel 8 project is giving serialize error

When I use the php artisan serve command, the project gives the following error.
Laravel\SerializableClosure\Exceptions\InvalidSignatureException Your
serialized closure might have been modified or it's unsafe to be
unserialized.
What is the reason for that? How can I solve this?
I also had similar type of issue like this as shown in attached image and I was able to resolve that by referring this article. check this article clearly

Laravel - Tinker breakpoint in controller

New to Lavarel.
I am trying to debug a controller's method in Laravel, to do so I'm using Tinker (which is based on Psysh).
I added both of these versions to the breakpoint inside the method signup of my MySuperController:
extract(\Psy\Shell::debug(get_defined_vars()));
eval(\Psy\sh());
I've run php artisan tinker and done the following in the console:
$controller = app()->make('\App\Http\Controllers\Api\V1\MySuperController');
app()->call([$controller, 'signup'], ["param"=>"value"]);
When executing that, Tinker responds with: Illuminate\Validation\ValidationException with message 'The given data was invalid.'
But I never see the code stop on the breakpoint. Did I assume wrongly that I could debug step by step with Tinker?
This answer was based off of user #lagbox's comment. I asked them to make it an answer so I could choose it, but it's been 4 months, so I'm creating it myself so others can quickly see the question has been answered:
User #lagbox mentioned in a comment:
are you using a form request to validate? if so they are resolved and validated before your controller method is called
The comment was spot on. Tmethod was using a custom request class, which extended from api/application/vendor/laravel/framework/src/Illuminate/Foundation/Http/FormRequest.php . I added the eval() within that class and it finally got to the breakpoint.

CakePHP 4 - view helper - error reading session values

I am still fairly new with CakePHP and leaning with version 4. I can read PHP session values in a template index.php file with below. I think that is wrong way to do but I tested anyway.
$userrole_id = $this->request->getSession()->read('Auth.userrole_id');
And now I am trying to read session values in View Helper so that I can use same code in many different places. But above code throws an error with "Call to a member function getSession() on null". And as you can see in the above one line code, I have Authentication set up and that is working fine. And I have helper loaded in AppView.php, and that is loaded fine, too.
I am pretty sure I am missing basic stuff but I cannot figure it out. Any suggestions would be appreciated.
I found a solution in the official documentation, and I needed to do like below:
$this->getView()->getRequest()->getSession()->read('Auth.userrole_id');

Where does the output of dd() and dump() get written when developing Laravel in VS Code?

I'm developing a Laravel 8.x app in the current version of VS Code. I have a dump() statement in a Controller that I've written so that I can determine precisely what's in the $request that is being handled because I suspect that my date isn't exactly what I think it is. I've added this to the store() method: $request->dump() and I'm pretty sure it has executed but I can't find the output from the dump() function anywhere. I've got Debugbar installed and it does not show the dump() output. Ditto for any window of the browser like the console, inspector, etc. I've looked in the laravel.log but it's not there either. I've checked each of my terminal windows - the ones dedicated to php artisan serve and npm run watch and the one I use for all other commands but I can't find anything there. I'm out of ideas on where to look.
If the Laravel docs tell you where to find the output, I missed it; they describe what dump() and dd() do but I can't find where they describe where the output is written.
I'm pretty new to Laravel and I'm working alone so I have no work colleagues to ask. Could someone kindly tell me where to find the output of dump() so that I can debug this program?
None of the comments pointed me to precisely where I eventually found the dd() output so I'm posting it here for the sake of any future person who has the same issue. I finally found it in the browser, in the console tab (I'm using Firefox) and within the Response to the Axios statement that tried to write the new record to the database. Here's a picture:
I had assumed that the information wouldn't require me to drill down as far as I did; I thought it would be as visible as normal console.log() output.
I'm very grateful to those who replied to my question; you finally got me looking in the exact right place. I've never used dd() or dump() before, even in vanilla PHP, so I really had no idea where the output got written.

How to get the primary route, if it doesn't exist and we are being sent to 404 page

So basically I am trying to debug my routes, because they are not working as intended, but when using the profiler, I can see the URI string, which is basically the second part of URL in the browser address bar and CLASS/METHOD which are always of the 404 page that I am being redirected to. So how can I get the primary routes Class, Method and arguments/parameters that were attempted to run before being sent to 404?
E.g.
$route['en/catalog/(.+)/(.+)'] = "ccatalog/index/$1/$2";
something's gone wrong and I get redirected to the 404, but I want to see which class (most likely "ccatalog" here), which method (hopefully "index") and arguments ($1, $2).
Thank you in advance to anyone who could help me with my problem!
I don't see a reason for your route to not work.
Check by directly opening your_path/ccatalog/index/whatever/whatever in the browser.
If it gives you a 404, it means the problem is with your controller, maybe the controller or function naming.
If it is working fine, then you may be able to use a pre_system hook to figure out the parameter values.
You may also consider hacking around with Routing files in the core(making sure you change them back), to figure out what the real issue is.
Actually, this was done really easy:
$this->uri->rsegment(1);

Resources