为了账号安全,请及时绑定邮箱和手机立即绑定

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

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


这个是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://img1.sycdn.imooc.com//58f860b20001f48507570312.jpg

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

正在回答

1 回答

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

1 回复 有任何疑惑可以回复我~
#1

其实我不爱学习

怎么修改的
2017-05-26 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

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

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信