404 error laravel 4 routing - php

I am having troubles getting laravel to find a page when I route to it. My route is setup and being recognized as when I create link using URL::route('account-create') laravel will successfully parse that into '/account/create' as to where I want the link to go to. But upon clicking it I get a 404 error.
My route
Route::get('/account/create', array(
'as' => 'account-create',
'uses' => 'AccountController#getCreate'
));
My controller
class AccountController extends BaseController {
// view the create user form
public function getCreate()
{
//return View::make('account.create');
}
}
The create.blade.php is created and put inside an account folder under app/views. commenting or uncommenting makes no difference. The 404 remains.
I have also tried:
Route::get('/account/create', function()
{
return 'Hello World';
});
in my routes.php still the 404 remains
Is there some configuration I am missing?

After looking around some more I discovered I needed to enable rewrite_module on apache. Makes perfect sense really, how can laravel make clean urls if it cant rewrite the url. I knew it was going to be something simple to fix.
Thanks a lot for your replys

Does navigating to index.php/account/create work? If so, it is probably an error in your root-level .htaccess file, or in your VirtualHost settings in httpd.conf on your server. Post the contents of .htaccess from app/public.

Related

Laravel route exist but unable to view page

I have been invited to collaborate on a laravel 7 project and I have been able to set up the project locally on a windows 10 system using wamp server. While reviewing the project, I noticed the plan is to use subdomain routing. I am currently tasked with setting up the blade templates and I want to test the route but I can't get the route to work correctly even though the routes exist. This is what the routes look like
When i try viewing the page for realestate by calling the url like this realestate.localhost:8000 I get the connection error below
The route is inside routes/realestate.php folder and its using a closure
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return 'Realestate Routes';
});
What is the right way to call the route in my local enviroment on windows?
I'm not sure if your environment is different from mine, but make sure you're accessing via http:// and not https://
I just saw your Route code - it's been a long day, sorry :P
Try reading up on Subdomain routing here.
Your Route should look like this:
Route::domain('realestate.localhost')->group(function () {
Route::get('/', function () {
return 'Hello, world!'
});
// all other routes for realestate.localhost go in here
});
You need to edit your hosts and add redirect to localhost from your subdomain. see https://stackoverflow.com/a/56921347/11775360

Laravel App - Admin Route ONLY '/admin' will always return a 404 error | '/admins' or anything else works

So if you go here you will see the EXACT SAME ISSUE word for word that i'm having...
Basically I have the admin route set like this:
Route::get('/admin', function () {
return view('admin.app');
});
Simple enough right? It always returns this error here:
Not Found
The requested URL /admin/ was not found on this server.
If i change the route to /admins (plural) or really anything else, even /test the route displays properly.
I DID have an admin folder inside my public folder, but I have since deleted the admin folder and now the problem is still persisting. I don't really understand why. I'm running on a Laravel/Homestead environment. Basic LEMP stack. Nothing special.
Edit: When i type in mysite.dev:8000/admin it directs me automatically to mysite.dev/admin (Notice there is no port) So, now i'm really even more confused. :/
Edit 2: Changed the route to admin/dashboard works just fine. Could it be possible that Laravel has defined the /admin route as a 'reserved route' or something (similar to reserved keywords in any programming language) to where it won't ever display anything? Is that even a thing?
Route::get('admin/dashboard', function () {
return view('admin.app');
});
Any ideas?
delete or rename admin folder in public and run
php artisan cache:clear
I think you have admin name folder in your public directory if you remove that it will work enter link description here

Can't route properly in Laravel

I am very new to laravel and I simply don't get how to route properly, am completely lost. The problem is I can only route a view to localhost/public. For example I can't route a view to "localhost/public/something". Am not even sure my urls are correct. If i leave "something.php" empty nothing will show, but if i add some html it shows only the html no views. Am sure am doing it all wrong. So how does one route a view to a page other than "public/".
The routing for index is
Route::get('/', function(){
return View::make('welcome');
});
works okay.
Now how can I achieve the same if do
Route::get('something', function(){
return View::make('welcome');
});
or
Route::get('/something', function(){
return View::make('welcome');
});
So i finally got it to work after so many hours. I deleted my laravel installation and did a new one and the problem is gone. Thanks.
There's nothing wrong with your code but might be for .htaccess
Please try accessing the route via following URL
http://localhost/public/index.php?/something
if it's working, you need to use the alternative .htaccess file provided on Laravel website or see if mod_rewrite is loaded on your Apache.

