diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 9d33f54..56ed60b 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -2,7 +2,6 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; use Spatie\Activitylog\Models\Activity; class ActivityController extends Controller @@ -14,13 +13,11 @@ public function index() return view('activity_log.index', compact('activities')); } + public function all() { $activities = Activity::all(); return view('activity_log.all', compact('activities')); } - } - - diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index da259be..54e187d 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -17,7 +17,8 @@ class AuthController extends Controller public function postLogin(PostLoginRequest $request) { if (Auth::attempt($request->only('email', 'password'))) { - activity() ->causedBy(auth()->user())->log('User logged into the portal'); // Log activity message + activity()->causedBy(auth()->user())->log('User logged into the portal'); // Log activity message + return redirect('dashboard')->with('success', 'Welcome '.auth()->user()->name); } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 77694a2..9e16a86 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -35,15 +35,15 @@ public function create() public function store(StoreUserRequest $request) { - activity()->causedBy(auth()->user())->log('User ' . $request->name . ' created'); + activity()->causedBy(auth()->user())->log('User '.$request->name.' created'); $user = $this->userRepository->store($request); - return redirect()->route('user.index')->with('success', 'User ' . $user->name . ' created'); + return redirect()->route('user.index')->with('success', 'User '.$user->name.' created'); } public function show(User $user) { - activity()->causedBy(auth()->user())->log('User ' . $user->name . ' viewed'); + activity()->causedBy(auth()->user())->log('User '.$user->name.' viewed'); if ($user->role === 'Customer') { $customer = Customer::where('user_id', $user->id)->first(); @@ -64,7 +64,7 @@ public function edit(User $user) public function update(User $user, UpdateCustomerRequest $request) { - activity()->causedBy(auth()->user())->log('User ' . $user->name . ' updated'); + activity()->causedBy(auth()->user())->log('User '.$user->name.' updated'); $user->update($request->all()); if ($user->isCustomer()) { @@ -73,18 +73,18 @@ public function update(User $user, UpdateCustomerRequest $request) ]); } - return redirect()->route('user.index')->with('success', 'User ' . $user->name . ' udpated!'); + return redirect()->route('user.index')->with('success', 'User '.$user->name.' udpated!'); } public function destroy(User $user) { - activity()->causedBy(auth()->user())->log('User ' . $user->name . ' updated'); + activity()->causedBy(auth()->user())->log('User '.$user->name.' updated'); try { $user->delete(); - return redirect()->route('user.index')->with('success', 'User ' . $user->name . ' deleted!'); + return redirect()->route('user.index')->with('success', 'User '.$user->name.' deleted!'); } catch (\Exception $e) { - return redirect()->route('user.index')->with('failed', 'Customer ' . $user->name . ' cannot be deleted! Error Code:' . $e->errorInfo[1]); + return redirect()->route('user.index')->with('failed', 'Customer '.$user->name.' cannot be deleted! Error Code:'.$e->errorInfo[1]); } } } diff --git a/app/Http/Requests/StoreCustomerRequest.php b/app/Http/Requests/StoreCustomerRequest.php index 51c9828..cebc4e5 100644 --- a/app/Http/Requests/StoreCustomerRequest.php +++ b/app/Http/Requests/StoreCustomerRequest.php @@ -23,8 +23,8 @@ public function authorize() */ public function rules() { - - if($this->isMethod('put')){ + + if ($this->isMethod('put')) { return [ 'name' => 'required', 'address' => 'required|max:255', @@ -34,6 +34,7 @@ public function rules() 'avatar' => 'mimes:png,jpg', ]; } + return [ 'name' => 'required', 'address' => 'required|max:255', diff --git a/database/migrations/2024_09_24_191240_create_activity_log_table.php b/database/migrations/2024_09_24_191240_create_activity_log_table.php index 7c05bc8..b788f65 100644 --- a/database/migrations/2024_09_24_191240_create_activity_log_table.php +++ b/database/migrations/2024_09_24_191240_create_activity_log_table.php @@ -1,8 +1,8 @@