在Laravel中更新/发布数据库列

时间:2015-01-23 18:09:54

标签: laravel-4

我有一个普遍的问题。

我在larvel中有一个搜索表单,它从数据库中返回结果。

在这些我有一个输入字段,如果价格是== 0

,则输入价格

当我输入价格并提交时,我的问题是在没有我之前的搜索结果的情况下返回搜索页面,即它不会刷新带有结果和新更新字段等的同一页面。

在视图中形成

{{ Form::open(['action' => 'price_input'])->with($gyms) }}
                              {{ Form::text('enter_price', null, ['class' =>        'form-control', 'size' => '50', 'id' => 'enter_price', 'autocomplete' => 'on', 'runat' => 'server', 'required' => 'required', 'placeholder' => 'enter price!', 'style' => 'margin-bottom: 0px!important;']) }}
                             {{ Form::submit('Search', ['class' => 'btn btn-   primary', 'style' => 'margin-left: 10px;']) }}
                        {{ Form::close() }}

路线

 Route::post('/', [ //not used yet
'as' => 'price_input',
'uses' => 'PagesController@priceUpdate'
]);

模型

    public function priceUpdate($gyms)
{

    if (Input::has('enter_price'))
    {

    $price = Input::get('enter_price');
    Gym::updatePrice($price);

    return Redirect::back()->withInput();

    }


    Session::get('gyms');

    return Redirect::to('pages.home') ->with('gyms', $gym);   



}

没有打扰模型,因为它工作正常。

任何想法的人?

感谢您的回答,

我已将控制器更改为此

public function priceUpdate($gyms)
{



    if (Input::has('enter_price'))
    {

    $price = Input::get('enter_price');
    Gym::updatePrice($price);


    $gyms = Session::get('gyms');
    return Redirect::to('pages.home') ->with('gyms', $gyms);

    }




    $gyms = Session::get('gyms');
    return Redirect::to('pages.home') ->with('gyms', $gyms);
}

但是当我运行它时,我得到了      缺少PagesController :: priceUpdate()的参数1 将$ gyms传递给方法。

如果我拿走那些消失的$ gyms但不确定它是否仍在通过会话,抱歉我是新手。

orignally我有一个搜索框,当运行时返回

return View::make('pages.home')->with($data);

有什么区别
return View::make('pages.home')->with($data);

当我执行上述行时,它返回到搜索页面,在更新表单之前没有任何搜索选项,有什么想法吗?

1 个答案:

答案 0 :(得分:0)

目前,您只是检索现有会话而不对其执行任何操作。你需要这样做:

$gyms = Session::get('gyms');
return Redirect::to('pages.home') ->with('gyms', $gyms);

或者

return Redirect::to('pages.home')->with('gyms', Session::get('gyms'));

然后,您可以使用$gyms访问视图中的健身房。

或者,您也可以在视图中访问Session::get('gyms')。 另外,不确定它是否只是粘贴在这里的方式,但在->with之前你有一个不必要的空间。只是想确保这也不是问题的一部分!