Skip to content

Commit

Permalink
UPDATE: Laravel 11
Browse files Browse the repository at this point in the history
  • Loading branch information
MimisK13 committed Aug 21, 2024
1 parent a974a0f commit 6459273
Show file tree
Hide file tree
Showing 38 changed files with 1,482 additions and 1,995 deletions.
3 changes: 1 addition & 2 deletions app/Http/Controllers/Auth/AuthenticatedSessionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\LoginRequest;
use App\Providers\RouteServiceProvider;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
Expand All @@ -29,7 +28,7 @@ public function store(LoginRequest $request): RedirectResponse

$request->session()->regenerate();

return redirect()->intended(RouteServiceProvider::HOME);
return redirect()->intended(route('dashboard', absolute: false));
}

/**
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/Auth/ConfirmablePasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
Expand Down Expand Up @@ -36,6 +35,6 @@ public function store(Request $request): RedirectResponse

$request->session()->put('auth.password_confirmed_at', time());

return redirect()->intended(RouteServiceProvider::HOME);
return redirect()->intended(route('dashboard', absolute: false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;

Expand All @@ -15,7 +14,7 @@ class EmailVerificationNotificationController extends Controller
public function store(Request $request): RedirectResponse
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(RouteServiceProvider::HOME);
return redirect()->intended(route('dashboard', absolute: false));
}

$request->user()->sendEmailVerificationNotification();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
Expand All @@ -16,7 +15,7 @@ class EmailVerificationPromptController extends Controller
public function __invoke(Request $request): RedirectResponse|View
{
return $request->user()->hasVerifiedEmail()
? redirect()->intended(RouteServiceProvider::HOME)
? redirect()->intended(route('dashboard', absolute: false))
: view('auth.verify-email');
}
}
9 changes: 4 additions & 5 deletions app/Http/Controllers/Auth/PasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules\Password;

class PasswordController extends Controller
Expand All @@ -16,7 +15,7 @@ class PasswordController extends Controller
*/
public function update(Request $request): RedirectResponse
{
$validated = $request->validate([
$validated = $request->validateWithBag('updatePassword', [
'current_password' => ['required', 'current_password'],
'password' => ['required', Password::defaults(), 'confirmed'],
]);
Expand All @@ -25,6 +24,6 @@ public function update(Request $request): RedirectResponse
'password' => Hash::make($validated['password']),
]);

return Redirect::route('profile.edit')->with('success', 'Password has been updated!');
return back()->with('status', 'password-updated');
}
}
6 changes: 2 additions & 4 deletions app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Http\Controllers\Controller;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Registered;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
Expand Down Expand Up @@ -32,9 +31,8 @@ public function store(Request $request): RedirectResponse
{
$request->validate([
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:'.User::class],
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
'password' => ['required', 'confirmed', Rules\Password::defaults()],
'terms-of-service' => ['required']
]);

$user = User::create([
Expand All @@ -47,6 +45,6 @@ public function store(Request $request): RedirectResponse

Auth::login($user);

return redirect(RouteServiceProvider::HOME);
return redirect(route('dashboard', absolute: false));
}
}
5 changes: 2 additions & 3 deletions app/Http/Controllers/Auth/VerifyEmailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Auth\EmailVerificationRequest;
use Illuminate\Http\RedirectResponse;
Expand All @@ -16,13 +15,13 @@ class VerifyEmailController extends Controller
public function __invoke(EmailVerificationRequest $request): RedirectResponse
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
}

if ($request->user()->markEmailAsVerified()) {
event(new Verified($request->user()));
}

return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
}
}
8 changes: 2 additions & 6 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;

class Controller extends BaseController
abstract class Controller
{
use AuthorizesRequests, ValidatesRequests;
//
}
40 changes: 20 additions & 20 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace App\Http\Controllers;

use App\Http\Requests\User\StoreUserRequest;
use App\Http\Requests\User\UpdateUserRequest;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Http\Requests\User\StoreUserRequest;
use App\Http\Requests\User\UpdateUserRequest;

class UserController extends Controller
{
Expand All @@ -16,7 +16,7 @@ public function index()
$users = User::all();

return view('users.index', [
'users' => $users
'users' => $users,
]);
}

Expand All @@ -32,13 +32,13 @@ public function store(StoreUserRequest $request)
/**
* Handle upload an image
*/
if($request->hasFile('photo')){
if ($request->hasFile('photo')) {
$file = $request->file('photo');
$filename = hexdec(uniqid()).'.'.$file->getClientOriginalExtension();

$file->storeAs('profile/', $filename, 'public');
$user->update([
'photo' => $filename
'photo' => $filename,
]);
}

Expand All @@ -50,34 +50,34 @@ public function store(StoreUserRequest $request)
public function show(User $user)
{
return view('users.show', [
'user' => $user
'user' => $user,
]);
}

public function edit(User $user)
{
return view('users.edit', [
'user' => $user
'user' => $user,
]);
}

public function update(UpdateUserRequest $request, User $user)
{

// if ($validatedData['email'] != $user->email) {
// $validatedData['email_verified_at'] = null;
// }
// if ($validatedData['email'] != $user->email) {
// $validatedData['email_verified_at'] = null;
// }

$user->update($request->except('photo'));

/**
* Handle upload image with Storage.
*/
if($request->hasFile('photo')){
if ($request->hasFile('photo')) {

// Delete Old Photo
if($user->photo){
unlink(public_path('storage/profile/') . $user->photo);
if ($user->photo) {
unlink(public_path('storage/profile/').$user->photo);
}

// Prepare New Photo
Expand All @@ -89,7 +89,7 @@ public function update(UpdateUserRequest $request, User $user)

// Save DB
$user->update([
'photo' => $fileName
'photo' => $fileName,
]);
}

Expand All @@ -98,17 +98,17 @@ public function update(UpdateUserRequest $request, User $user)
->with('success', 'User has been updated!');
}

public function updatePassword(Request $request, String $username)
public function updatePassword(Request $request, string $username)
{
# Validation
// Validation
$validated = $request->validate([
'password' => 'required_with:password_confirmation|min:6',
'password_confirmation' => 'same:password|min:6',
]);

# Update the new Password
// Update the new Password
User::where('username', $username)->update([
'password' => Hash::make($validated['password'])
'password' => Hash::make($validated['password']),
]);

return redirect()
Expand All @@ -121,8 +121,8 @@ public function destroy(User $user)
/**
* Delete photo if exists.
*/
if($user->photo){
unlink(public_path('storage/profile/') . $user->photo);
if ($user->photo) {
unlink(public_path('storage/profile/').$user->photo);
}

$user->delete();
Expand Down
4 changes: 2 additions & 2 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Providers;

use Illuminate\Http\Request;
use App\Breadcrumbs\Breadcrumbs;
use Illuminate\Http\Request;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\ServiceProvider;

Expand All @@ -24,7 +24,7 @@ public function boot(): void
{
Paginator::useBootstrapFive();

Request::macro('breadcrumbs', function (){
Request::macro('breadcrumbs', function () {
return new Breadcrumbs($this);
});
}
Expand Down
26 changes: 0 additions & 26 deletions app/Providers/AuthServiceProvider.php

This file was deleted.

19 changes: 0 additions & 19 deletions app/Providers/BroadcastServiceProvider.php

This file was deleted.

38 changes: 0 additions & 38 deletions app/Providers/EventServiceProvider.php

This file was deleted.

Loading

0 comments on commit 6459273

Please sign in to comment.