Reputation: 13
i am getting error, Internal server error,
GET http://isp.local/teachers/168/edit 500 (Internal Server Error)
Controller:
public function edit($id)
{
$teacher = DB::table('teachers')
->find($id)
->select('*')
->first();
return response()->json([
'status' => 'success',
'teacher' => $teacher,
]);
}
while when i make following changes in controller i am getting correct results, what is issue in above code?
Controller:
public function edit($id)
{
$teacher = Teacher::find($id);
return response()->json([
'status' => 'success',
'teacher' => $teacher,
]);
}
Upvotes: 0
Views: 64
Reputation: 29278
That query is wrong. ->find()
executes the query, as does ->first()
, and everything is selected by default, so ->select('*')
is unnecessary.
$teacher = DB::table('teachers')->find($id);
Should be enough. But you're already using the correct
$teacher = Teacher::find($id);
So there isn't much point to using the DB::table()
approach.
Upvotes: 2