1 回答

TA貢獻(xiàn)1909條經(jīng)驗(yàn) 獲得超7個(gè)贊
看到創(chuàng)建表語(yǔ)句和存儲(chǔ)函數(shù)后。看來(lái)您的商店功能更有可能是這里的問(wèn)題。嘗試這個(gè):
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');
}
對(duì)于批量分配,您應(yīng)該將數(shù)據(jù)庫(kù)字段定義為可在您的Model
with中批量分配protected $fillable = ['title','description','user_id']。
- 1 回答
- 0 關(guān)注
- 198 瀏覽
添加回答
舉報(bào)