Route [people.comments] not defined - laravel

help me to find the problem, the laravel project gives error before loading
Route [people.comments] not defined
I copied and pasted the route name, copied and pasted the working routes, but no, it doesn't work.
Route::post('/people/comments', 'Admin\PeopleController#comments')->name('people.comments');
And It worked when I changed method POST to GET
Route::get('/people/comments', 'Admin\PeopleController#comments')->name('people.comments');
I am using this route inside a JAVASCRIPT
let url = '{{ route("people.comments") }}';
Now the question is why it is worked when I changed post to get? and why it is not working in POST ?
(I don't have routes with same name)
THANKS

This was my error two posts with same address and same method
Route::post('/people/comments', 'Admin\PeopleController#comments')->name('people.comments');
Route::post('/people/comments', 'Admin\PeopleController#blogs')->name('people.blogs');

Related

How to stop the GET method is not supported for this route from showing?

I have a working Laravel project with loads of different routes.
I'm currently testing it and one of my tests was to check if a user were to use a delete or post route from the URL. I didn't know what the application would do honestly and it outputted the typical:
The GET method is not supported for this route. Supported methods: DELETE
which I have seen a million times. Is there a way to stop this error from coming up and instead output an error screen or simply redirect to a different view?
The error message:
The GET method is not supported for this route. Supported methods: DELETE.
should only appear when your Laravel site has APP_DEBUG set to true (in the .env file).
When APP_DEBUG is set to false as it should always be in on a live site, then the user will be shown a 404 error page instead.
You can easily test this by adding the following code to your routes file:
Route::delete('test', function() {
return 'You should never see this text when viewing url via a GET request';
});
May be u didn't noticed but ur form tag method attribute and route definition is different

How to get previous route name in Laravel 5.8

I'm trying to get previous route name in Laravel 5.8. This answer (https://stackoverflow.com/a/40690569/16735772) works perfectly when I use Virtual Host but in direct url like (125.125.125.125/project_folder/public) does not because NotFoundHttpException is thrown.
With Virtual Host, $request->create(url()->previous()) creates a request with pathInfo and requestUri using relative url, for example, my_profile/2 but without Virtual Host, those attributes have different value, like project_folder/public/my_profile/2.
I don't need to redirect back, just know previous route name to check. For example:
if ($previous_route == 'show_name') {
//do something
}
Any help will be appreciated.
Try this code to get the previous route name:
Route::getRoutes()->match(
Request::create(URL::previous())
)->getName();
You can make a helper or blade directive to make it easier to access.

Laravel not picking up the correct route

I am developing an application using Laravel 8.x. I have an api.php file that I am using. It was all working fine for the last 5 months. Today I added a new route to the api.php file and that route is not getting picked up by the Laravel. I have the following items in the api.php file
//Products
Route::get('/products/{currency_id?}/{type?}/{eventtype?}', [Controllers\ProductsController::class, 'getproduct2']);
Route::get('/products/search/{query}/{itemtype?}/{itemcategory?}', [Controllers\ProductsController::class, 'findproduct']); //getproduct
Route::post('/products/findproductbyid/{product_id}', [Controllers\ProductsController::class, 'getproduct']);
Route::post('/products/create', [Controllers\ProductsController::class, 'setproduct']);
Route::post('/products/update', [Controllers\ProductsController::class, 'putproduct']);
And it shows up the URL list also
but when I access it (findproductbyid) in the browser it is not getting picked up. it shows the results of /products/{currency_id}/{type}/{eventtype}
Please tell me to know why is it so? I tried clearing Laravel cache, etc.
Thanks in advance
UPDATE: I tried changing the GET to POST, but it seems it is not getting updated to POST
You don't define url parameters with $, here you done {$product_id}
Change it to the following.
Route::get('/products/findbyproductid/{product_id}', [...]);
Rearrange the routes like this and try it out
Route::post('/products/findproductbyid/{product_id}', [Controllers\ProductsController::class, 'getproduct']);
Route::get('/products/search/{query}/{itemtype?}/{itemcategory?}', [Controllers\ProductsController::class, 'findproduct']); //getproduct
Route::get('/products/{currency_id?}/{type?}/{eventtype?}', [Controllers\ProductsController::class, 'getproduct2']);

How the Url path from file path name to another name in laravel

Fins below the route code.
Route::get('clientlayout.main.index','InvoiceTicketController#show');
Route::get('clientlayout.main.mydomains','InvoiceTicketController#set');
When I run these routes I'm getting the url as
http://localhost:8000/clientlayout.main.index and
http://localhost:8000/clientlayout.main.mydomains.
I want my Url to be changed as follows: http://localhost:8000/index and http://localhost:8000/mydomains.
Suggest me a solution for changing the route to rectify this issue.
Route::get('/index','InvoiceTicketController#show');
Route::get('/mydomains','InvoiceTicketController#set');
for named routes you can use like this way
Route::get('/index','InvoiceTicketController#show')->name('clientlayout.main.index');
for more details follow
https://laravel.com/docs/5.6/routing#named-routes
You should try the route.
Route::get('/clientlayout/main/index','InvoiceTicketController#show');
Route::get('/clientlayout/main/mydomains','InvoiceTicketController#set');
Url is making
http://localhost:8000/clientlayout/main/index
http://localhost:8000/clientlayout/main/mydomains
Or You Should try
Route::get('/index','InvoiceTicketController#show');
Route::get('/mydomains','InvoiceTicketController#set');
Then Url is making
http://localhost:8000/index
http://localhost:8000/mydomains

MethodNotAllowedHttpException with lucadegasperi/oauth2-server-laravel's included AccessTokenFlow POST route

This is my first Laravel project I'm on, and it has been a ton of fun so far.
I'm setting up an OAuth2 server. I have copied the code posted here in to my routes file.
Via this block of code...
Route::post('oauth/access_token', function()
{
return AuthorizationServer::performAccessTokenFlow();
});
I have tried doing http://local.server.com/oauth/access_token and a "MethodNotAllowedHttpException" error.
If there is any other information I could provide that would help you help me, please tell me!
Cheers
If you are typing http://local.server.com/oauth/access_token into the browser URL bar, then you are sending the request:
GET oauth/access_token
However, your route handles a POST request, and since there is no GET route defined, Laravel is responding with MethodNotAllowedHttpException
In order to properly test your route, you will need to send a POST request.

Resources