我在laravel php框架中编写了一个简单的Web应用程序来存储家庭关系。这是代码:
relationship.blade.php
<!doctype html>
<html>
<head>
<meta charset='utf-8'>
<title>Form!</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<style type="text/css">
div {
position: absolute;
top: 40px;
width: 713px;
/* margin-right: 20px; */
/* padding-right: 20px; */
left: 190px;
}
</style>
</head>
<body>
<p style="position: absolute; top: 40px; left: 478px;">Enter your name and relationship with other people in the family</p>
<div class="formController">
{{ Form::open() }}
{{ Form::token() }}
{{ Form::textField('username', 'Name:') }}
{{ Form::label('text', 'Relationship: '); }}
{{ Form::select('size', array('F' => 'Father', 'M' => 'Mother', 'S' => 'Sister', 'B' => 'Brother'), 'S'); }} <br>
{{ Form::submit('Click Me!'); }}
{{ Form::close() }}
</div>
</body>
</html>
Routes.php
<?php
Route::get('/', function()
{
return View::make('hello');
});
Route::get('/relationship', function()
{
return View::make('relationship');
});
RelationshipController.php
<?php
class RelationshipController extends BaseController {
public function showRelation()
{
return View::make('Relationship');
}
}
Relationship.php
(这是我编写代码以将表单数据推送到neo4j DB的模型)
<?php
class Duck extends NeoEloquent {
//protected $fillable = array('name', '', 'password');
public function index($name, $options) {
$formData = Neo4j::makeNode();
$formData->setProperty('name',$name)
->setProperty('relationship',$options)
->save();
}
}
但是,当我点击表单中的submit
按钮时,会显示错误消息,例如Whoops, looks like something went wrong.
如何修复它?并且数据不会存储在neo4j DB中。
答案 0 :(得分:0)
我设法解决了这个问题
我添加了死记硬背:
Code:
Route::post('relationship', array('before' => 'csrf', function()
{
// create the validation rules ------------------------
$rules = array(
'name' => 'required', // just a normal required validation
'options' => 'required|options|unique:relationship', // required and must be unique in the ducks table
);
// create custom validation messages ------------------
$messages = array(
'required' => 'The :attribute is really really really important.',
'same' => 'The :others must match.'
);
// do the validation ----------------------------------
// validate against the inputs from our form
$validator = Validator::make(Input::all(), $rules, $messages);
// check if the validator failed -----------------------
if ($validator->fails()) {
// redirect our user back with error messages
$messages = $validator->messages();
// also redirect them back with old inputs so they dont have to fill out the form again
// but we wont redirect them with the password they entered
return Redirect::to('relationship')
->withErrors($validator);
} else {
// validation successful ---------------------------
$relationship = new Relationship;
$relationship->name = Input::get('name');
$relationship->options = Input::get('options');
// $duck->password = Hash::make(Input::get('password'));
$relationship->save();
// redirect ----------------------------------------
return Redirect::to('relationship')
->with('messages', 'Hooray!');
}
}));