加了id后依然显示 NotFoundHttpException in RouteCollection.php line 161:

来源:2-7 Laravel-通过表单实现修改

青灯不点3884935

2017-04-20 15:19

想增加点难度,就自己修改了一些名称,结果作死出现了很多问题,但这回解决不了了。


这个是Controller的。

<?php

namespace App\Http\Controllers;

use App\Press;
use Illuminate\Http\Request;

class PressController extends  Controller
{

    //新闻列表页
    public  function index()
    {
        $news = Press::paginate(2);

        return view('press.index', [
            'news' => $news,
        ]);

    }

    public function create(Request $request)
    {

        $press = new Press();

        if($request->isMethod('POST')){

            $data = $request->input('Press');

            if(Press::create($data)){
                return redirect('press/index');
            }else{
                return redirect()->back();
            }
        }

        return view('press.create',[
            'press' => $press
        ]);
    }

    public function search()
    {
        return view('press.search');
    }

    public function save(Request $request)
    {

        $this->validate($request,[
            'Press.title' => 'required|min:1',
            'Press.content' => 'required|min:1',
        ]
//            ,[
//            'required' => 'attribute 为必填项',
//    ],[
//        'Press.title' => '标题',
//        ]
        );

        $data = $request->input('Press');

        $press = new Press();
        $press->title = $data['title'];
        $press->content = $data['content'];
        $press->field_id = $data['field_id'];

        if($press->save()){
            return redirect('press/index')->with('success','添加成功!');
        }else{
            return redirect()->back();
        }

        return view('press.create',[
            'press' => $press
        ]);

    }

    public function update($id)
    {
        $press = Press::find($id);

        return view('press.update',[
            'press' => $press
        ]);
    }


}
//这个是_form的

<form class="form-horizontal" methord="post" action="{{url('press/save')}}">

    {{ csrf_field() }}

    <div class="form-group">
        <label for="name" class="col-sm-2 control-label">标题</label>

        <div class="col-sm-5">
            <input type="text" name="Press[title]"
                   value="{{old('Press')['name'] ? old('Press')['name'] : $press->title }}"
                   class="form-control" id="title" placeholder="请输入新闻标题">
        </div>
        <div class="col-sm-5">
            <p class="form-control-static text-danger">标题不能为空</p>
        </div>
    </div>
    <div class="form-group">
        <label for="age" class="col-sm-2 control-label">内容</label>

        <div class="col-sm-5">
            <input type="text" name="Press[content]"
                   value="{{old('Press')['content'] ? old('Press')['content'] : $press->content }}"
                   class="form-control" id="content" placeholder="请输入新闻内容">
        </div>

    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">领域</label>

        <div class="col-sm-5">

            @foreach($press->field() as $ind => $val)
                <label class="radio-inline">
                    <input type="radio"
                           {{isset($press->field_id) && $press->field_id==$item?'checked="checked"':''}}
                           name="Press[field_id]"
                           {{ $press->field_id == $ind ? 'check' : '' }}
                           value="{{$ind}}"> {{ $val }}
                </label>
            @endforeach

        </div>
        <div class="col-sm-5">
            <p class="form-control-static text-danger">请选择新闻领域</p>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn btn-primary">新增</button>
        </div>
    </div>
</form>

http://img.mukewang.com/58f860b20001f48507570312.jpg

真诚的希望大神指点小白迷津...可以加好友有偿,感谢

写回答 关注

1回答

  • 青灯不点3884935
    2017-04-20 20:15:34

    通过修改老师的代码已经解决了问题了,感谢关注~

    其实我不爱学...

    怎么修改的

    2017-05-26 02:35:37

    共 1 条回复 >

轻松学会Laravel-表单篇

Laravel框架是世界上最流行的PHP框架,没有之一

32653 学习 · 255 问题

查看课程

相似问题