Skip to content

Commit 444f0d2

Browse files
Update controllers
1 parent 0260077 commit 444f0d2

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

app/Http/Controllers/RoleController.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ public function show(string $id)
4646
/**
4747
* Show the form for editing the specified resource.
4848
*/
49-
public function edit(string $id)
49+
public function edit(Role $role)
5050
{
51-
$role = Role::findOrFail($id);
52-
5351
return Inertia::render('Roles/Edit', compact('role'));
5452
}
5553

@@ -64,9 +62,9 @@ public function update(Request $request, string $id)
6462
/**
6563
* Remove the specified resource from storage.
6664
*/
67-
public function destroy(string $id)
65+
public function destroy(Role $role)
6866
{
69-
Role::destroy($id);
67+
$role->delete();
7068

7169
return back()->with('delete', 'Role has been deleted!');
7270
}

app/Http/Controllers/UserController.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,17 @@ class UserController extends Controller
1616
*/
1717
public function index(Request $request)
1818
{
19-
return Inertia::render('Users/Index', [
20-
'users' => User::with('role')->when($request->term, function ($query, $term) {
19+
$term = $request->input('term');
20+
21+
$users = User::with('role')
22+
->when($term, function ($query, $term) {
2123
$query->where('name', 'LIKE', '%' . $term . '%')
2224
->orWhere('email', 'LIKE', '%' . $term . '%');
23-
})->latest()->paginate(5),
24-
]);
25+
})
26+
->latest()
27+
->paginate(5);
28+
29+
return Inertia::render('Users/Index', compact('users'));
2530
}
2631

2732
/**

database/migrations/2001_02_28_225921_create_roles_table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public function up(): void
2020
});
2121

2222
Role::insert([
23-
['name' => 'Administrator'],
24-
['name' => 'Subscriber'],
25-
['name' => 'Guest']
23+
['name' => 'Administrator', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()],
24+
['name' => 'Subscriber', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()],
25+
['name' => 'Guest', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()],
2626
]);
2727
}
2828

0 commit comments

Comments
 (0)