我想在数据库中发布一些东西......但它不起作用......
我之前创建了一个表单,该表单效果很好,但现在它不适用于另一个表单?!
所以这是我的Route::group
Route::group(array('before' => 'auth', 'prefix' => 'admin'), function()
{
Route::resource('/', 'AdminController');
Route::resource('news', 'AdminNewsController');
Route::resource('calendar', 'AdminCalendarController');
});
模型Calendar
<?php
use Illuminate\Database\Eloquent\SoftDeletingTrait;
class Calendar extends Eloquent {
protected $table = 'event';
public $timestamps = false;
use SoftDeletingTrait;
protected $dates = ['deleted_at'];
}
create.blade.php
<div class="portlet-body form">
{{ Form::open(['method' => 'post', 'role' => 'form', 'files' => true]) }}
<div class="form-body">
<div class="form-group">
<label>Naam</label>
<input type="text" class="form-control" name="name" placeholder="Naam van de rally/event">
</div>
<div class="form-group">
<label>Korte info</label>
<textarea class="form-control" name="short_info" id="text_editor" rows="5" placeholder="Mag nie té lang zijn...">
</textarea>
</div>
<div class="form-group">
<label>Afbeelding / logo evenement</label>
</div>
<div class="form-group">
<div class="fileinput fileinput-new" data-provides="fileinput"><input type="hidden">
<div class="fileinput-new thumbnail" style="width: 200px; height: 150px;">
<img src="{{ Config::get('app.url') }}/public/img/10877743_338215636368840_1736631818_n.png" alt="">
</div>
<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px; line-height: 10px;">
</div>
<div>
<span class="btn default btn-file">
<span class="fileinput-new">
Selecteer een afbeelding
</span>
<span class="fileinput-exists">
Verander
</span>
{{ Form::file('img') }}
</span>
<a href="#" class="btn default fileinput-exists" data-dismiss="fileinput">
Verwijder
</a>
</div>
</div>
</div>
<div class="form-group">
<label>Doen we podium?</label>
<div class="radio-list">
<label class="radio-inline">
<span>
{{ Form::radio('podium', 'true') }}
</span>
<b style="color:green">Ja</b>
</label>
<label class="radio-inline">
<span>
{{ Form::radio('podium', 'false', true) }}
</span>
<b style="color:red">Nee</b>
</label>
</div>
</div>
<div class="form-group">
<label>Studio aanwezig?</label>
<div class="radio-list">
<label class="radio-inline">
<span>
{{ Form::radio('studio', 'true') }}
</span>
<b style="color:green">Ja</b>
</label>
<label class="radio-inline">
<span>
{{ Form::radio('studio', 'false', true) }}
</span>
<b style="color:red">Nee</b>
</label>
</div>
</div>
<div class="form-group">
<label>Is er rallyradio?</label>
<div class="radio-list">
<label class="radio-inline">
<span>
{{ Form::radio('radio', 'true') }}
</span>
<b style="color:green">Ja</b>
</label>
<label class="radio-inline">
<span>
{{ Form::radio('radio', 'false', true) }}
</span>
<b style="color:red">Nee</b>
</label>
</div>
</div>
<div class="form-group">
<label>Website</label>
<input type="text" class="form-control" name="site" placeholder="Website van het evenement">
</div>
<div class="form-group">
<label class="control-label">Start datum</label>
<input type="date" name="start_date" class="form-control" placeholder="dd/mm/yyyy">
</div>
<div class="form-group">
<label class="control-label">Eind datum</label>
<input type="date" name="expire_date" class="form-control" placeholder="dd/mm/yyyy">
</div>
</div>
<div class="form-actions">
<input type="submit" class="btn green" value="Oplsaan" />
</div>
{{ Form::close() }}
</div>
我的控制器 AdminCalendarController.php
public function store()
{
$rules = array(
'name' => 'required',
'short_info' => 'required',
'podium' => 'required',
'radio' => 'required',
'studio' => 'required',
'site' => 'required',
'start_date' => 'required',
'expire_date' => 'required'
);
$validator = Validator::make(Input::all(), $rules);
//process the storage
if ($validator->fails())
{
Session::flash('error_message', 'Fout:' . $validator->errors());
return Redirect::to('admin/calendar/create')->withErrors($validator);
}else{
//store
$event = new Calendar;
$event->rally_name = Input::get('name');
$event->short_info = Input::get('short_info');
$event->is_podium = Input::get('podium');
$event->is_studio = Input::get('studio');
$event->is_radio = Input::get('radio');
$event->website = Input::get('site');
$event->image = Input::file('img')->getClientOriginalName();
$event->posted_by = Auth::user()->username;
$event->start_date = strtotime(Input::get('start_date'));
$event->expire = strtotime(Input::get('expire_date'));
$event->published_at = time();
$event->save();
//save the image
$destinationPath = 'public/img/uploads';
if (Input::hasFile('img'))
{
$file = Input::file('img');
$file->move('public/img/uploads', $file->getClientOriginalName());
}
//redirect
Session::flash('success', 'Evenement succesvol aangemaakt!');
return Redirect::to('admin/calendar/create');
}
呈现的HTML(view-source):
<form method="POST" action="http://192.168.0.233/RPR/calendar" accept-charset="UTF-8" role="form" enctype="multipart/form-data"><input name="_token" type="hidden" value="tS5YojudgN6wGJpq59IYlN4DdiqW9o45pIrDvR7X">
<div class="form-body">
<div class="form-group">
<label>Naam</label>
<input type="text" class="form-control" name="name" placeholder="Naam van de rally/event">
</div>
<div class="form-group">
<label>Korte info</label>
<textarea class="form-control" name="short_info" id="text_editor" rows="5" placeholder="Mag nie té lang zijn...">
</textarea>
</div>
<div class="form-group">
<label>Afbeelding / logo evenement</label>
</div>
<div class="form-group">
<div class="fileinput fileinput-new" data-provides="fileinput"><input type="hidden">
<div class="fileinput-new thumbnail" style="width: 200px; height: 150px;">
<img src="http://192.168.0.233/RPR/public/img/10877743_338215636368840_1736631818_n.png" alt="">
</div>
<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px; line-height: 10px;">
</div>
<div>
<span class="btn default btn-file">
<span class="fileinput-new">
Selecteer een afbeelding
</span>
<span class="fileinput-exists">
Verander
</span>
<input name="img" type="file">
</span>
<a href="#" class="btn default fileinput-exists" data-dismiss="fileinput">
Verwijder
</a>
</div>
</div>
</div>
<div class="form-group">
<label>Doen we podium?</label>
<div class="radio-list">
<label class="radio-inline">
<span>
<input name="podium" type="radio" value="true">
</span>
<b style="color:green">Ja</b>
</label>
<label class="radio-inline">
<span>
<input checked="checked" name="podium" type="radio" value="false">
</span>
<b style="color:red">Nee</b>
</label>
</div>
</div>
<div class="form-group">
<label>Studio aanwezig?</label>
<div class="radio-list">
<label class="radio-inline">
<span>
<input name="studio" type="radio" value="true">
</span>
<b style="color:green">Ja</b>
</label>
<label class="radio-inline">
<span>
<input checked="checked" name="studio" type="radio" value="false">
</span>
<b style="color:red">Nee</b>
</label>
</div>
</div>
<div class="form-group">
<label>Is er rallyradio?</label>
<div class="radio-list">
<label class="radio-inline">
<span>
<input name="radio" type="radio" value="true">
</span>
<b style="color:green">Ja</b>
</label>
<label class="radio-inline">
<span>
<input checked="checked" name="radio" type="radio" value="false">
</span>
<b style="color:red">Nee</b>
</label>
</div>
</div>
<div class="form-group">
<label>Website</label>
<input type="text" class="form-control" name="site" placeholder="Website van het evenement">
</div>
<div class="form-group">
<label class="control-label">Start datum</label>
<input type="date" name="start_date" class="form-control" placeholder="dd/mm/yyyy">
</div>
<div class="form-group">
<label class="control-label">Eind datum</label>
<input type="date" name="expire_date" class="form-control" placeholder="dd/mm/yyyy">
</div>
</div>
<div class="form-actions">
<input type="submit" class="btn green" value="Oplsaan" />
</div>
</form>
在我的其他形式的帖子中,我完全一样,但是这个不起作用,另一个不行......
答案 0 :(得分:2)
使用
Route::resource('calendar', 'AdminCalendarController')
您正在自动设置一组CRUD路线规则。
您的创建表单已自行设置操作。
Form::open(['method' => 'post', 'role' => 'form', 'files' => true])
因此,当您在&/ 39; / calendar / create&#39;上提交您的POST时,应该在/ calendar上使用POST。
这就是你得到MethodNotAllowedHttpException的原因。没有POST路由到&#39; calendar / create&#39;。
尝试这样做(请记住您正在使用群组&#39; admin&#39;前缀):
Form::open(['method' => 'post', 'url' => url('admin/calendar'), 'role' => 'form', 'files' => true])
或
Form::open(['method' => 'post', 'url' => action('AdminCalendarController@store'), 'role' => 'form', 'files' => true])
PS:通过查看你的代码,我知道你知道CRUD / REST是什么,但我给了一些解释来帮助别人。