Laravel 5.3 route not working - php

I have installed fresh copy of laravel 5.3.
I have the following code in my route/web.php.
Route::get('/', function () {
return view('welcome');
});
Route::get('welcome', function () {
return view('welcome');
});
when i hit localhost/project/public in the browser i can see laravel welcome page.
But when i hit localhost/project/public/welcome then 404 Not Found comes up where i should get the same laravel welcome page.
Am i forgetting something ?

Laravel is case insensitive, so if you created the project with one of these will not find the path.

Has your route file been cached? See what happens when you run:
php artisan route:clear
and try again.

I was having some trouble with this myself, so for anyone having trouble with getting a Laravel route to work:
Make sure your route is defined the correct way by running php artisan route:list Your route should show up, along with the method. (get, post, ...)
Enable mod_rewrite from the Apache settings so Laravel can map /uri to whatever you like.
Modify the .htaccess or Apache settings to allow url overrides: AllowOverride All If you are working on something like localhost/~username/yourproject, also check the username.conf file in /private/etc/apache2.
I'm not an expert in Apache settings, so feel free to correct or elaborate where needed.

goto htaccess in your laravel folder
after ( RewriteEngine On ) add this
RewriteBase /yourlaravel project name/public
example:
RewriteBase /laravel/public

Related

laravel invalid route action with subdomain

