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
Related
I'm running a laravel project behind a reversed proxy which is why I need to force the root url and scheme:
URL::forceRootUrl($proxy_url);
URL::forceScheme($proxy_schema);
I've added this to the top of my /routes/web.php and it's working fine until I run:
php artisan optimize
It caches the routes in /bootstrap/cache without the forced url and scheme, so now all my urls are pointing to the wrong root url.
I've tried to move the code to /Providers/AppServiceProvider.php (both register and boot) in order to make it take effect when caching the routes but no luck.
I have to manually delete the routes cache file in /bootstrap/cache to make my routes work again.
Have do I make it take effect when caching the routes?
Edit:
I have also tried to create a global middleware where I do the force url and schema. Again it works fine before caching the routes, but when running php artisan optimize the routes are once again incorrect.
php artisan optimize removed since laravel 5.6 (source, source2)
Using URL::forceRootUrl and URL::forceScheme seems like a work-around for working with reverse proxies. The clean solution for it would be to add a trusted proxies in your configuration. This post explains the feature in full. But it comes down to:
Use the App\Http\Middleware\TrustProxies middleware
Edit the middleware $proxies property with the IP(s) of your load balancer
protected $proxies = [
'192.168.1.1',
'192.168.1.2',
];
Remove the following code from /routes/web.php
URL::forceRootUrl($proxy_url);
URL::forceScheme($proxy_schema);
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.
I am working on a Laravel site on two different linux machines, and everything is working fine. However, on two separate Amazon EC2 instances one particular route returns nothing (no errors, and no content) and there is nothing in the logs. My local machines run Arch (PHP 7.0.3) and Mint (PHP 5.5.9) and the EC2 instances run Ubuntu (with PHP 5.5.9) and Amazon Linux (PHP 5.6.17). The route that is not returning anything is set up as follows in my routes.php file:
Route::group(['prefix' => 'admin'], function () {
Route::resource('teacher', 'Admin\TeacherController');
}
Route::group(['middleware' => ['admin']], function () {
Route::resource('admin/teacher', 'Admin\TeacherController');
}
All the other routes set up this way are working perfectly on all environments which is what makes this seem so strange. There are no folders in the public directory with the names admin or teacher.
Does anyone have any ideas?
I managed to solve the problem with 'composer dumpautoload'
Not sure why it wasn't working only on one route, but that was my solution.
Hope this helps someone else!
You can use the group prefix and middleware at one place like this:
Route::group(['prefix' => 'admin', 'middleware' => 'admin'], function(){...
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.
Just starting with Laravel.
I've installed it on my wamp server and setup a virtual host in apache. The standard home controller works fine. I've installed the scaffold bundle and generated a blog according to the description at the bundle's github page. There was no errors.
I've added Route::controller(Controller::detect()); to my routes.php but none seem to be working. I've tried http://laravel.dev/blog/posts/create and http://laravel.dev/blog/post/create. The scaffold created 3 controllers, users.php, blog/posts.php and blog/comments.php.
laravel.dev is a virtual host pointing with D:\wamp\www\laravel\public as DocumentRoot.
What are the possible issues? Where do I start looking?
Dont use Route::controller(Controller::detect()) - its known to be buggy and causes alot of issue.
Just define each controller individually in the routes.
I suspect you might have to include "index.php" (http://laravel.dev/index.php/blog/posts/create) in your URLs for it to work. This is a default option set in Laravel.
If you would like to turn this off for cleaner URLs, set "index" to an empty string in config/application.php.
You can read more about this in the documentation: http://laravel.com/docs/install#cleaner-urls