Я написал простое веб-приложение в фреймворке laravel php для хранения семейных отношений. Вот код:
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)
<?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.
Мне удалось это исправить.
Я добавил Rote для публикации:
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!');
}
}));
Других решений пока нет …