Laravel NotFoundHttpException (RouteCollection->match)

I am new to Laravel and was following a tutorial (https://www.youtube.com/watch?v=Zz_R73eW3OU&list=PL09BB956FCFB5C5FD). I have just installed the latest version of Laravel and am going through the beginning stages of the tutorial. So far (installation, creating a migration) I was doing ok, but now I am stuck at the point of creating new routes.
I have created a controller in app/controllers:
<?php
class Slots_Controller extends Base_Controller{
public $restful = true;
public function get_index(){
return View::make( 'slots.index' );
}
}
As well as a very minimalist view in the file app/views/slots/index.php
<h1>Slots</h1>
My app/routes file looks like this :
Route::get('/', function()
{
return View::make('hello');
});
Route::get( '/public/slots', array(
'uses' => 'slots#index'
) );
I've searched a number of things on the web and here is how far I have come :
- i know ideally only the public dir should be in the htdocs, i will be doing that presumably at a further stage of the tutorial. so as of now, my laravel home page is at http://localhost:8888/my_directory.laravel/public/
- i have checked the apache mod-rewrite : it is on and it works well for codeIgniter
- i have checked that the .htaccess is as provided by laravel (and as suggested by different posts)
The weird thing is, if i change the routes for the home page like this :
Route::get('/', function()
{
return 'hello world';
// return View::make('hello');
});
Nothing changes, i.e. i still get the original welcome page. My understanding is this modification should have simply output "hello world" as the html for the home page.
So it seems that whatever I'm doing in routes.php has no effect whatsoever, as if I was modifying the wrong file or something.
I've spent the most part of an otherwise sunny afternoon on this, any help is much apreciated :)
Thanks,
Tepp
There are many things you are doing wrong here (The best way is to follow the tutorial on Laravel):
In your controller file you are mentioning "Base_Controller", are you sure you have such a file in your controllers directory? (According to my knowledge it should be BaseController)
The Route::get is not defined properly. There are many ways to define a route; however for your case it should be something like this:
Route::get('slots', array(
'uses' => 'Slots_Controller#get_index'
));
Hope this helps.

Change Laravel's default (root) controller

In Laravel the default controller is the Home_Controller. However I have a controller called frontend. I want to use this instead of the home controller.
When I register a route like this:
Route::controller(Controller::detect());
then a request to /offer will be handled from within the home controller like home#offer. I want to use frontend#offer and access it from the site's root - not like /frontend/offer.
What should I do?
Thanks in advance.
Home_Controller is one of the hard-coded convention which exist in Laravel 3, however there are still ways to define routing to point the Frontend_Controller methods, my preference would be.
Route::any('/(index|offer|something)', function ($action)
{
return Controller::call("frontend#{$action}");
});
Limitation with this is that you need to define all supported "actions" method in Frontend_Controller.
My guess is that the only reason you think the Home_Controller is some sort of default is because you are using Controller::detect(); I really haven't seen anything in the documentation to make me think that the Home_Controller is anything special at all. In fact, it doesn't even look like it is routed to in the example documentation. Given that, my first suggestion would be to get rid of Controller::detect() and see if that fixes your problem.
Barring that, have you tried registering frontend as route named home? It appears that all URL::home() does is search for the 'Home' route, and then redirect to it. When using controller routing this can be done with something to the effect of.
Route::get('/',
array(
'as' => 'home',
'uses' => 'frontend#index'
)
);
Or is that not your desired effect? Do you want all routes which aren't otherwise found to be redirected to your frontend controller?
If you are concerned about your urls looking pretty, you can probably use some rewrite rules in your .htaccess file to make the whole process of routing to /frontend/index transparent you your users.
Add this to your routes.php :
Route::get('/', array('as' => 'any.route.name', 'uses' => 'frontend#offer'));
If you have any other / route, just remove it.

Categories