php Laravel表单输入验证和插入
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Laravel表单输入验证和插入相关的知识,希望对你有一定的参考价值。
https://laracasts.com/discuss/channels/eloquent/whats-the-difference-between-save-and-create
<?php
// IN YOUR MODEL: add the fillable fields
namespace App;
use Illuminate\Database\Eloquent\Model;
class Task extends Model
{
protected $fillable = [
'task' , 'project_id', 'priority'
] ;
}
// IN YOUR CONTROLLER:
public function store(Request $request)
{
// dd( $request->all() ) ;
$this->validate( $request, [
'task' => 'required',
'project_id' => 'required'
]) ;
$post = Task::create([
'project_id' => $request->project_id,
'task' => $request->task,
'priority' => $request->priority
]);
// ->route is defined in web.php
Session::flash('success', 'Task Created') ;
return redirect()->route('task.show') ;
}
以上是关于php Laravel表单输入验证和插入的主要内容,如果未能解决你的问题,请参考以下文章
laravel 5.5 修改注册表单验证规则
PHP 表单
【PHP】laravel怎么获取网址里面的参数
【PHP】laravel怎么获取网址里面的参数
Laravel从表单输入中将“null”插入数据库。
(Laravel)表单验证不返回旧输入