如何为刀片提供变量并将其保存到变量中?

时间:2016-03-22 08:36:05

标签: php multithreading laravel

我的问题解释起来有点复杂。我正在做一个博客并做了类似主题的部分。我有一个主题表和一个线程表。在我的主题表中是一个主题'属性。不,我想要,如果我正在做一个新的线程,我也想保存主题,用户目前正在进行。

带变量的发送按钮是:

<a href="{{ action('Test\\TestController@add', [$thread->thema]) }}">
    <div class="btn btn-primary">Thread hinzufügen</div>
</a>

我的添加路线:

Route::get('/add/{thread}', 'Test\\TestController@add');

我的控制器功能只是将我发送给线程创建表单。

我的创建线程 - 形式:

{!! Former::horizontal_open()->action(action('Test\\TestController@store')) !!}
{!! Former::text('thread')->label('Title:')->autofocus() !!}
{!! Former::textarea('content')->label('Content')->rows(10) !!}
{!! Former::large_primary_submit('Add Thread') !!}
{!! Former::close() !!}

好吧,在我按下提交按钮后,线程被保存,但没有主题! :/

1 个答案:

答案 0 :(得分:0)

根据以下路线:

Route::get('/add/{thread}', 'Test\\TestController@add');

您将在$thread->thema方法中获得TestController@add,因此您的方法应该能够接收该参数/变量,例如:

public function add($thread)
{
    // Now you may pass the $thread to form and keep the value in a hidden
    // text box, to pass to the for the form, add the $thread using with:
    return view('FormView')->with('thread', $thread);
}

在表单中,创建一个隐藏的输入:

<input type="hidden" name="thread" value="{{ old('thread', $thread) }}" />

或许这个(如果它有效,不确定前者):

{!! Former::hidden('thread', old('thread', $thread))->label('Title:')->autofocus() !!}