-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bootstraping with controller and views #1
- Loading branch information
1 parent
c1a7978
commit d2b31a8
Showing
10 changed files
with
140 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Support\Facades\Hash; | ||
use RealRashid\SweetAlert\Facades\Alert; | ||
use Illuminate\Support\Str; | ||
use App\Models\User; | ||
|
||
class AccountController extends Controller | ||
{ | ||
public function logout() | ||
{ | ||
Auth::logout(); | ||
return redirect()->route('login');; | ||
} | ||
|
||
public function changePassword(Request $request) | ||
{ | ||
if (!auth()->user()) { | ||
Alert::toast('Not authenticated!', 'success'); | ||
return redirect()->back(); | ||
} | ||
|
||
//check if the password is valid | ||
$request->validate([ | ||
'current_password' => 'required|min:8', | ||
'new_password' => 'required|min:8' | ||
]); | ||
|
||
$authUser = auth()->user(); | ||
|
||
$currentP = $request->current_password; | ||
$newP = $request->new_password; | ||
$confirmP = $request->confirm_password; | ||
|
||
if (Hash::check($currentP, $authUser->password)) { | ||
if (Str::of($newP)->exactly($confirmP)) { | ||
$user = User::find($authUser->id); | ||
$user->password = Hash::make($newP); | ||
if ($user->save()) { | ||
Alert::toast('Password Changed!', 'success'); | ||
return redirect()->intended('/'); | ||
} else { | ||
Alert::toast('Something went wrong!', 'warning'); | ||
} | ||
} else { | ||
Alert::toast('Passwords do not match!', 'info'); | ||
} | ||
} else { | ||
Alert::toast('Incorrect Password!', 'info'); | ||
} | ||
return redirect()->back(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
class HomeController extends Controller | ||
{ | ||
public function __construct() | ||
{ | ||
$this->middleware('auth'); | ||
} | ||
public function index() | ||
{ | ||
$userRole = auth()->user()->getRoleNames()->first(); | ||
switch ($userRole) { | ||
case 'admin': | ||
return redirect(route('admin.dashboard')); | ||
break; | ||
|
||
case 'seller': | ||
return redirect(route('seller.dashboard')); | ||
break; | ||
|
||
case 'shipper': | ||
return redirect(route('shipper.dashboard')); | ||
break; | ||
|
||
default: | ||
return redirect(route('user.index')); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
class UserController extends Controller | ||
{ | ||
//user profile | ||
public function index() | ||
{ | ||
return view('user.index'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use Illuminate\Http\Request; | ||
|
||
class AdminController extends Controller | ||
{ | ||
public function __construct() | ||
{ | ||
$this->middleware('role:admin')->except(['loginView']); | ||
} | ||
public function loginView() | ||
{ | ||
return view('auth-admin.login'); | ||
} | ||
public function dashboard() | ||
{ | ||
return view('admin.dashboard'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,8 +21,6 @@ class CategoryFactory extends Factory | |
*/ | ||
public function definition() | ||
{ | ||
return [ | ||
// | ||
]; | ||
return []; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters