I got this problem trying to get id by comparing user input with data in database. I am new in this and I tried some solution which not help at all.
Below is my controller code:
public function assign(Request $request)
{
$courselist = new Courselist;
$coursecode = $request->input('coursecode');
$courseid = DB::select("select id from course where course_code = '$coursecode'");
$courselist -> course_id = $courseid;
$courselist -> coordinator = $request->input('coordinatorname');
$courselist -> internal = $request->input('imname');
$courselist -> external = $request->input('exname');
$courselist -> dean = $request->input('deanname');
$courselist -> save();
return back()-> with('alert-success','Data successfully added!');
}
CodePudding user response:
$course = DB::table("your table name")->where("course_code ", "=", $coursecode)->first();
$courselist -> course_id = $course->id;
try this i hope it will work.