NotFoundHttpException Laravel 4 - php

I have a problem with my app on the server.
When I access it through various links, it works. But, when I put the URL to the same site in my browser, I get a NotFoundHttpException. What I have detected in the message of the exception are the following problems:
REDIRECT_URL /app/public//login
REQUEST_URI /app/public//login
I do not understand why it adds two slashes (//) after public instead of one (/).
The code for my file route.php is:
Route::get('login', 'UserController#get_index');
And, the code for my Controller is:
public function get_index()
{
return View::make('admin.login');
}

I think changing the naming convention to the one laravel uses will fix this problem.
Do this in your routes:
Route::get('login', 'UserController#getIndex');
and this in the controller:
public function getIndex()
{
return View::make('admin.login');
}

Related

Unable to access laravel 5.5 API route using Postman software

My api.php route is
Route::get('/allposts','PostController#index');
Controller function is and working with web.php Route file
public function index()
{
$posts= Post::all();
return PostResource::collection($posts);
}
my Resource is toArray function is
public function toArray($request)
{
return parent::toArray($request);
}
Postman link using GET are
"queuetest.com/api/allposts"
"http://queuetest.com/api/allposts"
both are not working
and getting Result in both Post man and browser: Sorry the page your looking for could not be found
Do you get something other than the Sorry the page you're looking for could not be found message when you do var_dump('test');die(); in your index method as the first line.
Edit: try to remove then / before /allPosts
Another edit: check in your RouteServiceProvider if the mapApiRoutes prefix is set to 'api'
If you are using the default route configuration that comes out of the box, you should place your route in routes/api.php if you want to access it in the /api namespace. Right now, the route should be accessible from http://queuetest.com/allposts.
This behavior can be configured in App\Providers\RouteServiceProviders.php. If you have a modified route configuration, there are numerous things that could cause this behaviour, and it is impossible to locate the problem without seeing more code.

Laravel routing strange behavior

I have a single domain/subdomain project. In order to see the event by slug, I made this route:
Route::prefix('events')->namespace('Content\Controller')->group(function () {
Route::get('/', 'EventController#getIndex')->name('event.index');
Route::get('{slug}', 'EventController#getView')->name('event.show');
Route::get('{slug}/edit', 'EventController#getEdit')->name('event.edit');
Route::post('load-more-ajax/{region?}', 'EventController#postLoadMoreAjax');
Route::any('sorted-ajax/{region?}', 'EventController#anySortedAjax');
Route::get('category/{category_slug}/{subcategory_slug?}', 'EventController#getCategory');
});
After my page didn't load correctly, I did a dump in the controller:
public function getView($slug)
{
return $slug;
}
To get to the route I am using this URL: https://example.com/events/slug-example.
The problem is that the route is being hit as I see the response when I change it, but I am not getting the slug, instead I am getting Region object back.
If I do this:
public function getView($region, $slug)
{
return $slug;
}
Then I get the slug back. But I have no idea how is this possible, and how could I do it (I came as another dev on the existing project).
I tried commenting out all the middleware and it is still the same. How can I even make something fill the method if I didn't explicitly say it?
EDIT
I noticed there is binding going on in routes file:
Route::bind('region', function ($value) {
...
});
Now if I dd($value) I get the variable back. How is this value filled? From where could it be forwarded?
Looking quickly it should work, but maybe you was verifying other url.
Make sure you put:
Route::get('{slug}', 'EventController#getView')->name('event.show');
Route::get('{slug}/edit', 'EventController#getEdit')->name('event.edit');
routes at the end of routes you showed.
EDIT
If you think that's not the case and you don't have your routes cached you should run:
php artisan route:list
to verify your routes.
EDIT2
After explaining by OPs in comment, domain used for accessing site is:
{region}.example.com
So having $region in controller as 1st parameter is correct behaviour because of route model binding and other route parameters will be 2nd, 3rd and so on.
Instead of
Route::prefix('events')->namespace('Content\Controller')->group(function () {
Route::get('/', 'EventController#getIndex')->name('event.index');
Route::get('{slug}', 'EventController#getView')->name('event.show');
Route::get('{slug}/edit', 'EventController#getEdit')->name('event.edit');
Route::post('load-more-ajax/{region?}', 'EventController#postLoadMoreAjax');
Route::any('sorted-ajax/{region?}', 'EventController#anySortedAjax');
Route::get('category/{category_slug}/{subcategory_slug?}', 'EventController#getCategory');
});
try
Route::prefix('events')->namespace('Content\Controller')->group(function () {
Route::get('/', 'EventController#getIndex')->name('event.index');
Route::post('load-more-ajax/{region?}', 'EventController#postLoadMoreAjax');
Route::any('sorted-ajax/{region?}', 'EventController#anySortedAjax');
Route::get('category/{category_slug}/{subcategory_slug?}', 'EventController#getCategory');
Route::get('{slug}', 'EventController#getView')->name('event.show');
Route::get('{slug}/edit', 'EventController#getEdit')->name('event.edit');
});

Laravel: 404 error instead of usual exceptions

I have two routes.
The second stopped working so I added the first one (which works perfectly).
Routes file
Route::get('/cms/index', function () {
return view('cms-templates/index');
});
Route::get('/cms', function () {
return view('cms-templates/index');
// tried return redirect('/cms/index')
// tried return hello world
});
The problem is it doesn't matter what I try to return in the second route, it always throws a page with error 404 Not Found ------ nginx/ver instead of the NotFoundHttpException or InvalidArgumentException that usually come when not finding route or file (which still happens with which other route)
Try this:
Route::get('/cms/index', function () {
return view('cms-templates.index'); //cms-templates should be a folder with a blade called index
});
Anyway you're trying to return the same view for two differents Routes?.
Also you can call to a controller and her function using this:
Route::get('/cms/index','namecontroller#function');
Feel free to ask if have any doubt.

Routing for subpages on production server not works

I am working on Lunux. My created locally webpage works good but after I sent on production server only mainpage is routing, subpages not.
For example address https://demo.tiltkomp.pl/ is working but https://demo.tiltkomp.pl/about return "NetworkError: 404 Not Found - https://demo.tiltkomp.pl/about"
my web.php:
Route::get('/', 'PagesController#index');
Route::get('about', 'PagesController#about');
in PagesController.php:
class PagesController extends Controller
{
public function index(){
return view('pages.index');
}
public function about(){
return view('pages.about');
}
}
Where do I make mistake ?
Please check this answer https://stackoverflow.com/a/28031497/5130217
So in case you using Apache you need to check mod_rewrite enabled and Override allowed in apache2.conf file.

laravel giving incomprehensible(to me) http exception

I use laravel 4 and am not able to show a component :
this is a line from my routes
Route::resource('/', 'PostsController');
and this is my show function from PostsController.php
public function show($id) {
return "HI";
}
And This is the line that links to the function from my view
<h1>{{$post['title']}}</h1>
And It properly links to localhost:8000/show/1
But I'm amazingly getting a Not found HTTP exception from laravel.
How do I get this to work?
So the answer is that #NihalSahu is wrong (me) and that resourceful routing doesn't work like that it would be infinitely better so as to set the router to host/{id}

Categories