1 回答
TA贡献1909条经验 获得超7个赞
看到创建表语句和存储函数后。看来您的商店功能更有可能是这里的问题。尝试这个:
use Illuminate\Support\Facades\Auth;
public function createTask(Request $request){
$user = Auth::user();//get the user model
$request->validate([//validate that the data is according to limitations
'title' => 'required|max:255',
'description' => 'max:1000',
]);
$task = new Task; //create a new instance of Task
//fill in the data
$task->title = $request->input('title');
if(!empty($request->input('description')){
$task->description = $request->input('description');
}
$task->user_id = $user->id;
$task->save();//save it
return redirect()->route('showList');
}
对于批量分配,您应该将数据库字段定义为可在您的Model
with中批量分配protected $fillable = ['title','description','user_id']。
- 1 回答
- 0 关注
- 141 浏览
添加回答
举报