112 lines
2.5 KiB
PHP
112 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class UsersController extends Controller
|
|
{
|
|
/**
|
|
* Display data for javascript ajax
|
|
*/
|
|
public function getData() {
|
|
$data = User::where('id', '!=', Auth::user()->id)->get();
|
|
return response()->json([
|
|
'status' => true,
|
|
'data' => $data->toArray()
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
return view('admin.pages.data_user.index');
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$data = User::create([
|
|
'name' => $request->name,
|
|
'email' => $request->email,
|
|
'role' => $request->role,
|
|
'alamat' => $request->alamat,
|
|
'password' => bcrypt('password', ['rounds' => 12])
|
|
]);
|
|
|
|
return response()->json([
|
|
'status' => true,
|
|
'msg' => 'Data berhasil di tambahkan'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(string $id)
|
|
{
|
|
$data = User::where('id', $id)->get();
|
|
return response()->json([
|
|
'status' => true,
|
|
'data' => $data[0]
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(string $id)
|
|
{
|
|
$data = User::where('id', $id)->get();
|
|
return response()->json([
|
|
'status' => true,
|
|
'data' => $data[0]
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, string $id)
|
|
{
|
|
$data = User::where('id', $id)->update([
|
|
'name' => $request->name,
|
|
'email' => $request->email,
|
|
'role' => $request->role,
|
|
'alamat' => $request->alamat
|
|
]);
|
|
|
|
return response()->json([
|
|
'status' => true,
|
|
'msg' => 'Data berhasil di edit'
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(string $id)
|
|
{
|
|
$data = User::where('id', $id)->delete();
|
|
|
|
return response()->json([
|
|
'status' => true,
|
|
'msg' => 'Data berhasil di hapus'
|
|
]);
|
|
}
|
|
}
|