繁体   English   中英

使用Laravel PHP框架在Neo4j DB中存储家庭关系

[英]Storing family relationships in neo4j DB by using laravel php framework

我已经在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中。

我设法解决了。
我添加了死记硬背来发布:
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!');

    }

}));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM