2. 3 Show User (ok)

C:\xampp82\htdocs\phongkhamnet\app\Http\Controllers\UserController.php
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use Spatie\Permission\Models\Role;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
$users = User::all();
return view('users.index', compact('users'));
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$roles = Role::pluck('name', 'id')->all();
return view('users.create')->with(compact('roles'));
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$inputs = $request->all();
$inputs['password'] = bcrypt($inputs['password']);
$user = User::create($inputs);
$roles = $inputs['roles'];
$user->assignRole($roles);
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
$user = User::find($id);
return view('users.show')->with(compact('user'));
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}
C:\xampp82\htdocs\phongkhamnet\resources\views\roles\show.blade.php
Last updated
Was this helpful?