-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdminController.php
74 lines (59 loc) · 1.88 KB
/
AdminController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades;
use App\Models\User;
class AdminController extends Controller
{
public function index()
{
return view('admin.dashboard');
}
public function register()
{
return view('admin.register');
}
public function postRegister(Request $request)
{
$request->validate(User::$rules);
$requests = $request->all();
$requests['password'] = Hash::make($request->password);
$requests['image'] = "";
if ($request->hasFile('image')) {
$files = Str::random("20") . "-" . $request->image->getClientOriginalName();
$request->file('image')->move("file/admin/", $files);
$request['image'] = "file/admin/" . $files;
}
$user = User::create($requests);
if($user){
return redirect('register')->with('status', 'Berhasil mendaftar !');
}
return redirect('register')->with('status', 'Gagal Register Account');
}
public function login()
{
return view('admin.login');
}
public function postLogin(Request $request)
{
$requests = $request->all();
$data = User::where('email', $requests['email'])->first();
if($data){
$cek = Hash::check($requests['password'], $data->password);
if($cek){
Session::put('admin', $data->email);
Session::put('admin_id', $data->id);
return redirect('admin');
}
}
return redirect('login')->with('status', 'Gagal login Admin');
}
public function logout()
{
Session::flush();
return redirect('login')->with('status', 'Berhasil Logout');
}
}