What is the proper way to add a subdomain into your routes? I have a laravel/homestead project working on my local computer but when I move it to HostGator, a shared host server, it no longer works. Well the home page works but the links to the sub-pages don't.
For example, the following route works fine on my local version:
Route::get('/appointments', 'AppointmentController#index');
But if I use that route on the remote server, it takes it to tekknow.net/appointments instead of tekknow.net/medaverter/appointments.
So I followed instructions from here:
https://laravel.com/docs/5.6/routing#route-group-sub-domain-routing
and added a prefix like this:
Route::prefix('MedAverter')->group(function() {
Route::get('/appointments', 'AppointmentController#index');
});
But that doesn't work either. It also goes to /tekknow.net/appointments
I also tried changing the route to this:
Route::get('/MedAverter/appointments', 'AppointmentController#index');
But that also went to tekknow.net/appointments
Anybody know what I'm doing wrong?
EDIT: I went onto my HostGator cPanel and looked at all my subdomains and saw that my subdomain root was medaverter.tekknow.net which is linked to Document root of medaverter.tekknow.net/MedAverter which gets redirected to http://www.tekknow.net/MedAverter. So I renamed my folder from medaverter to MedAverter to match the subdomain redirection.
Here is a screenshot showing what I see in cPanel for columns Subdomains.Root Domain, Document Root, and Redirection
When you try php artisan route:list | grep appointments,
it prints:
[~/www/MedAverter]# php artisan route:list | grep appointments
| | GET|HEAD | MedAverter/appointments | | App\Http\Controllers\AppointmentController#index | web |
That means your route MedAverter/appointments is working for laravel.
Error 404 means route cannot be found.
So I think that's something wrong with your nginx configuration.
When I try http://tekknow.net/MedAverter/MedAverter/appointments.
It has really found the route with error 500.
So, I think you have defined this code in your nginx configuration:
location = / {
rewrite ^ https://tekknow.net/MedAverter;
}
Solution 1:
Change back to rewrite ^ https://tekknow.net/; in nginx configuration.
(I'm not familiar with hostGatar cPanel, but I think you can change medaverter.tekknow.net/MedAverter redirected to http://www.tekknow.net/`)
And in your laravel project, you need to keep prefix MedAverter to appointments.
Solution 2:
Keep the rewrite code. It means you don't need to change the cPanel redirect.
And remove prefix MedAverter in laravel routes. HostGatar(Nginx) will automatically redirect with this prefix MedAverter for appointments.
Clear all caches
The problem you're getting can be due to cache. So, make sure that's not the problem by running
php artisan route:clear && php artisan view:clear && php artisan config:clear && php artisan cache:clear && php artisan clear-compiled
Base URL
If you want to change the base URL of your Laravel app, that's something already asked.
Multiple Path Prefixes
In this case you have a more than one route with the same prefix in their path. If that's the case, you can use route groups to simplify the structure.
Route::prefix('medaverter')->group(function () {
Route::get('/', function () {
// Path /medaverter
});
Route::get('appointments', function () {
// Path /medaverter/appointments
});
});
This would go to, respectively, tekknow.net/medaverter and tekknow.net/medaverter/appointments. You could also create another prefix, like testing, configure in the same way and go to tekknow.net/testing or tekknow.net/testing/whatever.
Namespace prefixes
When you’re grouping routes by route prefix, it’s likely their controllers have a similar PHP namespace. In the medaverter example, all of the medaverter routes’ controllers might be under a Medaverter namespace.
Route::namespace('Medaverter')->group(function () {
// App\Http\Controllers\Medaverter\AppointmentController
Route::get('medaverter/appointments', 'AppointmentController#index');
});
u can use route groups for that here is a sample try this:
Route::group(['prefix' => 'medaverter'], function () {
Route::get('/appointments', [AppointmentController::class, 'index'])->name('index');
});
or
Route::group(['prefix' => 'medaverter'], function () {
Route::get('/appointments', 'AppointmentController#index');
});

Route/View related issue in Laravel

I've encountered a problem while creating simple apps with Laravel on IIS.
When I create a new Laravel application I can see the Laravel welcome page just fine.
If I create another view in the same folder as the welcome.blade.php (test.blade.php for example), and set up the route for that in routes/web.php I can't navigate to that page in browser. EDIT: When I attempt this I get a 404.
My web.php is as follows:
<?php
Route::get('/', function (){
return view('welcome');
});
Route::get('/test', function (){
return view('test');
});
At first I thought that perhaps the project was not reading web.php, but when I run php artisan route:list the test route is listed.
I thought perhaps that my view didn't work, so I renamed it as welcome.blade.php and that loaded up fine. I just seem to be unable to add a route to any view or anonymous function that isn't mapped to welcome.blade.php
I tried adding a static route.php file into the app directory with the same code, but that made no difference to the result.
I'm sure I must be missing something basic, but I can't seem to put my finger on where I've gone wrong. Would massively appreciate any help you might be able to offer. Thank you.
Right I worked out where I went wrong. I hadn't run artisan serve. Very simple.
If you're having this problem, try navigating to your application root in cmd and then try
php artisan serve
Then navigate to your page using that information.
Thank you to everyone who posted, massively appreciated.
You need to install Url Rewrite in your terminal. Then import the .htaccess file located in your project/public folder.
To install Url Rewrite, you need to install Web Platform Installer (WPI). Once installed, open WPI then search for the keyword "Url Rewrite", then install the first item in the result. Once the download is finished, Url Rewrite will be available in your IIS Manager
I think IIS server maybe blocks test url.
IIS server has such features.
Before time, I remember that I used IIS blacklist url feature.
You may check IIS url block feature.

laravel route fix needed

I have a laravel project which I run from my local apache server directory.
The link for accessing this project is
www.localhost/project.dev/public/index.php
And I have a navigation menu
After I have set the APP_URL in .env file to
http://localhost/blog.dev/public/index.php/
I get no problems while navigating through the About and Contact pages in the project but when I access the Home page the browser goes to the
http://localhost/
but not to the
http://localhost/blog.dev/public/index.php/
How can I fix it? Here are my routes:
Route::get('/', 'PagesController#getIndex');
Route::get('about', 'PagesController#getAbout');
Route::get('contact', 'PagesController#getContact');
I think the best way is to setup a vhost in apache. if you want to work like this in your .env set the APP_URL= http://localhost/blog.dev/public/
Run php artisan serve in command line. The laravel buil-in server will active. And you will able to access your laravel application using correct url as like http://localhost:8000 try this and let me know if you have any problem.

Laravel routing not working correctly

Quick question,
EDIT: I do not know how to access other routes besides '/'
Here are the routes I want to access
Route::get('/', 'HomeController#index');
Route::get('users', 'UserController#index');
Route::get('foo', function()
{
return 'Hello World';
});
Here is my routes. Via php artisan routes
I can successfully access localhost/cartraderlaravel/public
It takes me to HomeController#index
when I try to access foo or users I get
I have tried
localhost/cartraderlaravel/public/users
localhost/cartraderlaravel/users
localhost/cartraderlaravel/foo
localhost/cartraderlaravel/public/foo
All of these return a "Not Found" error. Help anyone?
You should point your root directory to cartraderlaravel/public in WAMP so that you need not to visit localhost/cartraderlaravel/public. To do that in WAMP follow :
Click on WampServer icon in taskbar
Select Apache > httpd.conf from the pullup
Search for the term “DocumentRoot”
Change the DocumentRoot path to your custom directory
Search again for “DocumentRoot” again same procedure
Save your changes and “Restart All Services”
Further research shows this is a common problem with WAMP. Something to do with Apache settings. I have moved to using a virtual network and everything works now

Laravel routing (?) problems

So I just uploaded my site from my local dev environment to my server.
But there's a problem. Only the index page loads. I've mapped some
controllers to different routes like this:
//controller detection
Route::controller(Controller::detect());
//site routes
Route::get('/','site#index');
Route::get('about','site#about');
Route::get('blog','site#blog');
Route::get('downloads','site#downloads');
Route::get('products','site#products');
Route::get('shop','site#shop');
//admin routes
Route::get('login','admin#login');
//ajax functions
Route::get('loadnews/(:num)','ajax#loadnews');
Route::post('sendmessage','ajax#sendmessage');
Route::post('loadblog','ajax#loadblog');
Route::post('loadblogdetails','ajax#loadblogdetails');
Event::listen('404', function()
{
return Response::error('404');
});
Event::listen('500', function()
{
return Response::error('500');
});
Route::filter('before', function()
{
// Do stuff before every request to your application...
});
Route::filter('after', function($response)
{
// Do stuff after every request to your application...
});
Route::filter('csrf', function()
{
if (Request::forged()) return Response::error('500');
});
Route::filter('auth', function()
{
if (Auth::guest()) return Redirect::to('login');
});
And when I click on the links pointing to these routes, I've get a
simple Error: 324 (net::ERR_EMPTY_RESPONSE): from chrome.
How can I fix this?
The site currently located at: site
I was having a similar problem, and I resolved it deleting the line:
Route::controller(Controller::detect());
I'm using named Url's. Give it a try.
At least on my end I was able to fix this problem by adding. RewriteBase / to the .htaccess file. Now everything seems to be working properly.
Make sure you register the controller if you haven't.
Route::controller(array('site'));
If you're using Apache on your server, make sure mod_rewrite is on and configured as well as a decent .htaccess rule set, laravel comes with a pretty decent .htaccess for Apache servers.
Also make sure you have removed the 'index.php' base url from Application config.
These are probably the most common reasons why Routes don't work. You can also test your routes from the command line that makes this process a little simpler:
php artisan route:call get about
I had to put the root route, in your case :
Route::get('/','site#index');
at the bottom of the routes.php file
It appears you are using Linux, but in case this is applicable for future readers with the same issue:
For me, the issue was that I am running my app on Windows Server 2008 R2 and I hadn't set up the htaccess properly through my IIS Manager. I hadn't realized I needed to do this because for other sites, my htaccess files were working fine, but none of them were using mod_rewrite.
The solution was to install "IIS URL Rewrite Module 2", which I then could use from the IIS Manager, where I would choose to "Import" everything from the default htaccess file included with Laravel.
After that, all pages loaded, not just the index.

Categories