brunodd
brunodd

Reputation: 634

Laravel 5.0's Route::post renders an empty page, why is this when Route::get works just fine

I am new to laravel and php. I'm trying to get basic forms to work but when I want to use Route::post() I get an empty page. I have viewed multiple tutorials but can't find any differences between my (failing) code and the working examples.

My routes.php:

<?php

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

Route::post('creating', function() {
    return 'Creating something';
});

index.blade.php:

<br>
<form action='creating' method='post'>
    <button type="submit"> Create something </button>
</form>
</br>

I'm using Laravel 5.0 and XAMPP on OS X Yosemite. As mentioned before:

localhost/test/public

will render a page with the 'Create something' button. But when pressing it, I get a blank page (url will then be: localhost/test/public/creating)

EDIT: I have tried changing 'creating' to '/creating', this made no difference.

EDIT2: Changing to:

Route::get(creating, function() {
    return 'Creating something';
})

and

method = 'get'

Does work.

Upvotes: 2

Views: 1292

Answers (1)

brunodd
brunodd

Reputation: 634

After checking the error logs (duh?!) I noticed the permissions for the storage/ directory were insufficient. After fixing this, I still needed to:

  1. add "illuminate/html": "5.0.*" to the composer.json file.
  2. add 'lluminate\Html\HtmlServiceProvider' to the providers array, and 'Form'=> 'Illuminate\Html\FormFacade', 'HTML'=> 'Illuminate\Html\HtmlFacade' to the aliases array in the config/app.php file.
  3. Add {!! Form::token() !!} to the View

This fixed the entire problem

Upvotes: 2

Related Questions