首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用laravel框架在neo4j DB中存储家庭关系

使用laravel框架在neo4j DB中存储家庭关系
EN

Stack Overflow用户
提问于 2015-01-23 09:32:29
回答 1查看 211关注 0票数 0

我用laravel框架编写了一个简单的web应用程序来存储家庭关系。以下是代码:

relationship.blade.php

代码语言:javascript
运行
复制
<!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

代码语言:javascript
运行
复制
<?php

Route::get('/', function()
{
    return View::make('hello');
});

Route::get('/relationship', function()
{
    return View::make('relationship');
});  

RelationshipController.php

代码语言:javascript
运行
复制
<?php

class RelationshipController extends BaseController {

    public function showRelation()
    {
        return View::make('Relationship');
    }

}  

Relationship.php (这是我编写代码将表单数据推送到neo4j DB的模型)

代码语言:javascript
运行
复制
<?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中。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-23 20:03:46

我设法修好了。

我增加了投递的死记硬背:

Code:

代码语言:javascript
运行
复制
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!');

    }

}));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28106782

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档