2017-07-01 40 views
1

Laravel 5.4资源控制器我创建了PHP的工匠命令NotesController错误使用各种方法

php artisan make:controller NoteController --resource 

路线

Route::resource('notes','NoteController'); 

我检查他们使用的路线:list命令了。所有路线都存在。 但是,当我尝试发送形式notes.store它被重定向到localhost /博客/笔记/和显示的本地主机/博客/公共/笔记

指数/

[ICO] Name Last modified Size Description 
[PARENTDIR] Parent Directory  -  
Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/7.0.9 Server at localhost Port 80 

创建形式是

{!! Form::open(['method' => 'POST', 'route' => 'notes.store', 'class' => 'form-horizontal']) !!} 
    {!! Form::hidden('user_id', Auth::user()->id) !!} 

    {!! Form::label('level', 'Level') !!} 
    {!! Form::select('level', $level,null, ['class' => 'form-control', 'required' => 'required']) !!} 

     {!!Form::label('faculty','Faculty:')!!} 
     {!!Form::text('faculty',null, array('class'=> 'form-control'))!!} 

     {!! Form::label('notecatagory', 'Note Catagory') !!} 
     {!! Form::select('notecatagory', $notecatagory,null, ['class' => 'form-control', 'required' => 'required']) !!} 

     {!!Form::label('title','Title:')!!} 
     {!!Form::textarea('title',null, array('class'=> 'form-control'))!!} 


     <div class="btn-group pull-right"> 
      {!! Form::submit("Create Post", ['class' => 'btn btn-block btn-success', 'style'=>'margin-top : 20px;margin-bottom: 20px;']) !!} 
     </div> 
    {!! Form::close() !!} 

我手工录入,核对数据notes.show和notes.update工作正常,但我有问题,notes.indexnotes.store我还有其他的职位CONTROLL呃工作正常。我试图编辑帖子控制器,但问题仍然是一样的

注意控制器

<?php 

namespace App\Http\Controllers; 

use Illuminate\Http\Request; 
use Illuminate\Database\Eloquent\Relations\Relation; 
use Session; 
use App\Note; 
use 
App\User; 

class NoteController extends Controller 
{ 
    public function __construct(){ 
     $this->middleware('auth'); 

    } 
    /** 
    * Display a listing of the resource. 
    * 
    * @return \Illuminate\Http\Response 
    */ 
    public function index() 
    { 
     return view('notes.index'); 
    } 


public function store(Request $request) 
{ 
    $this->validate($request, array(
    'user_id'=> 'required |number', 
    'level'=>'required', 
    'faculty'=>'required', 
    'notecatagory'=>'required', 
    'title'=> 'required' 
    )); 

    $note = new Note; 
    $note->user_id = $request->user_id; 
    $note->level = $request->level; 
    $note->faculty = $request->faculty; 
    $note->notecatagory = $request->notecatagory; 
    $note->title = $request->title; 

    $note->save(); 

    Session::flash('success','Note successfully created'); 

    return redirect()->route('notes.show', $note->id); 
} 
+0

发表您的看法刀片和 \t 检查你的代码,并检查您的形式 –

+0

{的“行动”属性的值! Form :: open(['method'=>'POST','route'=>'notes.store','class'=>'form-horizo​​ntal'])!!} – Santosraj

+1

你可以发布源视图形式? –

回答

0

我不知道什么是错在laravel。经过一整天的尝试,我在路线上做了一些改变,并开始工作。 我改变了路线,从

Route::resource('notes','NoteController');

Route::resource('note','NoteController');

和更改文件夹名称从笔记要注意和其他所有航线note.indexnote.store。没有任何其他更改,相同的文件开始工作。我仍然不知道发生了什么事。如果你知道,请让我知道