jeudi 19 janvier 2017

Laravel routes don't seem to work

I'm new to Laravel.

I've set up a Fedora 23 server through Oracle VirtualBox, installed composer and created a Laravel 5.3 project as the html folder (for convenience, since it's accessible by just the virtual machine's IP address). I also disabled its firewall, since this is just for testing/learning.

I gave storage folder 755 permissions, and I get the welcome page showing on browser by just typing http://«IP».

I created a index.blade.php view, with the same code as welcome.blade.php but changing the word Laravel to "Something". Now comes the problem.

I've created a HomeController.php controller, so that I could get the php artisan route:cache without errors, since if I returned the view on routes/web.php file, it gave me an error:

[myuser@webserver]$ php artisan route:cache
Route cache cleared!

[LogicException]
Unable to prepare route [/] for serialization. Uses Closure.

So my files look like this:

routes/web.php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/

/*
Route::get('/', function () {
    return view('welcome');
});

Route::get('home', function () {
    return view('index');
});
*/

Route::get('/', 'HomeController@getWelcomePage');
Route::get('home', 'HomeController@homepage');

app/Http/Controllers/HomeController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

class HomeController extends Controller
{
        public function homepage(){
                return view('index');
        }

        public function getWelcomePage(){
                return view('welcome');
        }

}

public/.htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

/etc/httpd/conf/httpd.conf (I removed the comment lines in the example here for length purposes)

ServerRoot "/etc/httpd"

Listen 80

Include conf.modules.d/*.conf

User apache
Group apache

ServerAdmin root@localhost

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/var/www/html/public"

<Directory "/var/www">
    AllowOverride none
    # Allow open access:
    Require all granted
</Directory>

<Directory "/var/www/html">
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "logs/error_log"

LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "logs/access_log" combined
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>

<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>

AddDefaultCharset UTF-8

<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>

EnableSendfile on

IncludeOptional conf.d/*.conf

After all this, I can see the welcome page by typing http://«IP», but if I type http://«IP»/home I only get a blank page. Browser tells me that the page returned with a 500 Internal Server Error, however at storage/logs/laravel.log nothing shows up (the last log was the error due to the php artisan route:cache not being able to execute due to the view being returned in the web.php file)

[2017-01-19 13:00:49] local.ERROR: exception 'LogicException' with message 'Unable to prepare
route [/] for serialization. Uses Closure.'
in /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php:995

The weirdest part for me is that if I comment ALL the entries in the route file, I get a route not found exception for http://«IP»/home, but if I just type http://«IP» I still get the welcome blade.

I believe that my problem is something really simple, but after hours of searching and trial/error, I still can't solve this.

Any help/suggestions are welcome.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2k57zEc
via IFTTT

Aucun commentaire:

Enregistrer un commentaire