夙诞

109 经验值

view

<div class="row">
        <div class="col-md-9" role="main">
            <form action="/note/create" method="post">
                {!! csrf_field() !!}
                <div class="form-group">
                    <label for="title">标题</label>
                    <input type="text" class="form-control" name="title" id="title" placeholder="">
                </div>
                <div class="form-group">
                    <label for="category_id">分类</label>
                    <select class="form-control" name="category_id" id="category_id">
                        @foreach($categories as $category)
                            <option value="{$category->id}">{$category->name}</option>
                        @endforeach
                    </select>
                </div>
                <div class="form-group">
                    <label for="tags">标签</label>
                    <input type="text" class="form-control tag" name="tags" id="tags" value="">
                </div>
                <div class="form-group">
                    <label for="body">内容</label>
                    <textarea name="body" id="body" rows="16" class="form-control" placeholder="Balabala"></textarea>
                </div>
                <input class="btn btn-info pull-right" type="submit" value="保存">
            </form>
        </div>
    </div>

controller

public function store(Requests\NoteCreateRequest $request){
        $data = [
            'user_id'=>Auth::user()->id,
            'last_user_id'=>Auth::user()->id,
            'status'=>1,
        ];
        $note = Note::create(array_merge($request->all(),$data));
        return redirect('/note/'.$note->id);
    }

roures

Route::group(['middleware' => ['web']], function () {
    Route::post('/note/create','NoteController@store');
});

laravel安装的是最新的,应该是5.2

laravel request验证,数据项有误后返回前页面,之前所有填写数据都丢失。
带数据返回是不是有设置项呢