laravel中表单验证
use App\Http\Controllers\Controller;
//把新增文章的内容存入数据库
public function articleAdd(Request $request){
$this->validate($request, [
'keywords' => 'required', //laravel自带验证功能,括号里记得加上Request $request
]);
//文章标题
$title = $request->input('articletitle');
//分类id
$cateid = $request->input('articlecolumn');
//排序
$sort = $request->input('articlesort');
//关键词
$keywords = $request->input('keywords');
//文章摘要
$abstract = $request->input('abstract');
//作者
$author = $request->input('author');
$type = $request->input('type');
//评论
$comment = $request->input('comment');
//缩略图
if($request->input('path')!=''){
$thumb = $request->input('path');
}else{
$thumb = '';
}
//文章内容
$content = $request->input('content');
$articles = new Articles;
$articles->title = $title;
$articles->cateid = $cateid;
$articles->sort = $sort;
$articles->keywords = $keywords;
$articles->abstract = $abstract;
$articles->author = $author;
$articles->comment = $comment;
$articles->thumb = $thumb;
$articles->content = $content;
$articles->type = $type;
$articles->save();
$result = array('status'=>1);
echo json_encode($result);
}