2017-07-01 39 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。沒有任何其他更改,相同的文件開始工作。我仍然不知道發生了什麼事。如果你知道,請讓我知道