New-OMIS/app/Http/Controllers/Usercontroller.php.bak

46 lines
1.1 KiB
PHP
Raw Normal View History

2024-04-04 07:46:19 +00:00
<?php
namespace App\Http\Controllers;
use App\DataTables\UsersDataTable;
use App\Models\User;
use Illuminate\Http\Request;
use Spatie\Permission\Models\Role;
class UserController extends Controller
{
public function create()
{
$roles = Role::all();
return view('users.create', compact('roles'));
}
public function store(Request $request)
{
$validatedData = $request->validate([
'name' => 'required|min:5',
'email' => 'required',
'password' => 'required',
'role' => 'required',
]);
$user = User::create($validatedData);
$user->roles()->attach($request->role);
toastr()->success('User has been created!');
return redirect()->route('users.index');
}
2024-04-04 08:19:00 +00:00
public function index()
2024-04-04 07:46:19 +00:00
{
2024-04-04 08:19:00 +00:00
$users = User::latest()->get();
return view('users.index', compact('users'));
2024-04-04 07:46:19 +00:00
}
public function destroy(string $id)
{
$user = User::findOrFail($id);
$user->delete();
toastr()->success('Data has been deleted successfully!');
return redirect()->back();
}
}