저는 laravel을 처음 사용하여 게시물을 작성하는 데 문제가 있습니다.
내 경로는 다음과 같습니다.
Route::post('savepost', 'PostsController@savepost');
여기 내 createpost.blade.php가 있습니다.
@include('header')
<div class="container">
<!-- Main component for a primary marketing message or call to action -->
<div class="jumbotron">
<h3>Create New Post</h3>
<form action="savepost" class="form-horizontal" method="post" role="form">
<div class="form-group">
<label for="inputEmail3" class="col-sm-4 control-label">Post Title</label>
<div class="col-sm-8">
<input type="text" class="form-control" name="title" id="inputEmail3" placeholder="Enter New Title">
</div>
@if($errors->has('title'))
<p class="alert alert-danger"><strong>oopps! </strong>{{ $errors->first('title') }} </p>
@endif
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-4 control-label">Post Description</label>
<div class="col-sm-8">
<textarea name="description"></textarea>
</div>
@if($errors->has('description'))
<p class="alert alert-danger"><strong>oopps! </strong>{{ $errors->first('description') }} </p>
@endif
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">
<input type="submit" class="btn btn-default" value="Save Post">
</div>
</div>
</form>
</div>
</div> <!-- /container -->
@include('footer')
다음은 내 PostsController입니다.
class PostsController extends BaseController{
public function createpost(){
return View::make('createpost');
}
public function savepost(){
$input = Input::all();
$validation = Validator::make($input, Posts::$rules);
if ($validation->passes())
{
Posts::create(array(
'title'=>Input::get('title'),
'description'=>Input::get('description')
));
}
else{
return Redirect::route('createpost')->withErrors($validation);
}
}
}
내 모델은 다음과 같습니다.
class Posts extends Eloquent {
protected $guarded = array();
protected $fillable = array('name', 'description');
protected $table = 'posts';
public static $rules = array(
'title' => 'required|min:5',
'description' => 'required'
);
}
그리고 여기 내 게시물 데이터베이스가 있습니다.
id title description url date
제발 도와주세요
게시물 테이블에 기본 라벨 타임 스탬프가 없습니다. 다음을 수행하여 모델에서이를 해제하십시오.
public $timestamps = false;
또는 게시물 테이블에 추가하십시오.
alter table posts add created_at datetime NOT NULL
alter table posts add updated_at datetime
또는 모델에서 고유 한 타임 스탬프를 만듭니다. 날짜 열이 있으므로 다음과 같이 할 수 있습니다.
const CREATED_AT = 'date';
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다