Php 使用各种方法的Laravel 5.4资源控制器中的错误
我用php artisan命令创建了一个NotesControllerPhp 使用各种方法的Laravel 5.4资源控制器中的错误,php,laravel,controller,resources,crud,Php,Laravel,Controller,Resources,Crud,我用php artisan命令创建了一个NotesController php artisan make:controller NoteController --resource 路线 Route::resource('notes','NoteController'); 我也使用route:list命令检查了它们。所有路线都存在。 但是当我尝试将表单发送到notes.store时,它会被重定向到localhost/blog/notes/并显示 本地主机/blog/public/notes的
php artisan make:controller NoteController --resource
路线
Route::resource('notes','NoteController');
我也使用route:list命令检查了它们。所有路线都存在。
但是当我尝试将表单发送到notes.store时,它会被重定向到localhost/blog/notes/并显示
本地主机/blog/public/notes的索引/
[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() !!}
我不知道拉维尔出了什么问题。经过一整天的尝试,我对路线做了一些改变,它开始工作了。 我改了路线
Route::resource('notes','NoteController')代码>
到
Route::resource('note','NoteController')代码>
并将文件夹名称从notes更改为note,将所有其他路由更改为note.index
note.store
。在没有任何其他更改的情况下,相同的文件开始工作。我还是不知道发生了什么。如果你知道,请让我知道发布你的刀片视图,检查你的代码,检查你的表单的'action'属性值{!!form::open(['method'=>'Post','route'=>'notes.store','class'=>'form horizontal'])!!你能发布表单源代码视图的快照吗?
<?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);
}