I have a problem when I use routes in Laravel 5.0, I only need to call this route:
Route::get('home', 'HomeController#index');
But the browser shows me this, when I write http://localhost/course/public/home:
Not Found
The requested URL /course/public/home was not found on this server.
Apache/2.4.9 (Win64) PHP/5.5.12 Server at localhost Port 80
If I write http://localhost/course/public/
the index works but the other routes doesn't work, I don't know why.
In my Routes.php I have this:
Route::get('/', 'WelcomeController#index');
Route::get('home', 'HomeController#index');
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
I only downloaded laravel 5.0 with composer, I did not change nothing in the code after the download, I only want to test the routes and these don't work.
Thaks for your help.
in conclusion (the comments solved the problem, so thank you guys for this!!) you probably run Laravel on Apache and you don't have mod_rewrite enabled... or not configured correctly.
Laravel works with so called pretty urls. In order to achieve this, every request is rewritten and the config you can find in the .htaccess file in the public folder. This to give a quick and dirty explanation will let you write URLs without the index.php.
Additionally your server should serve the public folder and not the main folder. That's a security thing if you want to use your site in production.
Alternatively you can use nginx which in my opinion is a lot easier to configure and if you run laravel homestead everything comes straight out of the box.
Related
This is my first time asking questions in StackOverflow so sorry for the mistakes.
I have a problem with laravel routes.
<?php
use Illuminate\Support\Facades\Route;
//start :: login
Route::group(['namespace' => 'auth'], function () {
Route::get('/', 'AuthController#index')->name('index');
Route::get('/showResult', 'AuthController#Result')->name('Result');
Route::post('/showResultds', 'AuthController#showResult')->name('showResult');
Route::post('/dologin', 'AuthController#doLogin')->name('doLogin');
Route::get('/logout', 'AuthController#logout')->name('logout');
So these are my routes.
I have determined the app URL correctly in .env file.
My problem is that when my website is on the server (windows server) the route becomes the server's local IP address and not my domain or public IP address.
When I click on my links it becomes 172.30.30.4/login for example. and not domainname.com/login
Thanks for your help
When changing anything in any of the config files or the .env you should always run
php artisan config:cache
This will clear your current cache and cache your new settings
change the url in your config/app.php
'url' => env('APP_URL', 'http://localhost'),
and dont forget to run php artisan config:cache
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.
I have used Laravel Boilerplate for development of my application. Beside that I have installed L5Modular with it. So i define the route Like following inside my Modules
<?php
Route::group(array('module' => 'test', 'middleware' => ['web','auth'], 'prefix'=>'frontend','namespace' => 'App\Modules\test\Controllers'), function() {
Route::resource('test', 'TestController');
});
But when i tried to access the route http://localhost/blog/public/test/create it's showing 404 Error.
Why my route not accessed? is there any error of defining route?
You need to configure a virtual host to get laravel working, that's quite easy and even easier if you're using any software such as MAMP or XAMPP.
If you're on a MAC I'd suggest to have a look at laravel valet: you'll have your web server running in seconds.
If you don't want to do any of this, you'll have to change a few things in order to get Laravel working in a sub directory.
You might forget to write frontend prefix to URL. Try to access by:
http://localhost/blog/public/frontend/test/create
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.
Recently,I just installed a chat package called Easychat. At first, it worked perfectly. I don't why but today I'm facing a problem where It said as in the pic
In the console it also said: Failed to load resource: the server responded with a status of 500 (Internal Server Error)
The weirdest thing is that when I go to Route file and change the URI from easychat to something different like easychat222 just for testing.
From
Route::get('/easychat', [
'as' => 'chatnow',
'uses' => 'EasychatController#getIndex'
]);
To
Route::get('/easychat222', [
'as' => 'chatnow',
'uses' => 'EasychatController#getIndex'
]);
and refresh the page. It works perfectly with the old uri (easychat) not with the new one.
Anybody knows what is the problem here and please tell me how to fix it.
Thank you very much!
You're using wrong web server configuration. You should point web server to a public directory inside Laravel directory and restart it.
Change these lines in Apache config file (if you're using Apache):
For Apache you can use these directives:
DocumentRoot "/path_to_aravel_project/public"
<Directory "/path_to_aravel_project/public">
For nginx:
root /path_to_aravel_project/public;