何时要创建录音时出现此错误消息?
BadMethodCallException in => C:\ wamp64 \ www \ exemple \ vendor \ laravel \ framework \ src \ Illuminate \ Support \ Traits \ Macroable.php第74行: 方法验证不存在。
我不明白问题所在?
控制器-学生
public function index()
{
$students = Student::oldest()->paginate(5);
return view('admin.students.index', compact('students'))
->with('i', (request()->input('page',1) -1)*5);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('admin.students.create', compact('students'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$request->validate([
'name' => 'required',
'firstname' => 'required'
]);
$exists = Student::where('name', $request->get('name'))->where('firstname', $request->get('firstname'))->count();
if (!$exists){
Student::create($request->all());
return redirect()->route('students.index')
->with('success', 'new data created successfully');
}
else{
return redirect()->route('students.index')
->with('error', 'doublon');
}
}
答案 0 :(得分:1)
尝试以下代码。用此替换请求
$this->validate([
'name' => 'required',
'firstname' => 'required'
]);