duanlie3187 2017-02-04 04:31
浏览 226

Laravel:资源控制器'store'方法不会产生任何结果,也不会产生错误

I'm trying to implement the category creation form on the backend of a site I'm building. The idea is to have it be on the same page as the index of existing categories. At present, though, the creation system does nothing. It doesn't return an error; nothing shows up in the database when queried directly; and nothing new appears on the page as per the redirect. Because there's no feedback, I'm groping around for what's different/wrong about this route versus the very similar route I made for the post creation mechanism earlier. In any case, here's the relevant creation form:

<form method="POST" action="{{ route('categories.store') }}" data-parsley-validate>
        <div class="form-group">
          <label name="name">Category Name:</label>
          <input id="name" name="name" class="form-control" required maxlength="255">
        </div>
        <input type="submit" value="Create" class="btn btn-lg btn-block">
        <input type="hidden" name="_token" value="{{ Session::token() }}">
</form>

Here is the 'store' method from the CategoryController:

public function store(Request $request)
    {
        $this->validate($request, array(
          'name' => 'required|max:255'
        ));

        $category = new Category;
        $category->name = $request->name;
        $category->save();

        Session::flash('success', 'Category has been created!');

        return redirect()->route('categories.index');
    }

And here is the web.php routes file:

<?php

Route::get('/', 'PageController@getIndex');
Route::get('/contact', 'PageController@getContact');

Route::resource('posts', 'PostController');
Route::resource('categories', 'CategoryController');
Route::get('blog/{slug}', 'PostController@show')->where('slug', '[\w\d\-\_]+');
Route::get('blog', 'PostController@index');

Auth::routes();

Route::get('/home', 'HomeController@index');

?>

Again, I'm not getting any error messages at all, it's just that the submission button does nothing. Thanks in advance!

  • 写回答

2条回答 默认 最新

  • dongxian7194 2017-02-04 06:24
    关注

    try this

    return redirect('categories.index')->withErrors($validation);
    

    you can also check this

    Display errors

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度