[英]Laravel 5 CRUD Error
I`m new to the laravel. 我是laravel的新手。 So I implement CRUD function, but it gives me 2 errors. 所以我实现了CRUD功能,但它给了我2个错误。 One is this. 一个是这个。
ErrorException in UrlGenerator.php line 304: Route [Item.store] not defined. UrlGenerator.php第304行中的ErrorException:路由[Item.store]未定义。 (View: C:\\xampp\\htdocs\\demo\\resources\\views\\Item\\create.blade.php) (视图:C:\\ xampp \\ htdocs \\ demo \\ resources \\ views \\ Item \\ create.blade.php)
Here is my index function. 这是我的索引函数。
public function index()
{
$items = Item::all();
// return $items;
return view('Item.index', compact('items'));
}
Here is my Store Function. 这是我的存储功能。
public function store(Request $request)
{
item::create($request -> all());
$item = new item;
$item ->service = $request ->service;
$item ->unit = $request ->unit;
$item ->boq_no = $request ->boq_no;
$item ->boq_qty = $request ->boq_qty;
$item ->save();
Item::create($request->all());
return redirect()->route('item')
->with('success','Item created successfully');
}
Here is my Route. 这是我的路线。
Route::group(['middleware' => ['web']], function () {
Route::resource('item', 'ItemCRUDController');
});
Here is my create.blade.php 这是我的create.blade.php
@extends('layouts.app')
@section('content')
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-default">
<div class="panel-heading">
<h2>Create New Item</h2>
</div>
<div class="panel-body">
<form action="{{route('Item.store')}}" method="post" >
{{ csrf_field() }}
<div class="form-group">
<label>Service</label>
<input type="hidden" value="{{ csrf_token() }}" name="_token" />
<input type="text" name="service" class="form-control" value="">
</div>
<div class="form-group">
<label>Unit</label>
<input type="text" name="unit"class="form-control" value="">
</div>
<div class="form-group">
<label>Boq Number</label>
<input type="text" name="boq_no"class="form-control" value="">
</div>
<div class="form-group">
<label>Boq Quentity</label>
<input type="text" name="boq_qty"class="form-control" value="">
</div>
<input type="submit" class="btn btn-success pull-right">
</form>
</div>
</div>
</div>
</div>
@endsection
Problem was this code works earlier but i do few changes now it gives that error.but when it works it duplicate save values. 问题是这段代码可以更早地工作,但是现在我做了一些更改,但给出了错误。但是当它工作时,它会重复保存值。 Can anyone help me to get this solve? 谁能帮我解决这个问题? Thank you. 谢谢。
Change this: 更改此:
{{route('Item.store')}}
To this: 对此:
{{ route('item.store') }}
If you'll still get an error, clear route cache with this command: 如果仍然出现错误,请使用以下命令清除路由缓存:
php artisan route:clear
The error says "Route [Item.store] not defined".
You have 2 options: 您有2个选择:
{{ route('Item.store') }}
to /item/store
(简便方法)将表单操作从{{ route('Item.store') }}
更改为/item/store
Route::post('item/store', 'ItemCRUDController@store')->name('item.store'); 路线:: post('item / store','ItemCRUDController @ store')-> name('item.store');
NOTE: 注意:
I think it's better to void capitalization (don't use "Item.store", it's better to use "item.store") 我认为最好不要使用大写字母(不要使用“ Item.store”,最好使用“ item.store”)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.