Skip to content

Commit fcfa94d

Browse files
committed
replace unnecessary use of DB::table
1 parent d14e90a commit fcfa94d

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

app/app/Http/Controllers/SuggestionController.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use App\Location;
1212
use App\BaseUser;
1313
use App\Suggestion;
14+
use App\User;
1415
use DB;
1516

1617
class SuggestionController extends Controller
@@ -81,18 +82,16 @@ public function addSuggestion(Request $request)
8182

8283
public function showSuggestionList(string $location_id)
8384
{
84-
$location_name = DB::table('location')->where('id', '=', $location_id)->get(['name'])[0]->name;
85+
$location_name = Location::find($location_id)->name;
8586
$suggestions = DB::table('suggestion')
8687
->where('location_id', '=', $location_id)
8788
->get([
8889
'id',
8990
'user_id',
9091
'when_generated']);
9192
foreach ($suggestions as $suggestion) {
92-
$name = DB::table('user')
93-
->where('id', '=', $suggestion->user_id)
94-
->get(['first_name','last_name'])[0];
95-
$suggestion->user_name = $name->first_name." ".$name->last_name;
93+
$user = User::find($suggestion->user_id);
94+
$suggestion->user_name = $user->first_name." ".$user->last_name;
9695
}
9796
$view_data = [
9897
'suggestions' => $suggestions,
@@ -103,14 +102,10 @@ public function showSuggestionList(string $location_id)
103102

104103
public function showSuggestionDetail(string $suggestion_id)
105104
{
106-
$suggestion = DB::table('suggestion')->where('id', '=', $suggestion_id)->get()[0];
107-
$location = DB::table('location')
108-
->where('id', '=', $suggestion->location_id)
109-
->get(['name','external_web_url','address','phone_number'])[0];
110-
$name = DB::table('user')
111-
->where('id', '=', $suggestion->user_id)
112-
->get(['first_name','last_name'])[0];
113-
$user_name = $name->first_name." ".$name->last_name;
105+
$suggestion = Suggestion::find($suggestion_id);
106+
$location = Location::find($suggestion->location_id);
107+
$user = User::find($suggestion->user_id);
108+
$user_name = $user->first_name." ".$user->last_name;
114109
$view_data = [
115110
'suggestion' => $suggestion,
116111
'user_name' => $user_name,

0 commit comments

Comments
 (0)