404 in Routes.php with laravel 5 - laravel

I have a route that I have recently change to:
Route::get('/tournaments/{{tournamentId}}/invite/{token}', 'InviteController#register');
When I try to access it with
http://laravel.dev:8000/tournaments/1/invite/ad5a5sd
I get a 404...
All my others routes work fine...
Any idea what could be the problem??

It's a small error (easy to overlook), but you shouldn't be using double curly braces. {{tournamentId}} should be {tournamentId} so the route should be:
Route::get('/tournaments/{tournamentId}/invite/{token}', 'InviteController#register');

Related

Laravel Route gives Object not found error

So i had a route to create a post that was like http://127.0.0.1:8000/posts/create and now I am trying to delete the word create completely and have my route as http://127.0.0.1:8000/posts/ the problem is when i put nothing after the (/) I get Object not found Error, but when i put anything even one letter after the (/) it works.
Is not it allowed for a POST method to be used where its url ends with a slash? I'm confused
Ok, that was silly, the problem was that i'm adding a / at the end of the route while it should be /posts and that is it, no / after posts

Sorry, the page you are looking for could not be found without showing any error : Laravel 5.5

Newly installed Laravel 5.5 showing Sorry, the page you are looking for could not be found. without any error . Please see the screenshot :
I think its not even looks into routes file, this is my routes.php and htaccess
What will be the reason for this ?
All your WEB routes will be located in the file:
routes\web.php
Register your routes there.
Order
Pay attention to routes order, it's really important (fooled me so many times to be honest).
Because Laravel goes through list of routes top to bottom until it finds the first match, as a rule of thumb, try to define routes with no parametres first then routes with parameters in your route file (web/api).
Example: (based on Radical's answer)
Route::get('/blog/{id}', 'BlogController#show');
Route::get('/blog/comments', 'BlogController#comments');
In this case, Route::get('/blog/{id}', 'BlogController#show'); comes first so it would be selected. Even when what you really want is Route::get('/blog/comments', 'BlogController#comments');
My two cents :)
I ran into this issue when findOrFail method failed in the Controller method.
Ensure that your register.blade.php is in the resources/views directory and remove the trailing slash from the URL you are assigning to this view.
Sometimes the error messages in the storage/logs/laravel.log log file (if you have the default configuration) can help as well.
There are a lot of reasons why this won't work
Probably the route was written well eg: Route::get('/boost/{type}/{{type_id}}', ['uses' => 'RequestController#getBoosted', 'as'=>'boosts/{{type}}/{{type_id}}']);
when it is meant to be like this: Route::get('/boost/{type}/{type_id}', ['uses' => 'RequestController#getBoosted', 'as'=>'boosts/{type}/{type_id}']);
Looking at the two above code the second route is correct because of the curly brackets are one instead of two
Probably you will be needing to clear your cache which happens at rare occasions
Probably the developer in question did not put the links properly at there controllers Return view('site.block')
you must make sure that the page that is referenced is at the correct location
I think you can use this commands:
php artisan config:cache
php artisan view:clear
these commands use and I hope your error solve

Laravel returning a leading \n character on responses

Every response from my Laravel application seems to be getting prepend with a \n character, even when all I return is a number.
It feels like I have to have introduced this as a bug, but I can't find anywhere where I might have done that. I see I have some other applications I've built in Laravel that have this as well (but others that don't) so after pulling my hair out I thought I'd check and see if this something others have experienced.
The issue is that I'm trying to return an ID and use it but it has this leading character. I could strip it client side, but would rather fix the root issue.
ETA:
This route:
Route::get('/test', function(){
return 'hello world';
});
Produces this response:
It's not an issue for HTML of course, but when I try to assign it as an id, I'm getting "\n 234".
First of all PHEWW! this is a bad issue to end up with.
This can happen when any of your files starting from index.php of public folder to the controller which throws the response. Any where if at all there is a <?php
?> with a new line in between
or
any file involved in route request and response starting with <?php is on any other line than line no.1
Check your
public/index.php
bootstrap/app.php
config/app.php
any other files under config folder
routes/web.php or routes/api.php
app/Http/Controllers/YourController.php
I feel checking these must fix your issue. if not comment below lets discuss!
I ran into the same issue and fixed it with phpStorm's global regex search:
[\s\S]\<\?php
In the end I had a new line in the index.php before <?php like mentioned in the other comments
i was getting the same issue and used the following command to see what is in the buffer before returning any data
dd(ob_get_contents());
it turned out that i have several "\n" in the (routes.php) or in the routes files in case you use multiple files
If you're using Laravel as an API, I would recommend using the JSON response function:
return response()->json([
'id' => 234
]);
This should alleviate the leading line-break issue.
As for why you're experiencing it currently, it might have to do with your request headers. In the past, I've had to add 'Accept' => 'application/json' to my request headers in order to ensure Laravel knows I always want JSON back.
It happened to me too, finally I found it in public/index.php that there was a line of test code at the end of the file, I forgot to delete it. After I deleted it, all thing is good. But it is still very strange that before I deleted it, the extra wording didn’t show up locally but only on the live server.
I've had the same problem and fixed it by clearing the output buffer before the return in the controller.
ob_get_clean();
return response($data)->header('Content-Type','text/xml');
I have solved it by going through the official php documentation: https://www.php.net/manual/en/function.ob-get-clean.php
I hope it helps you

Laravel 4 - Duplicate Url

I am having a problem with the confide package for user authentification.
My problem is that when I login, I am redirected to the login page which throws an notFoundHttpException because the url I am redirected to is duplicated... looks like this:
http://www.mypage.dev/http://www.mypage.dev
My virtual host is set up like this here
https://github.com/daylerees/laravel-website-configs/blob/master/apache.conf
What is making this happen?
---EDIT---
Gathering more experience...
It seems that this occurs when the following redirect is used:
return Redirect::action('Controller#action')
If I use:
return Redirect::to('/action')
everything is just fine.
My route look like this:
Route::get('/action', 'Controller#action');
Change your Route to
Route::get('action', 'Controller#action');
Your current route's definition appends /action to the end of the current URL.
Because of the underscore, the url http://newsletters_app.dev is invalid according to filter_var($url, FILTER_VALIDATE_URL). Because of this, HTML::link() is generating a duplicate base. Solution is to simply remove the underscore from the URL.

Remove controller name from codeigniter 2 url path

I am having trouble removing the controller name from my url path on my localhost.
i have this url - localhost:8888/localhost/site_name/
i have been able to remove index.php from the url using my htaccess similar to http://codeigniter.com/wiki/mod_rewrite so that:
localhost:8888/localhost/site_name/index.php/controller_name
is now:
localhost:8888/localhost/site_name/controller_name/
but i can't remove the controller name from the path so that:
localhost:8888/localhost/site_name/controller_name/function_name/
becomes:
localhost:8888/localhost/site_name/function_name/
I am using only one controller, and i have added:
$route['^(function_name1|function_name2|function_name3)(/:any)?$'] = 'controller_name/$0';
$route['^(?!ezstore|ezsell|login).*'] = "home/$0"; /*similar variation i tried*/
and other variations to my routes file but it does not have any effect. i also tried using the _remap function but that does not help in this case.
Any help will be appreciated! Thanks
You can use a wildcard route,
$route['(:any)'] = "controller_name/$1";
Then when if you go to http://localhost/function_one/param1
it will call the controller controller_name the function function_once and pass param1 as the first parameter.
nb: I must point out, using only one controller for an entire site does raise warning bells for me, you may want to get your code design checked out, but that's just me.

Resources