如何创建ONE Post路由以允许在管理员的许多页面上进行更改/更新?

时间:2018-02-28 12:36:00

标签: laravel

我创建了一个应用程序,现在它应该允许管理员更新前端的内容。我已经集成了TinyMCE。到现在为止还挺好。但是,而不是创建100的路线

Route::post('/category1/person1', [
    'uses' => 'MainController@infoupdate',
    'as' => 'infoupdate',
]);

Route::post('/category1/person2', [
    'uses' => 'MainController@infoupdate',
    'as' => 'infoupdate2',
]);

等...

考虑到DRY原则,我想只使用一条路线。 我尝试使用 where 过滤器,但这给了我一个错误:

  

缺少路线参数

Route::post('/{type}/{person}', [
    'uses' => 'MainController@infoupdate',
    'as' => 'infoupdate',
])->where(['type' => '(actors|authors)', 'person' => '.*']);

观点:

@if($admin)
    <form action="{{ route('infoupdate') }}" method="post">
        <div class="form-group">
            <label for="textareaeditor"></label>
            <textarea name="content" rows="10" class="form-control" id="textareaeditor"></textarea>
        </div>
        {{ csrf_field() }}
        <button type="submit">Update</button>
    </form>
@endif

我错过了什么?

1 个答案:

答案 0 :(得分:0)

问题出在您看来。创建表单时,必须传递创建路径所需的参数:

@if($admin)
<form action="{{ route('infoupdate', ['type' => 'actors', 'person' => 'person1']) }}" method="post">
    <div class="form-group">
        <label for="textareaeditor"></label>
        <textarea name="content" rows="10" class="form-control" id="textareaeditor"></textarea>
    </div>
    {{ csrf_field() }}
    <button type="submit">Update</button>
</form>
@endif