├── .editorconfig ├── .env.example ├── .gitattributes ├── .gitignore ├── README.md ├── app ├── Console │ └── Kernel.php ├── Exceptions │ └── Handler.php ├── Http │ ├── Controllers │ │ ├── Admin │ │ │ └── TestController.php │ │ ├── Auth │ │ │ ├── AuthenticatedSessionController.php │ │ │ ├── ConfirmablePasswordController.php │ │ │ ├── EmailVerificationNotificationController.php │ │ │ ├── EmailVerificationPromptController.php │ │ │ ├── NewPasswordController.php │ │ │ ├── PasswordController.php │ │ │ ├── PasswordResetLinkController.php │ │ │ ├── RegisteredUserController.php │ │ │ ├── SocialiteController.php │ │ │ └── VerifyEmailController.php │ │ ├── Controller.php │ │ ├── HomeController.php │ │ ├── ProfileController.php │ │ └── ResultController.php │ ├── Kernel.php │ ├── Middleware │ │ ├── Authenticate.php │ │ ├── EncryptCookies.php │ │ ├── PreventRequestsDuringMaintenance.php │ │ ├── RedirectIfAuthenticated.php │ │ ├── TrimStrings.php │ │ ├── TrustHosts.php │ │ ├── TrustProxies.php │ │ ├── ValidateSignature.php │ │ ├── VerifyCsrfToken.php │ │ └── isAdmin.php │ └── Requests │ │ ├── Auth │ │ └── LoginRequest.php │ │ └── ProfileUpdateRequest.php ├── Livewire │ ├── Front │ │ ├── Leaderboard.php │ │ └── Quizzes │ │ │ └── Show.php │ ├── Questions │ │ ├── QuestionForm.php │ │ └── QuestionList.php │ └── Quiz │ │ ├── QuizForm.php │ │ └── QuizList.php ├── Models │ ├── Question.php │ ├── QuestionOption.php │ ├── QuestionQuiz.php │ ├── Quiz.php │ ├── Test.php │ ├── TestAnswer.php │ └── User.php ├── Providers │ ├── AppServiceProvider.php │ ├── AuthServiceProvider.php │ ├── BroadcastServiceProvider.php │ ├── EventServiceProvider.php │ └── RouteServiceProvider.php └── View │ └── Components │ ├── AppLayout.php │ ├── GuestLayout.php │ └── SelectList.php ├── artisan ├── bootstrap ├── app.php └── cache │ └── .gitignore ├── composer.json ├── composer.lock ├── config ├── app.php ├── auth.php ├── broadcasting.php ├── cache.php ├── cors.php ├── database.php ├── filesystems.php ├── hashing.php ├── livewire.php ├── logging.php ├── mail.php ├── queue.php ├── quiz.php ├── sanctum.php ├── services.php ├── session.php └── view.php ├── database ├── .gitignore ├── factories │ ├── QuestionFactory.php │ ├── QuestionOptionFactory.php │ ├── QuizFactory.php │ └── UserFactory.php ├── migrations │ ├── 2014_10_12_000000_create_users_table.php │ ├── 2014_10_12_100000_create_password_reset_tokens_table.php │ ├── 2019_08_19_000000_create_failed_jobs_table.php │ ├── 2019_12_14_000001_create_personal_access_tokens_table.php │ ├── 2023_04_04_074741_add_socialite_fields_to_users_table.php │ ├── 2023_04_04_075435_add_is_admin_to_users_table.php │ ├── 2023_04_04_075728_create_questions_table.php │ ├── 2023_04_04_103300_create_question_options_table.php │ ├── 2023_04_04_104015_create_quizzes_table.php │ ├── 2023_04_04_113312_create_question_quiz_table.php │ ├── 2023_04_05_133738_create_tests_table.php │ └── 2023_04_05_133752_create_test_answers_table.php └── seeders │ └── DatabaseSeeder.php ├── package-lock.json ├── package.json ├── phpunit.xml ├── postcss.config.js ├── public ├── .htaccess ├── favicon.ico ├── index.php └── robots.txt ├── resources ├── css │ └── app.css ├── js │ ├── app.js │ └── bootstrap.js └── views │ ├── admin │ └── tests.blade.php │ ├── auth │ ├── confirm-password.blade.php │ ├── forgot-password.blade.php │ ├── login.blade.php │ ├── register.blade.php │ ├── reset-password.blade.php │ └── verify-email.blade.php │ ├── components │ ├── application-logo.blade.php │ ├── auth-session-status.blade.php │ ├── danger-button.blade.php │ ├── dropdown-link.blade.php │ ├── dropdown.blade.php │ ├── input-error.blade.php │ ├── input-label.blade.php │ ├── modal.blade.php │ ├── nav-link.blade.php │ ├── primary-button.blade.php │ ├── responsive-nav-link.blade.php │ ├── secondary-button.blade.php │ ├── select-list.blade.php │ ├── social-links.blade.php │ ├── text-input.blade.php │ └── textarea.blade.php │ ├── dashboard.blade.php │ ├── front │ ├── quizzes │ │ └── show.blade.php │ └── results │ │ ├── index.blade.php │ │ └── show.blade.php │ ├── home.blade.php │ ├── layouts │ ├── app.blade.php │ ├── guest.blade.php │ └── navigation.blade.php │ ├── livewire │ ├── front │ │ ├── leaderboard.blade.php │ │ └── quizzes │ │ │ └── show.blade.php │ ├── questions │ │ ├── question-form.blade.php │ │ └── question-list.blade.php │ └── quiz │ │ ├── quiz-form.blade.php │ │ └── quiz-list.blade.php │ ├── profile │ ├── edit.blade.php │ └── partials │ │ ├── delete-user-form.blade.php │ │ ├── update-password-form.blade.php │ │ └── update-profile-information-form.blade.php │ └── welcome.blade.php ├── routes ├── App │ └── Http │ │ └── Livewire │ │ └── Questions │ │ └── Index.php ├── api.php ├── auth.php ├── channels.php ├── console.php └── web.php ├── storage ├── app │ ├── .gitignore │ └── public │ │ └── .gitignore ├── debugbar │ └── .gitignore ├── framework │ ├── .gitignore │ ├── cache │ │ ├── .gitignore │ │ └── data │ │ │ └── .gitignore │ ├── sessions │ │ └── .gitignore │ ├── testing │ │ └── .gitignore │ └── views │ │ └── .gitignore └── logs │ └── .gitignore ├── tailwind.config.js ├── tests ├── CreatesApplication.php ├── Feature │ ├── AdminRoutesTest.php │ ├── Auth │ │ ├── AuthenticationTest.php │ │ ├── EmailVerificationTest.php │ │ ├── PasswordConfirmationTest.php │ │ ├── PasswordResetTest.php │ │ ├── PasswordUpdateTest.php │ │ └── RegistrationTest.php │ ├── Livewire │ │ ├── QuestionsTest.php │ │ └── QuizzesTest.php │ └── ProfileTest.php ├── TestCase.php └── Unit │ └── ExampleTest.php └── vite.config.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.{yml,yaml}] 15 | indent_size = 2 16 | 17 | [docker-compose.yml] 18 | indent_size = 4 19 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | APP_DEBUG=true 5 | APP_URL=http://localhost 6 | 7 | LOG_CHANNEL=stack 8 | LOG_DEPRECATIONS_CHANNEL=null 9 | LOG_LEVEL=debug 10 | 11 | DB_CONNECTION=mysql 12 | DB_HOST=127.0.0.1 13 | DB_PORT=3306 14 | DB_DATABASE=project 15 | DB_USERNAME=root 16 | DB_PASSWORD= 17 | 18 | BROADCAST_DRIVER=log 19 | CACHE_DRIVER=file 20 | FILESYSTEM_DISK=local 21 | QUEUE_CONNECTION=sync 22 | SESSION_DRIVER=file 23 | SESSION_LIFETIME=120 24 | 25 | MEMCACHED_HOST=127.0.0.1 26 | 27 | REDIS_HOST=127.0.0.1 28 | REDIS_PASSWORD=null 29 | REDIS_PORT=6379 30 | 31 | MAIL_MAILER=smtp 32 | MAIL_HOST=mailpit 33 | MAIL_PORT=1025 34 | MAIL_USERNAME=null 35 | MAIL_PASSWORD=null 36 | MAIL_ENCRYPTION=null 37 | MAIL_FROM_ADDRESS="hello@example.com" 38 | MAIL_FROM_NAME="${APP_NAME}" 39 | 40 | AWS_ACCESS_KEY_ID= 41 | AWS_SECRET_ACCESS_KEY= 42 | AWS_DEFAULT_REGION=us-east-1 43 | AWS_BUCKET= 44 | AWS_USE_PATH_STYLE_ENDPOINT=false 45 | 46 | PUSHER_APP_ID= 47 | PUSHER_APP_KEY= 48 | PUSHER_APP_SECRET= 49 | PUSHER_HOST= 50 | PUSHER_PORT=443 51 | PUSHER_SCHEME=https 52 | PUSHER_APP_CLUSTER=mt1 53 | 54 | VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}" 55 | VITE_PUSHER_HOST="${PUSHER_HOST}" 56 | VITE_PUSHER_PORT="${PUSHER_PORT}" 57 | VITE_PUSHER_SCHEME="${PUSHER_SCHEME}" 58 | VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" 59 | 60 | GITHUB_CLIENT_ID= 61 | GITHUB_CLIENT_SECRET= 62 | 63 | FACEBOOK_CLIENT_ID= 64 | FACEBOOK_CLIENT_SECRET= 65 | 66 | GOOGLE_CLIENT_ID= 67 | GOOGLE_CLIENT_SECRET= 68 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | 3 | *.blade.php diff=html 4 | *.css diff=css 5 | *.html diff=html 6 | *.md diff=markdown 7 | *.php diff=php 8 | 9 | /.github export-ignore 10 | CHANGELOG.md export-ignore 11 | .styleci.yml export-ignore 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.phpunit.cache 2 | /node_modules 3 | /public/build 4 | /public/hot 5 | /public/storage 6 | /storage/*.key 7 | /vendor 8 | .env 9 | .env.backup 10 | .env.production 11 | .phpunit.result.cache 12 | Homestead.json 13 | Homestead.yaml 14 | auth.json 15 | npm-debug.log 16 | yarn-error.log 17 | /.fleet 18 | /.idea 19 | /.vscode 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Laravel Logo

2 | 3 |

4 | Build Status 5 | Total Downloads 6 | Latest Stable Version 7 | License 8 |

9 | 10 | ## About Laravel 11 | 12 | Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as: 13 | 14 | - [Simple, fast routing engine](https://laravel.com/docs/routing). 15 | - [Powerful dependency injection container](https://laravel.com/docs/container). 16 | - Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage. 17 | - Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent). 18 | - Database agnostic [schema migrations](https://laravel.com/docs/migrations). 19 | - [Robust background job processing](https://laravel.com/docs/queues). 20 | - [Real-time event broadcasting](https://laravel.com/docs/broadcasting). 21 | 22 | Laravel is accessible, powerful, and provides tools required for large, robust applications. 23 | 24 | ## Learning Laravel 25 | 26 | Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. 27 | 28 | You may also try the [Laravel Bootcamp](https://bootcamp.laravel.com), where you will be guided through building a modern Laravel application from scratch. 29 | 30 | If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 2000 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library. 31 | 32 | ## Laravel Sponsors 33 | 34 | We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell). 35 | 36 | ### Premium Partners 37 | 38 | - **[Vehikl](https://vehikl.com/)** 39 | - **[Tighten Co.](https://tighten.co)** 40 | - **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)** 41 | - **[64 Robots](https://64robots.com)** 42 | - **[Cubet Techno Labs](https://cubettech.com)** 43 | - **[Cyber-Duck](https://cyber-duck.co.uk)** 44 | - **[Many](https://www.many.co.uk)** 45 | - **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)** 46 | - **[DevSquad](https://devsquad.com)** 47 | - **[Curotec](https://www.curotec.com/services/technologies/laravel/)** 48 | - **[OP.GG](https://op.gg)** 49 | - **[WebReinvent](https://webreinvent.com/?utm_source=laravel&utm_medium=github&utm_campaign=patreon-sponsors)** 50 | - **[Lendio](https://lendio.com)** 51 | 52 | ## Contributing 53 | 54 | Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). 55 | 56 | ## Code of Conduct 57 | 58 | In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct). 59 | 60 | ## Security Vulnerabilities 61 | 62 | If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed. 63 | 64 | ## License 65 | 66 | The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). 67 | -------------------------------------------------------------------------------- /app/Console/Kernel.php: -------------------------------------------------------------------------------- 1 | command('inspire')->hourly(); 16 | } 17 | 18 | /** 19 | * Register the commands for the application. 20 | */ 21 | protected function commands(): void 22 | { 23 | $this->load(__DIR__.'/Commands'); 24 | 25 | require base_path('routes/console.php'); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/Exceptions/Handler.php: -------------------------------------------------------------------------------- 1 | , \Psr\Log\LogLevel::*> 14 | */ 15 | protected $levels = [ 16 | // 17 | ]; 18 | 19 | /** 20 | * A list of the exception types that are not reported. 21 | * 22 | * @var array> 23 | */ 24 | protected $dontReport = [ 25 | // 26 | ]; 27 | 28 | /** 29 | * A list of the inputs that are never flashed to the session on validation exceptions. 30 | * 31 | * @var array 32 | */ 33 | protected $dontFlash = [ 34 | 'current_password', 35 | 'password', 36 | 'password_confirmation', 37 | ]; 38 | 39 | /** 40 | * Register the exception handling callbacks for the application. 41 | */ 42 | public function register(): void 43 | { 44 | $this->reportable(function (Throwable $e) { 45 | // 46 | }); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/Http/Controllers/Admin/TestController.php: -------------------------------------------------------------------------------- 1 | withCount('questions')->latest()->paginate(); 13 | 14 | return view('admin.tests', compact('tests')); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/AuthenticatedSessionController.php: -------------------------------------------------------------------------------- 1 | authenticate(); 29 | 30 | $request->session()->regenerate(); 31 | 32 | return redirect()->intended(RouteServiceProvider::HOME); 33 | } 34 | 35 | /** 36 | * Destroy an authenticated session. 37 | */ 38 | public function destroy(Request $request): RedirectResponse 39 | { 40 | Auth::guard('web')->logout(); 41 | 42 | $request->session()->invalidate(); 43 | 44 | $request->session()->regenerateToken(); 45 | 46 | return redirect('/'); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ConfirmablePasswordController.php: -------------------------------------------------------------------------------- 1 | validate([ 29 | 'email' => $request->user()->email, 30 | 'password' => $request->password, 31 | ])) { 32 | throw ValidationException::withMessages([ 33 | 'password' => __('auth.password'), 34 | ]); 35 | } 36 | 37 | $request->session()->put('auth.password_confirmed_at', time()); 38 | 39 | return redirect()->intended(RouteServiceProvider::HOME); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/EmailVerificationNotificationController.php: -------------------------------------------------------------------------------- 1 | user()->hasVerifiedEmail()) { 18 | return redirect()->intended(RouteServiceProvider::HOME); 19 | } 20 | 21 | $request->user()->sendEmailVerificationNotification(); 22 | 23 | return back()->with('status', 'verification-link-sent'); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/EmailVerificationPromptController.php: -------------------------------------------------------------------------------- 1 | user()->hasVerifiedEmail() 19 | ? redirect()->intended(RouteServiceProvider::HOME) 20 | : view('auth.verify-email'); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/NewPasswordController.php: -------------------------------------------------------------------------------- 1 | $request]); 23 | } 24 | 25 | /** 26 | * Handle an incoming new password request. 27 | * 28 | * @throws \Illuminate\Validation\ValidationException 29 | */ 30 | public function store(Request $request): RedirectResponse 31 | { 32 | $request->validate([ 33 | 'token' => ['required'], 34 | 'email' => ['required', 'email'], 35 | 'password' => ['required', 'confirmed', Rules\Password::defaults()], 36 | ]); 37 | 38 | // Here we will attempt to reset the user's password. If it is successful we 39 | // will update the password on an actual user model and persist it to the 40 | // database. Otherwise we will parse the error and return the response. 41 | $status = Password::reset( 42 | $request->only('email', 'password', 'password_confirmation', 'token'), 43 | function ($user) use ($request) { 44 | $user->forceFill([ 45 | 'password' => Hash::make($request->password), 46 | 'remember_token' => Str::random(60), 47 | ])->save(); 48 | 49 | event(new PasswordReset($user)); 50 | } 51 | ); 52 | 53 | // If the password was successfully reset, we will redirect the user back to 54 | // the application's home authenticated view. If there is an error we can 55 | // redirect them back to where they came from with their error message. 56 | return $status == Password::PASSWORD_RESET 57 | ? redirect()->route('login')->with('status', __($status)) 58 | : back()->withInput($request->only('email')) 59 | ->withErrors(['email' => __($status)]); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/PasswordController.php: -------------------------------------------------------------------------------- 1 | validateWithBag('updatePassword', [ 19 | 'current_password' => ['required', 'current_password'], 20 | 'password' => ['required', Password::defaults(), 'confirmed'], 21 | ]); 22 | 23 | $request->user()->update([ 24 | 'password' => Hash::make($validated['password']), 25 | ]); 26 | 27 | return back()->with('status', 'password-updated'); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/PasswordResetLinkController.php: -------------------------------------------------------------------------------- 1 | validate([ 29 | 'email' => ['required', 'email'], 30 | ]); 31 | 32 | // We will send the password reset link to this user. Once we have attempted 33 | // to send the link, we will examine the response then see the message we 34 | // need to show to the user. Finally, we'll send out a proper response. 35 | $status = Password::sendResetLink( 36 | $request->only('email') 37 | ); 38 | 39 | return $status == Password::RESET_LINK_SENT 40 | ? back()->with('status', __($status)) 41 | : back()->withInput($request->only('email')) 42 | ->withErrors(['email' => __($status)]); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/RegisteredUserController.php: -------------------------------------------------------------------------------- 1 | validate([ 34 | 'name' => ['required', 'string', 'max:255'], 35 | 'email' => ['required', 'string', 'email', 'max:255', 'unique:'.User::class], 36 | 'password' => ['required', 'confirmed', Rules\Password::defaults()], 37 | ]); 38 | 39 | $user = User::create([ 40 | 'name' => $request->name, 41 | 'email' => $request->email, 42 | 'password' => Hash::make($request->password), 43 | ]); 44 | 45 | event(new Registered($user)); 46 | 47 | Auth::login($user); 48 | 49 | return redirect(RouteServiceProvider::HOME); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/SocialiteController.php: -------------------------------------------------------------------------------- 1 | validateProvider($request); 20 | 21 | return Socialite::driver($provider)->redirect(); 22 | } 23 | 24 | public function callbackSocial(Request $request, string $provider) 25 | { 26 | $this->validateProvider($request); 27 | 28 | $response = Socialite::driver($provider)->user(); 29 | 30 | $user = User::firstOrCreate( 31 | ['email' => $response->getEmail()], 32 | ['password' => Str::password()] 33 | ); 34 | $data = [$provider . '_id' => $response->getId()]; 35 | 36 | if ($user->wasRecentlyCreated) { 37 | $data['name'] = $response->getName() ?? $response->getNickname(); 38 | 39 | event(new Registered($user)); 40 | } 41 | 42 | $user->update($data); 43 | 44 | Auth::login($user, remember: true); 45 | 46 | return redirect()->intended(RouteServiceProvider::HOME); 47 | } 48 | 49 | protected function validateProvider(Request $request): array 50 | { 51 | return $this->getValidationFactory()->make( 52 | $request->route()->parameters(), 53 | ['provider' => 'in:facebook,google,github'] 54 | )->validate(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/VerifyEmailController.php: -------------------------------------------------------------------------------- 1 | user()->hasVerifiedEmail()) { 19 | return redirect()->intended(RouteServiceProvider::HOME.'?verified=1'); 20 | } 21 | 22 | if ($request->user()->markEmailAsVerified()) { 23 | event(new Verified($request->user())); 24 | } 25 | 26 | return redirect()->intended(RouteServiceProvider::HOME.'?verified=1'); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | has('questions') 14 | ->when(auth()->guest() || ! auth()->user()->is_admin, function($query) { 15 | return $query->where('published', 1); 16 | }) 17 | ->orderBy('id') 18 | ->get(); 19 | 20 | $public = $query->where('public', true); 21 | $registered = $query->where('public', false); 22 | 23 | return view('home', compact('public', 'registered')); 24 | } 25 | 26 | public function show(Quiz $quiz, $slug = null) 27 | { 28 | return view('front.quizzes.show', compact( 'quiz')); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Http/Controllers/ProfileController.php: -------------------------------------------------------------------------------- 1 | $request->user(), 21 | ]); 22 | } 23 | 24 | /** 25 | * Update the user's profile information. 26 | */ 27 | public function update(ProfileUpdateRequest $request): RedirectResponse 28 | { 29 | $request->user()->fill($request->validated()); 30 | 31 | if ($request->user()->isDirty('email')) { 32 | $request->user()->email_verified_at = null; 33 | } 34 | 35 | $request->user()->save(); 36 | 37 | return Redirect::route('profile.edit')->with('status', 'profile-updated'); 38 | } 39 | 40 | /** 41 | * Delete the user's account. 42 | */ 43 | public function destroy(Request $request): RedirectResponse 44 | { 45 | $request->validateWithBag('userDeletion', [ 46 | 'password' => ['required', 'current_password'], 47 | ]); 48 | 49 | $user = $request->user(); 50 | 51 | Auth::logout(); 52 | 53 | $user->delete(); 54 | 55 | $request->session()->invalidate(); 56 | $request->session()->regenerateToken(); 57 | 58 | return Redirect::to('/'); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/Http/Controllers/ResultController.php: -------------------------------------------------------------------------------- 1 | withCount('questions')->where('user_id', auth()->id())->paginate(); 15 | 16 | return view('front.results.index', compact('results')); 17 | } 18 | 19 | public function show(Test $test) 20 | { 21 | $test->load('user', 'quiz'); 22 | $total_questions = $test->quiz->questions->count(); 23 | $users = null; 24 | 25 | $results = TestAnswer::where('test_id', $test->id) 26 | ->with('question.questionOptions') 27 | ->get(); 28 | 29 | if (! $test->quiz->public) { 30 | $users = User::select('users.id', 'users.name', \DB::raw('sum(tests.result) as correct'), \DB::raw('sum(tests.time_spent) as time_spent')) 31 | ->join('tests', 'users.id', '=', 'tests.user_id') 32 | ->where('tests.quiz_id', $test->quiz_id) 33 | ->whereNotNull('tests.time_spent') 34 | ->groupBy('users.id', 'users.name') 35 | ->orderBy('correct', 'desc') 36 | ->orderBy('time_spent') 37 | ->get(); 38 | } 39 | return view('front.results.show', compact('test', 'results', 'total_questions', 'users')); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/Http/Kernel.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | protected $middleware = [ 17 | // \App\Http\Middleware\TrustHosts::class, 18 | \App\Http\Middleware\TrustProxies::class, 19 | \Illuminate\Http\Middleware\HandleCors::class, 20 | \App\Http\Middleware\PreventRequestsDuringMaintenance::class, 21 | \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class, 22 | \App\Http\Middleware\TrimStrings::class, 23 | \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class, 24 | ]; 25 | 26 | /** 27 | * The application's route middleware groups. 28 | * 29 | * @var array> 30 | */ 31 | protected $middlewareGroups = [ 32 | 'web' => [ 33 | \App\Http\Middleware\EncryptCookies::class, 34 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 35 | \Illuminate\Session\Middleware\StartSession::class, 36 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, 37 | \App\Http\Middleware\VerifyCsrfToken::class, 38 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 39 | ], 40 | 41 | 'api' => [ 42 | // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class, 43 | \Illuminate\Routing\Middleware\ThrottleRequests::class.':api', 44 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 45 | ], 46 | ]; 47 | 48 | /** 49 | * The application's middleware aliases. 50 | * 51 | * Aliases may be used to conveniently assign middleware to routes and groups. 52 | * 53 | * @var array 54 | */ 55 | protected $middlewareAliases = [ 56 | 'auth' => \App\Http\Middleware\Authenticate::class, 57 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 58 | 'auth.session' => \Illuminate\Session\Middleware\AuthenticateSession::class, 59 | 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 60 | 'can' => \Illuminate\Auth\Middleware\Authorize::class, 61 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 62 | 'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class, 63 | 'signed' => \App\Http\Middleware\ValidateSignature::class, 64 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 65 | 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, 66 | 'isAdmin' => \App\Http\Middleware\isAdmin::class 67 | ]; 68 | } 69 | -------------------------------------------------------------------------------- /app/Http/Middleware/Authenticate.php: -------------------------------------------------------------------------------- 1 | expectsJson() ? null : route('login'); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/Http/Middleware/EncryptCookies.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | protected $except = [ 15 | // 16 | ]; 17 | } 18 | -------------------------------------------------------------------------------- /app/Http/Middleware/PreventRequestsDuringMaintenance.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | protected $except = [ 15 | // 16 | ]; 17 | } 18 | -------------------------------------------------------------------------------- /app/Http/Middleware/RedirectIfAuthenticated.php: -------------------------------------------------------------------------------- 1 | check()) { 24 | return redirect(RouteServiceProvider::HOME); 25 | } 26 | } 27 | 28 | return $next($request); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrimStrings.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | protected $except = [ 15 | 'current_password', 16 | 'password', 17 | 'password_confirmation', 18 | ]; 19 | } 20 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrustHosts.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | public function hosts(): array 15 | { 16 | return [ 17 | $this->allSubdomainsOfApplicationUrl(), 18 | ]; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrustProxies.php: -------------------------------------------------------------------------------- 1 | |string|null 14 | */ 15 | protected $proxies; 16 | 17 | /** 18 | * The headers that should be used to detect proxies. 19 | * 20 | * @var int 21 | */ 22 | protected $headers = 23 | Request::HEADER_X_FORWARDED_FOR | 24 | Request::HEADER_X_FORWARDED_HOST | 25 | Request::HEADER_X_FORWARDED_PORT | 26 | Request::HEADER_X_FORWARDED_PROTO | 27 | Request::HEADER_X_FORWARDED_AWS_ELB; 28 | } 29 | -------------------------------------------------------------------------------- /app/Http/Middleware/ValidateSignature.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | protected $except = [ 15 | // 'fbclid', 16 | // 'utm_campaign', 17 | // 'utm_content', 18 | // 'utm_medium', 19 | // 'utm_source', 20 | // 'utm_term', 21 | ]; 22 | } 23 | -------------------------------------------------------------------------------- /app/Http/Middleware/VerifyCsrfToken.php: -------------------------------------------------------------------------------- 1 | 13 | */ 14 | protected $except = [ 15 | // 16 | ]; 17 | } 18 | -------------------------------------------------------------------------------- /app/Http/Middleware/isAdmin.php: -------------------------------------------------------------------------------- 1 | user() && auth()->user()->is_admin) { 19 | return $next($request); 20 | } 21 | 22 | return abort(403); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/Http/Requests/Auth/LoginRequest.php: -------------------------------------------------------------------------------- 1 | 26 | */ 27 | public function rules(): array 28 | { 29 | return [ 30 | 'email' => ['required', 'string', 'email'], 31 | 'password' => ['required', 'string'], 32 | ]; 33 | } 34 | 35 | /** 36 | * Attempt to authenticate the request's credentials. 37 | * 38 | * @throws \Illuminate\Validation\ValidationException 39 | */ 40 | public function authenticate(): void 41 | { 42 | $this->ensureIsNotRateLimited(); 43 | 44 | if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) { 45 | RateLimiter::hit($this->throttleKey()); 46 | 47 | throw ValidationException::withMessages([ 48 | 'email' => trans('auth.failed'), 49 | ]); 50 | } 51 | 52 | RateLimiter::clear($this->throttleKey()); 53 | } 54 | 55 | /** 56 | * Ensure the login request is not rate limited. 57 | * 58 | * @throws \Illuminate\Validation\ValidationException 59 | */ 60 | public function ensureIsNotRateLimited(): void 61 | { 62 | if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { 63 | return; 64 | } 65 | 66 | event(new Lockout($this)); 67 | 68 | $seconds = RateLimiter::availableIn($this->throttleKey()); 69 | 70 | throw ValidationException::withMessages([ 71 | 'email' => trans('auth.throttle', [ 72 | 'seconds' => $seconds, 73 | 'minutes' => ceil($seconds / 60), 74 | ]), 75 | ]); 76 | } 77 | 78 | /** 79 | * Get the rate limiting throttle key for the request. 80 | */ 81 | public function throttleKey(): string 82 | { 83 | return Str::transliterate(Str::lower($this->input('email')).'|'.$this->ip()); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /app/Http/Requests/ProfileUpdateRequest.php: -------------------------------------------------------------------------------- 1 | 15 | */ 16 | public function rules(): array 17 | { 18 | return [ 19 | 'name' => ['string', 'max:255'], 20 | 'email' => ['email', 'max:255', Rule::unique(User::class)->ignore($this->user()->id)], 21 | ]; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/Livewire/Front/Leaderboard.php: -------------------------------------------------------------------------------- 1 | quizzes = Quiz::where('public', 1)->where('published', 1)->get(); 21 | } 22 | 23 | public function render(): View 24 | { 25 | $total_questions = QuestionQuiz::select('question_id') 26 | ->join('quizzes', 'question_quiz.quiz_id', '=', 'quizzes.id') 27 | ->where('quizzes.published', 1) 28 | ->when($this->quizId > 0, function ($query) { 29 | return $query->where('quiz_id', $this->quizId); 30 | }) 31 | ->count(); 32 | 33 | $users = User::select('users.name', \DB::raw('sum(tests.result) as correct'), \DB::raw('sum(tests.time_spent) as time_spent')) 34 | ->join('tests', 'users.id', '=', 'tests.user_id') 35 | ->whereNotNull('tests.quiz_id') 36 | ->whereNotNull('tests.time_spent') 37 | ->whereNull('tests.deleted_at') 38 | ->when($this->quizId > 0, function ($query) { 39 | return $query->where('tests.quiz_id', $this->quizId); 40 | }) 41 | ->groupBy('users.id', 'users.name') 42 | ->orderBy('correct', 'desc') 43 | ->orderBy('time_spent') 44 | ->take(100) 45 | ->get(); 46 | 47 | return view('livewire.front.leaderboard', compact('users', 'total_questions')); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/Livewire/Front/Quizzes/Show.php: -------------------------------------------------------------------------------- 1 | startTimeSeconds = now()->timestamp; 34 | 35 | $this->questions = Question::query() 36 | ->inRandomOrder() 37 | ->whereRelation('quizzes', 'id', $this->quiz->id) 38 | ->with('questionOptions') 39 | ->get(); 40 | 41 | $this->currentQuestion = $this->questions[$this->currentQuestionIndex]; 42 | 43 | for($i = 0; $i < $this->questionsCount; $i++) { 44 | $this->questionsAnswers[$i] = []; 45 | } 46 | } 47 | 48 | public function changeQuestion(): void 49 | { 50 | $this->currentQuestionIndex++; 51 | 52 | if ($this->currentQuestionIndex >= $this->questionsCount) { 53 | $this->submit(); 54 | } 55 | 56 | $this->currentQuestion = $this->questions[$this->currentQuestionIndex]; 57 | } 58 | 59 | #[Computed] 60 | public function questionsCount(): int 61 | { 62 | return $this->questions->count(); 63 | } 64 | 65 | public function submit(): Redirector|RedirectResponse 66 | { 67 | $result = 0; 68 | 69 | $test = Test::create([ 70 | 'user_id' => auth()->id(), 71 | 'quiz_id' => $this->quiz->id, 72 | 'result' => 0, 73 | 'ip_address' => request()->ip(), 74 | 'time_spent' => now()->timestamp - $this->startTimeSeconds 75 | ]); 76 | 77 | foreach ($this->questionsAnswers as $key => $option) { 78 | $status = 0; 79 | 80 | if (! empty($option) && QuestionOption::find($option)->correct) { 81 | $status = 1; 82 | $result++; 83 | } 84 | 85 | TestAnswer::create([ 86 | 'user_id' => auth()->id(), 87 | 'test_id' => $test->id, 88 | 'question_id' => $this->questions[$key]->id, 89 | 'option_id' => $option ?? null, 90 | 'correct' => $status, 91 | ]); 92 | } 93 | 94 | $test->update([ 95 | 'result' => $result, 96 | ]); 97 | 98 | return to_route('results.show', $test); 99 | } 100 | 101 | public function render(): View 102 | { 103 | return view('livewire.front.quizzes.show'); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /app/Livewire/Questions/QuestionForm.php: -------------------------------------------------------------------------------- 1 | exists) { 27 | $this->question = $question; 28 | $this->editing = true; 29 | $this->question_text = $question->question_text; 30 | $this->code_snippet = $question->code_snippet; 31 | $this->answer_explanation = $question->answer_explanation; 32 | $this->more_info_link = $question->more_info_link; 33 | 34 | foreach ($question->questionOptions as $option) { 35 | $this->questionOptions[] = [ 36 | 'id' => $option->id, 37 | 'option' => $option->option, 38 | 'correct' => $option->correct, 39 | ]; 40 | } 41 | } 42 | } 43 | 44 | public function addQuestionsOption(): void 45 | { 46 | $this->questionOptions[] = [ 47 | 'option' => '', 48 | 'correct' => false 49 | ]; 50 | } 51 | 52 | public function removeQuestionsOption(int $index): void 53 | { 54 | unset($this->questionOptions[$index]); 55 | $this->questionOptions = array_values(($this->questionOptions)); 56 | } 57 | 58 | public function save(): Redirector|RedirectResponse 59 | { 60 | $this->validate(); 61 | 62 | if (empty($this->question)) { 63 | $this->question = Question::create($this->only(['question_text', 'code_snippet', 'answer_explanation', 'more_info_link'])); 64 | } else { 65 | $this->question->update($this->only(['question_text', 'code_snippet', 'answer_explanation', 'more_info_link'])); 66 | } 67 | 68 | $this->question->questionOptions()->delete(); 69 | 70 | foreach ($this->questionOptions as $option) { 71 | $this->question->questionOptions()->create($option); 72 | } 73 | 74 | return to_route('questions'); 75 | } 76 | 77 | public function render(): View 78 | { 79 | return view('livewire.questions.question-form'); 80 | } 81 | 82 | protected function rules(): array 83 | { 84 | return [ 85 | 'question_text' => [ 86 | 'string', 87 | 'required', 88 | ], 89 | 'code_snippet' => [ 90 | 'string', 91 | 'nullable', 92 | ], 93 | 'answer_explanation' => [ 94 | 'string', 95 | 'nullable', 96 | ], 97 | 'more_info_link' => [ 98 | 'url', 99 | 'nullable', 100 | ], 101 | 'questionOptions' => [ 102 | 'required', 103 | 'array', 104 | ], 105 | 'questionOptions.*.option' => [ 106 | 'required', 107 | 'string', 108 | ], 109 | ]; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /app/Livewire/Questions/QuestionList.php: -------------------------------------------------------------------------------- 1 | paginate(); 15 | 16 | return view('livewire.questions.question-list', compact('questions')); 17 | } 18 | 19 | public function delete(Question $question): void 20 | { 21 | abort_if(! auth()->user()->is_admin, Response::HTTP_FORBIDDEN, '403 Forbidden'); 22 | 23 | $question->delete(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/Livewire/Quiz/QuizForm.php: -------------------------------------------------------------------------------- 1 | initListsForFields(); 32 | 33 | if ($quiz->exists) { 34 | $this->quiz = $quiz; 35 | $this->editing = true; 36 | $this->title = $quiz->title; 37 | $this->slug = $quiz->slug; 38 | $this->description = $quiz->description; 39 | $this->published = $quiz->published; 40 | $this->public = $quiz->public; 41 | 42 | $this->questions = $quiz->questions()->pluck('id')->toArray(); 43 | } else { 44 | $this->published = false; 45 | $this->public = false; 46 | } 47 | } 48 | 49 | public function updatedTitle(): void 50 | { 51 | $this->slug = Str::slug($this->title); 52 | } 53 | 54 | public function save(): Redirector|RedirectResponse 55 | { 56 | $this->validate(); 57 | 58 | if (empty($this->quiz)) { 59 | $this->quiz = Quiz::create($this->only(['title', 'slug', 'description', 'published', 'public'])); 60 | } else { 61 | $this->quiz->update($this->only(['title', 'slug', 'description', 'published', 'public'])); 62 | } 63 | 64 | $this->quiz->questions()->sync($this->questions); 65 | 66 | return to_route('quizzes'); 67 | } 68 | 69 | public function render(): View 70 | { 71 | return view('livewire.quiz.quiz-form'); 72 | } 73 | 74 | protected function rules(): array 75 | { 76 | return [ 77 | 'title' => [ 78 | 'string', 79 | 'required', 80 | ], 81 | 'slug' => [ 82 | 'string', 83 | 'nullable', 84 | ], 85 | 'description' => [ 86 | 'string', 87 | 'nullable', 88 | ], 89 | 'published' => [ 90 | 'boolean', 91 | ], 92 | 'public' => [ 93 | 'boolean', 94 | ], 95 | 'questions' => [ 96 | 'array' 97 | ], 98 | ]; 99 | } 100 | 101 | protected function initListsForFields(): void 102 | { 103 | $this->listsForFields['questions'] = Question::pluck('question_text', 'id')->toArray(); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /app/Livewire/Quiz/QuizList.php: -------------------------------------------------------------------------------- 1 | latest()->paginate(); 15 | 16 | return view('livewire.quiz.quiz-list', compact('quizzes')); 17 | } 18 | 19 | public function delete(Quiz $quiz) 20 | { 21 | abort_if(! auth()->user()->is_admin, Response::HTTP_FORBIDDEN, '403 Forbidden'); 22 | 23 | $quiz->delete(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/Models/Question.php: -------------------------------------------------------------------------------- 1 | hasMany(QuestionOption::class)->inRandomOrder(); 26 | } 27 | 28 | public function quizzes(): BelongsToMany 29 | { 30 | return $this->belongsToMany(Quiz::class); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Models/QuestionOption.php: -------------------------------------------------------------------------------- 1 | 'boolean', 23 | ]; 24 | 25 | public function question(): BelongsTo 26 | { 27 | return $this->belongsTo(Question::class); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/Models/QuestionQuiz.php: -------------------------------------------------------------------------------- 1 | 'boolean', 25 | 'public' => 'boolean', 26 | ]; 27 | 28 | public function questions(): BelongsToMany 29 | { 30 | return $this->belongsToMany(Question::class); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Models/Test.php: -------------------------------------------------------------------------------- 1 | belongsTo(User::class); 27 | } 28 | 29 | public function quiz(): BelongsTo 30 | { 31 | return $this->belongsTo(Quiz::class); 32 | } 33 | 34 | public function questions(): BelongsToMany 35 | { 36 | return $this->belongsToMany(Question::class, 'test_answers', 'test_id', 'question_id'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/Models/TestAnswer.php: -------------------------------------------------------------------------------- 1 | belongsTo(User::class); 26 | } 27 | 28 | public function test(): BelongsTo 29 | { 30 | return $this->belongsTo(Test::class); 31 | } 32 | 33 | public function question(): BelongsTo 34 | { 35 | return $this->belongsTo(Question::class); 36 | } 37 | 38 | public function option(): BelongsTo 39 | { 40 | return $this->belongsTo(QuestionOption::class); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/Models/User.php: -------------------------------------------------------------------------------- 1 | 19 | */ 20 | protected $fillable = [ 21 | 'name', 22 | 'email', 23 | 'password', 24 | 'is_admin', 25 | 'facebook_id', 26 | 'google_id', 27 | 'github_id', 28 | ]; 29 | 30 | /** 31 | * The attributes that should be hidden for serialization. 32 | * 33 | * @var array 34 | */ 35 | protected $hidden = [ 36 | 'password', 37 | 'remember_token', 38 | ]; 39 | 40 | /** 41 | * The attributes that should be cast. 42 | * 43 | * @var array 44 | */ 45 | protected $casts = [ 46 | 'email_verified_at' => 'datetime', 47 | ]; 48 | } 49 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | user()?->is_admin; 25 | }); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/Providers/AuthServiceProvider.php: -------------------------------------------------------------------------------- 1 | 14 | */ 15 | protected $policies = [ 16 | // 'App\Models\Model' => 'App\Policies\ModelPolicy', 17 | ]; 18 | 19 | /** 20 | * Register any authentication / authorization services. 21 | */ 22 | public function boot(): void 23 | { 24 | // 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/Providers/BroadcastServiceProvider.php: -------------------------------------------------------------------------------- 1 | > 16 | */ 17 | protected $listen = [ 18 | Registered::class => [ 19 | SendEmailVerificationNotification::class, 20 | ], 21 | ]; 22 | 23 | /** 24 | * Register any events for your application. 25 | */ 26 | public function boot(): void 27 | { 28 | // 29 | } 30 | 31 | /** 32 | * Determine if events and listeners should be automatically discovered. 33 | */ 34 | public function shouldDiscoverEvents(): bool 35 | { 36 | return false; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/Providers/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | configureRateLimiting(); 28 | 29 | $this->routes(function () { 30 | Route::middleware('api') 31 | ->prefix('api') 32 | ->group(base_path('routes/api.php')); 33 | 34 | Route::middleware('web') 35 | ->group(base_path('routes/web.php')); 36 | }); 37 | } 38 | 39 | /** 40 | * Configure the rate limiters for the application. 41 | */ 42 | protected function configureRateLimiting(): void 43 | { 44 | RateLimiter::for('api', function (Request $request) { 45 | return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip()); 46 | }); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/View/Components/AppLayout.php: -------------------------------------------------------------------------------- 1 | make(Illuminate\Contracts\Console\Kernel::class); 34 | 35 | $status = $kernel->handle( 36 | $input = new Symfony\Component\Console\Input\ArgvInput, 37 | new Symfony\Component\Console\Output\ConsoleOutput 38 | ); 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Shutdown The Application 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Once Artisan has finished running, we will fire off the shutdown events 46 | | so that any final work may be done by the application before we shut 47 | | down the process. This is the last thing to happen to the request. 48 | | 49 | */ 50 | 51 | $kernel->terminate($input, $status); 52 | 53 | exit($status); 54 | -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | singleton( 30 | Illuminate\Contracts\Http\Kernel::class, 31 | App\Http\Kernel::class 32 | ); 33 | 34 | $app->singleton( 35 | Illuminate\Contracts\Console\Kernel::class, 36 | App\Console\Kernel::class 37 | ); 38 | 39 | $app->singleton( 40 | Illuminate\Contracts\Debug\ExceptionHandler::class, 41 | App\Exceptions\Handler::class 42 | ); 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Return The Application 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This script returns the application instance. The instance is given to 50 | | the calling script so we can separate the building of the instances 51 | | from the actual running of the application and sending responses. 52 | | 53 | */ 54 | 55 | return $app; 56 | -------------------------------------------------------------------------------- /bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel/laravel", 3 | "type": "project", 4 | "description": "The Laravel Framework.", 5 | "keywords": ["framework", "laravel"], 6 | "license": "MIT", 7 | "require": { 8 | "php": "^8.1", 9 | "guzzlehttp/guzzle": "^7.2", 10 | "laravel/framework": "^10.0", 11 | "laravel/sanctum": "^3.2", 12 | "laravel/socialite": "^5.6", 13 | "laravel/tinker": "^2.8", 14 | "livewire/livewire": "^3.0" 15 | }, 16 | "require-dev": { 17 | "barryvdh/laravel-debugbar": "^3.8", 18 | "fakerphp/faker": "^1.9.1", 19 | "laravel/breeze": "^1.20", 20 | "laravel/pint": "^1.0", 21 | "laravel/sail": "^1.18", 22 | "mockery/mockery": "^1.4.4", 23 | "nunomaduro/collision": "^7.0", 24 | "phpunit/phpunit": "^10.0", 25 | "spatie/laravel-ignition": "^2.0" 26 | }, 27 | "autoload": { 28 | "psr-4": { 29 | "App\\": "app/", 30 | "Database\\Factories\\": "database/factories/", 31 | "Database\\Seeders\\": "database/seeders/" 32 | } 33 | }, 34 | "autoload-dev": { 35 | "psr-4": { 36 | "Tests\\": "tests/" 37 | } 38 | }, 39 | "scripts": { 40 | "post-autoload-dump": [ 41 | "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", 42 | "@php artisan package:discover --ansi" 43 | ], 44 | "post-update-cmd": [ 45 | "@php artisan vendor:publish --tag=laravel-assets --ansi --force" 46 | ], 47 | "post-root-package-install": [ 48 | "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 49 | ], 50 | "post-create-project-cmd": [ 51 | "@php artisan key:generate --ansi" 52 | ] 53 | }, 54 | "extra": { 55 | "laravel": { 56 | "dont-discover": [] 57 | } 58 | }, 59 | "config": { 60 | "optimize-autoloader": true, 61 | "preferred-install": "dist", 62 | "sort-packages": true, 63 | "allow-plugins": { 64 | "pestphp/pest-plugin": true, 65 | "php-http/discovery": true 66 | } 67 | }, 68 | "minimum-stability": "stable", 69 | "prefer-stable": true 70 | } 71 | -------------------------------------------------------------------------------- /config/broadcasting.php: -------------------------------------------------------------------------------- 1 | env('BROADCAST_DRIVER', 'null'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Broadcast Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the broadcast connections that will be used 26 | | to broadcast events to other systems or over websockets. Samples of 27 | | each available type of connection are provided inside this array. 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'pusher' => [ 34 | 'driver' => 'pusher', 35 | 'key' => env('PUSHER_APP_KEY'), 36 | 'secret' => env('PUSHER_APP_SECRET'), 37 | 'app_id' => env('PUSHER_APP_ID'), 38 | 'options' => [ 39 | 'host' => env('PUSHER_HOST') ?: 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com', 40 | 'port' => env('PUSHER_PORT', 443), 41 | 'scheme' => env('PUSHER_SCHEME', 'https'), 42 | 'encrypted' => true, 43 | 'useTLS' => env('PUSHER_SCHEME', 'https') === 'https', 44 | ], 45 | 'client_options' => [ 46 | // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html 47 | ], 48 | ], 49 | 50 | 'ably' => [ 51 | 'driver' => 'ably', 52 | 'key' => env('ABLY_KEY'), 53 | ], 54 | 55 | 'redis' => [ 56 | 'driver' => 'redis', 57 | 'connection' => 'default', 58 | ], 59 | 60 | 'log' => [ 61 | 'driver' => 'log', 62 | ], 63 | 64 | 'null' => [ 65 | 'driver' => 'null', 66 | ], 67 | 68 | ], 69 | 70 | ]; 71 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_DRIVER', 'file'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Cache Stores 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the cache "stores" for your application as 26 | | well as their drivers. You may even define multiple stores for the 27 | | same cache driver to group types of items stored in your caches. 28 | | 29 | | Supported drivers: "apc", "array", "database", "file", 30 | | "memcached", "redis", "dynamodb", "octane", "null" 31 | | 32 | */ 33 | 34 | 'stores' => [ 35 | 36 | 'apc' => [ 37 | 'driver' => 'apc', 38 | ], 39 | 40 | 'array' => [ 41 | 'driver' => 'array', 42 | 'serialize' => false, 43 | ], 44 | 45 | 'database' => [ 46 | 'driver' => 'database', 47 | 'table' => 'cache', 48 | 'connection' => null, 49 | 'lock_connection' => null, 50 | ], 51 | 52 | 'file' => [ 53 | 'driver' => 'file', 54 | 'path' => storage_path('framework/cache/data'), 55 | ], 56 | 57 | 'memcached' => [ 58 | 'driver' => 'memcached', 59 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 60 | 'sasl' => [ 61 | env('MEMCACHED_USERNAME'), 62 | env('MEMCACHED_PASSWORD'), 63 | ], 64 | 'options' => [ 65 | // Memcached::OPT_CONNECT_TIMEOUT => 2000, 66 | ], 67 | 'servers' => [ 68 | [ 69 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 70 | 'port' => env('MEMCACHED_PORT', 11211), 71 | 'weight' => 100, 72 | ], 73 | ], 74 | ], 75 | 76 | 'redis' => [ 77 | 'driver' => 'redis', 78 | 'connection' => 'cache', 79 | 'lock_connection' => 'default', 80 | ], 81 | 82 | 'dynamodb' => [ 83 | 'driver' => 'dynamodb', 84 | 'key' => env('AWS_ACCESS_KEY_ID'), 85 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 86 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 87 | 'table' => env('DYNAMODB_CACHE_TABLE', 'cache'), 88 | 'endpoint' => env('DYNAMODB_ENDPOINT'), 89 | ], 90 | 91 | 'octane' => [ 92 | 'driver' => 'octane', 93 | ], 94 | 95 | ], 96 | 97 | /* 98 | |-------------------------------------------------------------------------- 99 | | Cache Key Prefix 100 | |-------------------------------------------------------------------------- 101 | | 102 | | When utilizing the APC, database, memcached, Redis, or DynamoDB cache 103 | | stores there might be other applications using the same cache. For 104 | | that reason, you may prefix every cache key to avoid collisions. 105 | | 106 | */ 107 | 108 | 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache_'), 109 | 110 | ]; 111 | -------------------------------------------------------------------------------- /config/cors.php: -------------------------------------------------------------------------------- 1 | ['api/*', 'sanctum/csrf-cookie'], 19 | 20 | 'allowed_methods' => ['*'], 21 | 22 | 'allowed_origins' => ['*'], 23 | 24 | 'allowed_origins_patterns' => [], 25 | 26 | 'allowed_headers' => ['*'], 27 | 28 | 'exposed_headers' => [], 29 | 30 | 'max_age' => 0, 31 | 32 | 'supports_credentials' => false, 33 | 34 | ]; 35 | -------------------------------------------------------------------------------- /config/filesystems.php: -------------------------------------------------------------------------------- 1 | env('FILESYSTEM_DISK', 'local'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Filesystem Disks 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure as many filesystem "disks" as you wish, and you 24 | | may even configure multiple disks of the same driver. Defaults have 25 | | been set up for each driver as an example of the required values. 26 | | 27 | | Supported Drivers: "local", "ftp", "sftp", "s3" 28 | | 29 | */ 30 | 31 | 'disks' => [ 32 | 33 | 'local' => [ 34 | 'driver' => 'local', 35 | 'root' => storage_path('app'), 36 | 'throw' => false, 37 | ], 38 | 39 | 'public' => [ 40 | 'driver' => 'local', 41 | 'root' => storage_path('app/public'), 42 | 'url' => env('APP_URL').'/storage', 43 | 'visibility' => 'public', 44 | 'throw' => false, 45 | ], 46 | 47 | 's3' => [ 48 | 'driver' => 's3', 49 | 'key' => env('AWS_ACCESS_KEY_ID'), 50 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 51 | 'region' => env('AWS_DEFAULT_REGION'), 52 | 'bucket' => env('AWS_BUCKET'), 53 | 'url' => env('AWS_URL'), 54 | 'endpoint' => env('AWS_ENDPOINT'), 55 | 'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false), 56 | 'throw' => false, 57 | ], 58 | 59 | ], 60 | 61 | /* 62 | |-------------------------------------------------------------------------- 63 | | Symbolic Links 64 | |-------------------------------------------------------------------------- 65 | | 66 | | Here you may configure the symbolic links that will be created when the 67 | | `storage:link` Artisan command is executed. The array keys should be 68 | | the locations of the links and the values should be their targets. 69 | | 70 | */ 71 | 72 | 'links' => [ 73 | public_path('storage') => storage_path('app/public'), 74 | ], 75 | 76 | ]; 77 | -------------------------------------------------------------------------------- /config/hashing.php: -------------------------------------------------------------------------------- 1 | 'bcrypt', 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Bcrypt Options 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may specify the configuration options that should be used when 26 | | passwords are hashed using the Bcrypt algorithm. This will allow you 27 | | to control the amount of time it takes to hash the given password. 28 | | 29 | */ 30 | 31 | 'bcrypt' => [ 32 | 'rounds' => env('BCRYPT_ROUNDS', 10), 33 | ], 34 | 35 | /* 36 | |-------------------------------------------------------------------------- 37 | | Argon Options 38 | |-------------------------------------------------------------------------- 39 | | 40 | | Here you may specify the configuration options that should be used when 41 | | passwords are hashed using the Argon algorithm. These will allow you 42 | | to control the amount of time it takes to hash the given password. 43 | | 44 | */ 45 | 46 | 'argon' => [ 47 | 'memory' => 65536, 48 | 'threads' => 1, 49 | 'time' => 4, 50 | ], 51 | 52 | ]; 53 | -------------------------------------------------------------------------------- /config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_MAILER', 'smtp'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Mailer Configurations 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure all of the mailers used by your application plus 24 | | their respective settings. Several examples have been configured for 25 | | you and you are free to add your own as your application requires. 26 | | 27 | | Laravel supports a variety of mail "transport" drivers to be used while 28 | | sending an e-mail. You will specify which one you are using for your 29 | | mailers below. You are free to add additional mailers as required. 30 | | 31 | | Supported: "smtp", "sendmail", "mailgun", "ses", "ses-v2", 32 | | "postmark", "log", "array", "failover" 33 | | 34 | */ 35 | 36 | 'mailers' => [ 37 | 'smtp' => [ 38 | 'transport' => 'smtp', 39 | 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 40 | 'port' => env('MAIL_PORT', 587), 41 | 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 42 | 'username' => env('MAIL_USERNAME'), 43 | 'password' => env('MAIL_PASSWORD'), 44 | 'timeout' => null, 45 | 'local_domain' => env('MAIL_EHLO_DOMAIN'), 46 | ], 47 | 48 | 'ses' => [ 49 | 'transport' => 'ses', 50 | ], 51 | 52 | 'mailgun' => [ 53 | 'transport' => 'mailgun', 54 | // 'client' => [ 55 | // 'timeout' => 5, 56 | // ], 57 | ], 58 | 59 | 'postmark' => [ 60 | 'transport' => 'postmark', 61 | // 'client' => [ 62 | // 'timeout' => 5, 63 | // ], 64 | ], 65 | 66 | 'sendmail' => [ 67 | 'transport' => 'sendmail', 68 | 'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'), 69 | ], 70 | 71 | 'log' => [ 72 | 'transport' => 'log', 73 | 'channel' => env('MAIL_LOG_CHANNEL'), 74 | ], 75 | 76 | 'array' => [ 77 | 'transport' => 'array', 78 | ], 79 | 80 | 'failover' => [ 81 | 'transport' => 'failover', 82 | 'mailers' => [ 83 | 'smtp', 84 | 'log', 85 | ], 86 | ], 87 | ], 88 | 89 | /* 90 | |-------------------------------------------------------------------------- 91 | | Global "From" Address 92 | |-------------------------------------------------------------------------- 93 | | 94 | | You may wish for all e-mails sent by your application to be sent from 95 | | the same address. Here, you may specify a name and address that is 96 | | used globally for all e-mails that are sent by your application. 97 | | 98 | */ 99 | 100 | 'from' => [ 101 | 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), 102 | 'name' => env('MAIL_FROM_NAME', 'Example'), 103 | ], 104 | 105 | /* 106 | |-------------------------------------------------------------------------- 107 | | Markdown Mail Settings 108 | |-------------------------------------------------------------------------- 109 | | 110 | | If you are using Markdown based email rendering, you may configure your 111 | | theme and component paths here, allowing you to customize the design 112 | | of the emails. Or, you may simply stick with the Laravel defaults! 113 | | 114 | */ 115 | 116 | 'markdown' => [ 117 | 'theme' => 'default', 118 | 119 | 'paths' => [ 120 | resource_path('views/vendor/mail'), 121 | ], 122 | ], 123 | 124 | ]; 125 | -------------------------------------------------------------------------------- /config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_CONNECTION', 'sync'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Queue Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure the connection information for each server that 24 | | is used by your application. A default configuration has been added 25 | | for each back-end shipped with Laravel. You are free to add more. 26 | | 27 | | Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null" 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'sync' => [ 34 | 'driver' => 'sync', 35 | ], 36 | 37 | 'database' => [ 38 | 'driver' => 'database', 39 | 'table' => 'jobs', 40 | 'queue' => 'default', 41 | 'retry_after' => 90, 42 | 'after_commit' => false, 43 | ], 44 | 45 | 'beanstalkd' => [ 46 | 'driver' => 'beanstalkd', 47 | 'host' => 'localhost', 48 | 'queue' => 'default', 49 | 'retry_after' => 90, 50 | 'block_for' => 0, 51 | 'after_commit' => false, 52 | ], 53 | 54 | 'sqs' => [ 55 | 'driver' => 'sqs', 56 | 'key' => env('AWS_ACCESS_KEY_ID'), 57 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 58 | 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), 59 | 'queue' => env('SQS_QUEUE', 'default'), 60 | 'suffix' => env('SQS_SUFFIX'), 61 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 62 | 'after_commit' => false, 63 | ], 64 | 65 | 'redis' => [ 66 | 'driver' => 'redis', 67 | 'connection' => 'default', 68 | 'queue' => env('REDIS_QUEUE', 'default'), 69 | 'retry_after' => 90, 70 | 'block_for' => null, 71 | 'after_commit' => false, 72 | ], 73 | 74 | ], 75 | 76 | /* 77 | |-------------------------------------------------------------------------- 78 | | Failed Queue Jobs 79 | |-------------------------------------------------------------------------- 80 | | 81 | | These options configure the behavior of failed queue job logging so you 82 | | can control which database and table are used to store the jobs that 83 | | have failed. You may change them to any database / table you wish. 84 | | 85 | */ 86 | 87 | 'failed' => [ 88 | 'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'), 89 | 'database' => env('DB_CONNECTION', 'mysql'), 90 | 'table' => 'failed_jobs', 91 | ], 92 | 93 | ]; 94 | -------------------------------------------------------------------------------- /config/quiz.php: -------------------------------------------------------------------------------- 1 | 60, 5 | ]; 6 | -------------------------------------------------------------------------------- /config/sanctum.php: -------------------------------------------------------------------------------- 1 | explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf( 19 | '%s%s', 20 | 'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1', 21 | Sanctum::currentApplicationUrlWithPort() 22 | ))), 23 | 24 | /* 25 | |-------------------------------------------------------------------------- 26 | | Sanctum Guards 27 | |-------------------------------------------------------------------------- 28 | | 29 | | This array contains the authentication guards that will be checked when 30 | | Sanctum is trying to authenticate a request. If none of these guards 31 | | are able to authenticate the request, Sanctum will use the bearer 32 | | token that's present on an incoming request for authentication. 33 | | 34 | */ 35 | 36 | 'guard' => ['web'], 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Expiration Minutes 41 | |-------------------------------------------------------------------------- 42 | | 43 | | This value controls the number of minutes until an issued token will be 44 | | considered expired. If this value is null, personal access tokens do 45 | | not expire. This won't tweak the lifetime of first-party sessions. 46 | | 47 | */ 48 | 49 | 'expiration' => null, 50 | 51 | /* 52 | |-------------------------------------------------------------------------- 53 | | Sanctum Middleware 54 | |-------------------------------------------------------------------------- 55 | | 56 | | When authenticating your first-party SPA with Sanctum you may need to 57 | | customize some of the middleware Sanctum uses while processing the 58 | | request. You may change the middleware listed below as required. 59 | | 60 | */ 61 | 62 | 'middleware' => [ 63 | 'verify_csrf_token' => App\Http\Middleware\VerifyCsrfToken::class, 64 | 'encrypt_cookies' => App\Http\Middleware\EncryptCookies::class, 65 | ], 66 | 67 | ]; 68 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'domain' => env('MAILGUN_DOMAIN'), 19 | 'secret' => env('MAILGUN_SECRET'), 20 | 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), 21 | 'scheme' => 'https', 22 | ], 23 | 24 | 'postmark' => [ 25 | 'token' => env('POSTMARK_TOKEN'), 26 | ], 27 | 28 | 'ses' => [ 29 | 'key' => env('AWS_ACCESS_KEY_ID'), 30 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 31 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 32 | ], 33 | 34 | 'github' => [ 35 | 'client_id' => env('GITHUB_CLIENT_ID'), 36 | 'client_secret' => env('GITHUB_CLIENT_SECRET'), 37 | 'redirect' => '/auth/github/callback', 38 | ], 39 | 40 | 'facebook' => [ 41 | 'client_id' => env('FACEBOOK_CLIENT_ID'), 42 | 'client_secret' => env('FACEBOOK_CLIENT_SECRET'), 43 | 'redirect' => '/auth/facebook/callback', 44 | ], 45 | 46 | 'google' => [ 47 | 'client_id' => env('GOOGLE_CLIENT_ID'), 48 | 'client_secret' => env('GOOGLE_CLIENT_SECRET'), 49 | 'redirect' => '/auth/google/callback', 50 | ], 51 | 52 | ]; 53 | -------------------------------------------------------------------------------- /config/view.php: -------------------------------------------------------------------------------- 1 | [ 17 | resource_path('views'), 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled View Path 23 | |-------------------------------------------------------------------------- 24 | | 25 | | This option determines where all the compiled Blade templates will be 26 | | stored for your application. Typically, this is within the storage 27 | | directory. However, as usual, you are free to change this value. 28 | | 29 | */ 30 | 31 | 'compiled' => env( 32 | 'VIEW_COMPILED_PATH', 33 | realpath(storage_path('framework/views')) 34 | ), 35 | 36 | ]; 37 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite* 2 | -------------------------------------------------------------------------------- /database/factories/QuestionFactory.php: -------------------------------------------------------------------------------- 1 | 9 | */ 10 | class QuestionFactory extends Factory 11 | { 12 | /** 13 | * Define the model's default state. 14 | * 15 | * @return array 16 | */ 17 | public function definition(): array 18 | { 19 | return [ 20 | 'question_text' => fake()->paragraph(), 21 | ]; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /database/factories/QuestionOptionFactory.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | class QuestionOptionFactory extends Factory 12 | { 13 | /** 14 | * Define the model's default state. 15 | * 16 | * @return array 17 | */ 18 | public function definition(): array 19 | { 20 | return [ 21 | 'option' => fake()->text(), 22 | 'correct' => fake()->boolean(), 23 | 'question_id' => Question::factory(), 24 | ]; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /database/factories/QuizFactory.php: -------------------------------------------------------------------------------- 1 | 10 | */ 11 | class QuizFactory extends Factory 12 | { 13 | /** 14 | * Define the model's default state. 15 | * 16 | * @return array 17 | */ 18 | public function definition(): array 19 | { 20 | $title = $this->faker->sentence(); 21 | $slug = Str::slug($title); 22 | 23 | return [ 24 | 'title' => $title, 25 | 'slug' => $slug, 26 | 'description' => fake()->paragraph(), 27 | 'published' => false, 28 | 'public' => false, 29 | ]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | 11 | */ 12 | class UserFactory extends Factory 13 | { 14 | /** 15 | * Define the model's default state. 16 | * 17 | * @return array 18 | */ 19 | public function definition(): array 20 | { 21 | return [ 22 | 'name' => fake()->name(), 23 | 'email' => fake()->unique()->safeEmail(), 24 | 'email_verified_at' => now(), 25 | 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 26 | 'remember_token' => Str::random(10), 27 | ]; 28 | } 29 | 30 | /** 31 | * Indicate that the model's email address should be unverified. 32 | */ 33 | public function unverified(): static 34 | { 35 | return $this->state(fn (array $attributes) => [ 36 | 'email_verified_at' => null, 37 | ]); 38 | } 39 | 40 | public function admin(): static 41 | { 42 | return $this->afterCreating(fn (User $user) => $user->update(['is_admin' => true])); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('name')->default(''); 17 | $table->string('email')->unique(); 18 | $table->timestamp('email_verified_at')->nullable(); 19 | $table->string('password'); 20 | $table->rememberToken(); 21 | $table->timestamps(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | */ 28 | public function down(): void 29 | { 30 | Schema::dropIfExists('users'); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_100000_create_password_reset_tokens_table.php: -------------------------------------------------------------------------------- 1 | string('email')->primary(); 16 | $table->string('token'); 17 | $table->timestamp('created_at')->nullable(); 18 | }); 19 | } 20 | 21 | /** 22 | * Reverse the migrations. 23 | */ 24 | public function down(): void 25 | { 26 | Schema::dropIfExists('password_reset_tokens'); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /database/migrations/2019_08_19_000000_create_failed_jobs_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('uuid')->unique(); 17 | $table->text('connection'); 18 | $table->text('queue'); 19 | $table->longText('payload'); 20 | $table->longText('exception'); 21 | $table->timestamp('failed_at')->useCurrent(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | */ 28 | public function down(): void 29 | { 30 | Schema::dropIfExists('failed_jobs'); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->morphs('tokenable'); 17 | $table->string('name'); 18 | $table->string('token', 64)->unique(); 19 | $table->text('abilities')->nullable(); 20 | $table->timestamp('last_used_at')->nullable(); 21 | $table->timestamp('expires_at')->nullable(); 22 | $table->timestamps(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | */ 29 | public function down(): void 30 | { 31 | Schema::dropIfExists('personal_access_tokens'); 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /database/migrations/2023_04_04_074741_add_socialite_fields_to_users_table.php: -------------------------------------------------------------------------------- 1 | after('password', function (Blueprint $table) { 16 | $table->string('facebook_id')->nullable(); 17 | $table->string('google_id')->nullable(); 18 | $table->string('github_id')->nullable(); 19 | }); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | */ 26 | public function down(): void 27 | { 28 | Schema::table('users', function (Blueprint $table) { 29 | // 30 | }); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /database/migrations/2023_04_04_075435_add_is_admin_to_users_table.php: -------------------------------------------------------------------------------- 1 | boolean('is_admin')->default(false)->after('password'); 16 | }); 17 | } 18 | 19 | /** 20 | * Reverse the migrations. 21 | */ 22 | public function down(): void 23 | { 24 | Schema::table('users', function (Blueprint $table) { 25 | // 26 | }); 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /database/migrations/2023_04_04_075728_create_questions_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->text('question_text'); 17 | $table->text('code_snippet')->nullable(); 18 | $table->text('answer_explanation')->nullable(); 19 | $table->string('more_info_link')->nullable(); 20 | $table->timestamps(); 21 | $table->softDeletes(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | */ 28 | public function down(): void 29 | { 30 | Schema::dropIfExists('questions'); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /database/migrations/2023_04_04_103300_create_question_options_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('option'); 17 | $table->boolean('correct')->default(0)->nullable(); 18 | $table->foreignId('question_id')->nullable()->constrained(); 19 | $table->timestamps(); 20 | $table->softDeletes(); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | */ 27 | public function down(): void 28 | { 29 | Schema::dropIfExists('question_options'); 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /database/migrations/2023_04_04_104015_create_quizzes_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->string('title'); 17 | $table->string('slug')->nullable(); 18 | $table->longText('description')->nullable(); 19 | $table->boolean('published')->default(0)->nullable(); 20 | $table->boolean('public')->default(0)->nullable(); 21 | $table->timestamps(); 22 | $table->softDeletes(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | */ 29 | public function down(): void 30 | { 31 | Schema::dropIfExists('quizzes'); 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /database/migrations/2023_04_04_113312_create_question_quiz_table.php: -------------------------------------------------------------------------------- 1 | foreignId('question_id')->constrained()->cascadeOnDelete(); 16 | $table->foreignId('quiz_id')->constrained()->cascadeOnDelete(); 17 | }); 18 | } 19 | 20 | /** 21 | * Reverse the migrations. 22 | */ 23 | public function down(): void 24 | { 25 | Schema::dropIfExists('question_quiz'); 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /database/migrations/2023_04_05_133738_create_tests_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->integer('result')->nullable(); 17 | $table->string('ip_address')->nullable(); 18 | $table->integer('time_spent')->nullable(); 19 | $table->foreignId('user_id')->nullable()->constrained(); 20 | $table->foreignId('quiz_id')->nullable()->constrained(); 21 | $table->timestamps(); 22 | $table->softDeletes(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | */ 29 | public function down(): void 30 | { 31 | Schema::dropIfExists('tests'); 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /database/migrations/2023_04_05_133752_create_test_answers_table.php: -------------------------------------------------------------------------------- 1 | id(); 16 | $table->boolean('correct')->default(0)->nullable(); 17 | $table->foreignId('user_id')->nullable()->constrained(); 18 | $table->foreignId('test_id')->nullable()->constrained(); 19 | $table->foreignId('question_id')->nullable()->constrained(); 20 | $table->foreignId('option_id')->nullable()->references('id')->on('question_options'); 21 | $table->timestamps(); 22 | $table->softDeletes(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | */ 29 | public function down(): void 30 | { 31 | Schema::dropIfExists('test_answers'); 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /database/seeders/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | create(); 16 | 17 | // \App\Models\User::factory()->create([ 18 | // 'name' => 'Test User', 19 | // 'email' => 'test@example.com', 20 | // ]); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "dev": "vite", 5 | "build": "vite build" 6 | }, 7 | "devDependencies": { 8 | "@tailwindcss/forms": "^0.5.2", 9 | "alpinejs": "^3.4.2", 10 | "autoprefixer": "^10.4.2", 11 | "axios": "^1.1.2", 12 | "laravel-vite-plugin": "^0.7.2", 13 | "postcss": "^8.4.6", 14 | "tailwindcss": "^3.1.0", 15 | "vite": "^4.0.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | ./tests/Unit 8 | 9 | 10 | ./tests/Feature 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | ./app 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | }; 7 | -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews -Indexes 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Handle Authorization Header 9 | RewriteCond %{HTTP:Authorization} . 10 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 11 | 12 | # Redirect Trailing Slashes If Not A Folder... 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | RewriteCond %{REQUEST_URI} (.+)/$ 15 | RewriteRule ^ %1 [L,R=301] 16 | 17 | # Send Requests To Front Controller... 18 | RewriteCond %{REQUEST_FILENAME} !-d 19 | RewriteCond %{REQUEST_FILENAME} !-f 20 | RewriteRule ^ index.php [L] 21 | 22 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LaravelDaily/Livewire-Laraquiz-Course/7128a245bba68bb3616dd6456bfc9dcca11421ea/public/favicon.ico -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | make(Kernel::class); 50 | 51 | $response = $kernel->handle( 52 | $request = Request::capture() 53 | )->send(); 54 | 55 | $kernel->terminate($request, $response); 56 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /resources/css/app.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | /* Select 2 */ 6 | .select2 { 7 | @apply w-full border-0 placeholder-gray-300 text-gray-600 bg-white rounded text-sm shadow focus:outline-none focus:ring !important; 8 | } 9 | 10 | .select2-dropdown { 11 | @apply absolute block w-auto box-border bg-white shadow-lg border-blue-200 z-50 float-left; 12 | } 13 | 14 | .select2-container--default .select2-selection--single { 15 | @apply border-0 h-11 flex items-center text-sm 16 | } 17 | 18 | .select2-container--default .select2-selection--multiple { 19 | @apply border-0 text-sm mr-1 20 | } 21 | 22 | .select2-container--default.select2-container--focus .select2-selection--single, 23 | .select2-container--default.select2-container--focus .select2-selection--multiple { 24 | @apply border-0 outline-none ring ring-indigo-500 25 | } 26 | 27 | .select2-container--default .select2-selection--single .select2-selection__arrow { 28 | top: 9px; 29 | } 30 | 31 | .select2-container .select2-selection--single .select2-selection__rendered { 32 | @apply px-3 py-3 text-blue-600 33 | } 34 | 35 | .select2-container .select2-selection--multiple .select2-selection__rendered { 36 | @apply px-3 py-2 text-blue-600 37 | } 38 | 39 | .select2-container--default .select2-selection--single .select2-selection__rendered { 40 | line-height: inherit; 41 | } 42 | 43 | .select2-selection__choice { 44 | @apply text-xs font-semibold inline-block py-1 px-2 rounded bg-gray-800 border-0 !important; 45 | } 46 | 47 | .select2-selection__choice span { 48 | @apply text-white !important; 49 | } 50 | 51 | .select2-search__field:focus { 52 | outline: none; 53 | } 54 | 55 | .select2-container--default .select2-selection--single .select2-selection__clear { 56 | @apply text-rose-500 ml-1 !important 57 | } 58 | 59 | .select2-container--default .select2-selection--multiple .select2-selection__choice__remove { 60 | @apply text-gray-300 mr-1 static !important 61 | } 62 | 63 | .select2-container--default .select2-selection--multiple .select2-selection__choice__remove:hover { 64 | @apply bg-gray-600 !important 65 | } 66 | 67 | .select-all, .deselect-all { 68 | @apply cursor-pointer; 69 | font-size: 0.5rem !important; 70 | } 71 | -------------------------------------------------------------------------------- /resources/js/app.js: -------------------------------------------------------------------------------- 1 | import './bootstrap'; 2 | -------------------------------------------------------------------------------- /resources/js/bootstrap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * We'll load the axios HTTP library which allows us to easily issue requests 3 | * to our Laravel back-end. This library automatically handles sending the 4 | * CSRF token as a header based on the value of the "XSRF" token cookie. 5 | */ 6 | 7 | import axios from 'axios'; 8 | window.axios = axios; 9 | 10 | window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 11 | 12 | /** 13 | * Echo exposes an expressive API for subscribing to channels and listening 14 | * for events that are broadcast by Laravel. Echo and event broadcasting 15 | * allows your team to easily build robust real-time web applications. 16 | */ 17 | 18 | // import Echo from 'laravel-echo'; 19 | 20 | // import Pusher from 'pusher-js'; 21 | // window.Pusher = Pusher; 22 | 23 | // window.Echo = new Echo({ 24 | // broadcaster: 'pusher', 25 | // key: import.meta.env.VITE_PUSHER_APP_KEY, 26 | // cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER ?? 'mt1', 27 | // wsHost: import.meta.env.VITE_PUSHER_HOST ? import.meta.env.VITE_PUSHER_HOST : `ws-${import.meta.env.VITE_PUSHER_APP_CLUSTER}.pusher.com`, 28 | // wsPort: import.meta.env.VITE_PUSHER_PORT ?? 80, 29 | // wssPort: import.meta.env.VITE_PUSHER_PORT ?? 443, 30 | // forceTLS: (import.meta.env.VITE_PUSHER_SCHEME ?? 'https') === 'https', 31 | // enabledTransports: ['ws', 'wss'], 32 | // }); 33 | -------------------------------------------------------------------------------- /resources/views/auth/confirm-password.blade.php: -------------------------------------------------------------------------------- 1 | 2 |
3 | {{ __('This is a secure area of the application. Please confirm your password before continuing.') }} 4 |
5 | 6 |
7 | @csrf 8 | 9 | 10 |
11 | 12 | 13 | 17 | 18 | 19 |
20 | 21 |
22 | 23 | {{ __('Confirm') }} 24 | 25 |
26 |
27 |
28 | -------------------------------------------------------------------------------- /resources/views/auth/forgot-password.blade.php: -------------------------------------------------------------------------------- 1 | 2 |
3 | {{ __('Forgot your password? No problem. Just let us know your email address and we will email you a password reset link that will allow you to choose a new one.') }} 4 |
5 | 6 | 7 | 8 | 9 |
10 | @csrf 11 | 12 | 13 |
14 | 15 | 16 | 17 |
18 | 19 |
20 | 21 | {{ __('Email Password Reset Link') }} 22 | 23 |
24 |
25 |
26 | -------------------------------------------------------------------------------- /resources/views/auth/login.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | @csrf 7 | 8 | 9 |
10 | 11 | 12 | 13 |
14 | 15 | 16 |
17 | 18 | 19 | 23 | 24 | 25 |
26 | 27 | 28 |
29 | 33 |
34 | 35 |
36 | @if (Route::has('password.request')) 37 | 38 | {{ __('Forgot your password?') }} 39 | 40 | @endif 41 | 42 | 43 | {{ __('Log in') }} 44 | 45 |
46 |
47 | 48 | 49 |
50 | -------------------------------------------------------------------------------- /resources/views/auth/register.blade.php: -------------------------------------------------------------------------------- 1 | 2 |
3 | @csrf 4 | 5 | 6 |
7 | 8 | 9 | 10 |
11 | 12 | 13 |
14 | 15 | 16 | 17 |
18 | 19 | 20 |
21 | 22 | 23 | 27 | 28 | 29 |
30 | 31 | 32 |
33 | 34 | 35 | 38 | 39 | 40 |
41 | 42 |
43 | 44 | {{ __('Already registered?') }} 45 | 46 | 47 | 48 | {{ __('Register') }} 49 | 50 |
51 |
52 | 53 | 54 |
55 | -------------------------------------------------------------------------------- /resources/views/auth/reset-password.blade.php: -------------------------------------------------------------------------------- 1 | 2 |
3 | @csrf 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 |
14 | 15 | 16 |
17 | 18 | 19 | 20 |
21 | 22 | 23 |
24 | 25 | 26 | 29 | 30 | 31 |
32 | 33 |
34 | 35 | {{ __('Reset Password') }} 36 | 37 |
38 |
39 |
40 | -------------------------------------------------------------------------------- /resources/views/auth/verify-email.blade.php: -------------------------------------------------------------------------------- 1 | 2 |
3 | {{ __('Thanks for signing up! Before getting started, could you verify your email address by clicking on the link we just emailed to you? If you didn\'t receive the email, we will gladly send you another.') }} 4 |
5 | 6 | @if (session('status') == 'verification-link-sent') 7 |
8 | {{ __('A new verification link has been sent to the email address you provided during registration.') }} 9 |
10 | @endif 11 | 12 |
13 |
14 | @csrf 15 | 16 |
17 | 18 | {{ __('Resend Verification Email') }} 19 | 20 |
21 |
22 | 23 |
24 | @csrf 25 | 26 | 29 |
30 |
31 |
32 | -------------------------------------------------------------------------------- /resources/views/components/application-logo.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources/views/components/auth-session-status.blade.php: -------------------------------------------------------------------------------- 1 | @props(['status']) 2 | 3 | @if ($status) 4 |
merge(['class' => 'font-medium text-sm text-green-600']) }}> 5 | {{ $status }} 6 |
7 | @endif 8 | -------------------------------------------------------------------------------- /resources/views/components/danger-button.blade.php: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /resources/views/components/dropdown-link.blade.php: -------------------------------------------------------------------------------- 1 | merge(['class' => 'block w-full px-4 py-2 text-left text-sm leading-5 text-gray-700 hover:bg-gray-100 focus:outline-none focus:bg-gray-100 transition duration-150 ease-in-out']) }}>{{ $slot }} 2 | -------------------------------------------------------------------------------- /resources/views/components/dropdown.blade.php: -------------------------------------------------------------------------------- 1 | @props(['align' => 'right', 'width' => '48', 'contentClasses' => 'py-1 bg-white']) 2 | 3 | @php 4 | switch ($align) { 5 | case 'left': 6 | $alignmentClasses = 'origin-top-left left-0'; 7 | break; 8 | case 'top': 9 | $alignmentClasses = 'origin-top'; 10 | break; 11 | case 'right': 12 | default: 13 | $alignmentClasses = 'origin-top-right right-0'; 14 | break; 15 | } 16 | 17 | switch ($width) { 18 | case '48': 19 | $width = 'w-48'; 20 | break; 21 | } 22 | @endphp 23 | 24 |
25 |
26 | {{ $trigger }} 27 |
28 | 29 | 43 |
44 | -------------------------------------------------------------------------------- /resources/views/components/input-error.blade.php: -------------------------------------------------------------------------------- 1 | @props(['messages']) 2 | 3 | @if ($messages) 4 |
    merge(['class' => 'text-sm text-red-600 space-y-1']) }}> 5 | @foreach ((array) $messages as $message) 6 |
  • {{ $message }}
  • 7 | @endforeach 8 |
9 | @endif 10 | -------------------------------------------------------------------------------- /resources/views/components/input-label.blade.php: -------------------------------------------------------------------------------- 1 | @props(['value']) 2 | 3 | 6 | -------------------------------------------------------------------------------- /resources/views/components/modal.blade.php: -------------------------------------------------------------------------------- 1 | @props([ 2 | 'name', 3 | 'show' => false, 4 | 'maxWidth' => '2xl' 5 | ]) 6 | 7 | @php 8 | $maxWidth = [ 9 | 'sm' => 'sm:max-w-sm', 10 | 'md' => 'sm:max-w-md', 11 | 'lg' => 'sm:max-w-lg', 12 | 'xl' => 'sm:max-w-xl', 13 | '2xl' => 'sm:max-w-2xl', 14 | ][$maxWidth]; 15 | @endphp 16 | 17 |
51 |
62 |
63 |
64 | 65 |
75 | {{ $slot }} 76 |
77 |
78 | -------------------------------------------------------------------------------- /resources/views/components/nav-link.blade.php: -------------------------------------------------------------------------------- 1 | @props(['active']) 2 | 3 | @php 4 | $classes = ($active ?? false) 5 | ? 'inline-flex items-center px-1 pt-1 border-b-2 border-indigo-400 text-sm font-medium leading-5 text-gray-900 focus:outline-none focus:border-indigo-700 transition duration-150 ease-in-out' 6 | : 'inline-flex items-center px-1 pt-1 border-b-2 border-transparent text-sm font-medium leading-5 text-gray-500 hover:text-gray-700 hover:border-gray-300 focus:outline-none focus:text-gray-700 focus:border-gray-300 transition duration-150 ease-in-out'; 7 | @endphp 8 | 9 | merge(['class' => $classes]) }}> 10 | {{ $slot }} 11 | 12 | -------------------------------------------------------------------------------- /resources/views/components/primary-button.blade.php: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /resources/views/components/responsive-nav-link.blade.php: -------------------------------------------------------------------------------- 1 | @props(['active']) 2 | 3 | @php 4 | $classes = ($active ?? false) 5 | ? 'block w-full pl-3 pr-4 py-2 border-l-4 border-indigo-400 text-left text-base font-medium text-indigo-700 bg-indigo-50 focus:outline-none focus:text-indigo-800 focus:bg-indigo-100 focus:border-indigo-700 transition duration-150 ease-in-out' 6 | : 'block w-full pl-3 pr-4 py-2 border-l-4 border-transparent text-left text-base font-medium text-gray-600 hover:text-gray-800 hover:bg-gray-50 hover:border-gray-300 focus:outline-none focus:text-gray-800 focus:bg-gray-50 focus:border-gray-300 transition duration-150 ease-in-out'; 7 | @endphp 8 | 9 | merge(['class' => $classes]) }}> 10 | {{ $slot }} 11 | 12 | -------------------------------------------------------------------------------- /resources/views/components/secondary-button.blade.php: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /resources/views/components/select-list.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | 11 |
12 |
13 | 14 | @push('scripts') 15 | 39 | @endpush 40 | -------------------------------------------------------------------------------- /resources/views/components/social-links.blade.php: -------------------------------------------------------------------------------- 1 | 14 | -------------------------------------------------------------------------------- /resources/views/components/text-input.blade.php: -------------------------------------------------------------------------------- 1 | @props(['disabled' => false]) 2 | 3 | merge(['class' => 'border-gray-300 focus:border-indigo-500 focus:ring-indigo-500 rounded-md shadow-sm']) !!}> 4 | -------------------------------------------------------------------------------- /resources/views/components/textarea.blade.php: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/views/dashboard.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 |

4 | {{ __('Dashboard') }} 5 |

6 |
7 | 8 |
9 |
10 |
11 |
12 | {{ __("You're logged in!") }} 13 |
14 |
15 |
16 |
17 |
18 | -------------------------------------------------------------------------------- /resources/views/front/quizzes/show.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 |

4 | {{ $quiz->title }} 5 |

6 |
7 | 8 |
9 |
10 |
11 |
12 | @if (! $quiz->public && ! auth()->check()) 13 |
14 | 15 | This test is available only for registered users. Please Log in or Register 16 | 17 |
18 | @else 19 | 20 | @endif 21 |
22 |
23 |
24 |
25 |
26 | -------------------------------------------------------------------------------- /resources/views/front/results/index.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 |

4 | My Results 5 |

6 |
7 | 8 |
9 |
10 |
11 |
12 |
13 | 14 | 15 | 16 | 18 | 21 | 24 | 27 | 29 | 30 | 31 | 32 | 33 | @forelse($results as $result) 34 | 35 | 38 | 41 | 44 | 47 | 52 | 53 | @empty 54 | 55 | 58 | 59 | @endforelse 60 | 61 |
17 | 19 | Quiz Title 20 | 22 | Date 23 | 25 | Result 26 | 28 |
36 | {{ $loop->iteration }} 37 | 39 | {{ $result->quiz->title }} 40 | 42 | {{ $result->created_at }} 43 | 45 | {{ $result->result.'/'.$result->questions_count }} 46 | 48 | 49 | View 50 | 51 |
56 | No results were found. 57 |
62 |
63 | 64 | {{ $results->links() }} 65 |
66 |
67 |
68 |
69 |
70 | -------------------------------------------------------------------------------- /resources/views/home.blade.php: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 |
5 |
6 |
Public quizzes
7 | 8 | @forelse($public as $quiz) 9 |
10 |
11 |
12 | {{ $quiz->title }} 13 |

Questions: {{ $quiz->questions_count }}

14 |
15 |
16 |
17 | @empty 18 |
No public quizzes found.
19 | @endforelse 20 |
21 |
22 |
23 |
24 | 25 |
26 |
27 |
28 |
29 |
Quizzes for Registered Users
30 | 31 | @forelse($registered as $quiz) 32 |
33 |
34 |
35 | {{ $quiz->title }} 36 |

Questions: {{ $quiz->questions_count }}

37 |
38 |
39 |
40 | @empty 41 |
No quizzes for registered users found.
42 | @endforelse 43 |
44 |
45 |
46 |
47 |
48 | -------------------------------------------------------------------------------- /resources/views/layouts/app.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | {{ config('app.name', 'Laravel') }} 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | @vite(['resources/css/app.css', 'resources/js/app.js']) 17 | @livewireStyles 18 | 19 | 20 |
21 | @include('layouts.navigation') 22 | 23 | 24 | @if (isset($header)) 25 |
26 |
27 | {{ $header }} 28 |
29 |
30 | @endif 31 | 32 | 33 |
34 | {{ $slot }} 35 |
36 |
37 | 38 | 39 | 40 | @livewireScripts 41 | @stack('scripts') 42 | 43 | 44 | -------------------------------------------------------------------------------- /resources/views/layouts/guest.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | {{ config('app.name', 'Laravel') }} 9 | 10 | 11 | 12 | 13 | 14 | 15 | @vite(['resources/css/app.css', 'resources/js/app.js']) 16 | 17 | 18 |
19 |
20 | 21 | 22 | 23 |
24 | 25 |
26 | {{ $slot }} 27 |
28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /resources/views/livewire/front/leaderboard.blade.php: -------------------------------------------------------------------------------- 1 |
2 | 3 |

4 | Leaderboard 5 |

6 |
7 | 8 |
9 |
10 |
11 |
12 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 29 | 30 | 31 | 32 | @forelse ($users as $user) 33 | auth()->check() && $user->name == auth()->user()->name])> 34 | 37 | 40 | 44 | 45 | @empty 46 | 47 | 48 | 49 | @endforelse 50 | 51 |
24 | Username 25 | 27 | Correct answers 28 |
35 | {{ $loop->iteration }} 36 | 38 | {{ $user->name }} 39 | 41 | {{ $user->correct }} / {{ $total_questions }} 42 | (time: {{ intval($user->time_spent / 60) }}:{{ gmdate('s', $user->time_spent) }} minutes) 43 |
No results.
52 |
53 |
54 |
55 |
56 |
57 | -------------------------------------------------------------------------------- /resources/views/livewire/front/quizzes/show.blade.php: -------------------------------------------------------------------------------- 1 |
4 | 5 |
6 | Time left for this question: sec. 7 |
8 | 9 | Question {{ $currentQuestionIndex + 1 }} of {{ $this->questionsCount }}: 10 |

{{ $currentQuestion->question_text }}

11 | 12 | @if ($currentQuestion->code_snippet) 13 |
{{ $currentQuestion->code_snippet }}
14 | @endif 15 | 16 | @foreach($currentQuestion->questionOptions as $option) 17 |
18 | 26 |
27 | @endforeach 28 | 29 | @if ($currentQuestionIndex < $this->questionsCount - 1) 30 |
31 | 32 | Next question 33 | 34 |
35 | @else 36 |
37 | Submit 38 |
39 | @endif 40 |
41 | -------------------------------------------------------------------------------- /resources/views/livewire/questions/question-form.blade.php: -------------------------------------------------------------------------------- 1 |
2 | 3 |

4 | {{ $editing ? 'Edit Question' : 'Create Question' }} 5 |

6 |
7 | 8 |
9 |
10 |
11 |
12 |
13 |
14 | 15 | 16 | 17 |
18 | 19 |
20 | 21 | @foreach($questionOptions as $index => $questionOption) 22 |
23 | 24 | 25 |
26 | Correct 27 | 30 |
31 |
32 | 33 | @endforeach 34 | 35 | 36 | 37 | 38 | Add 39 | 40 |
41 | 42 |
43 | 44 | 45 | 46 |
47 | 48 |
49 | 50 | 51 | 52 |
53 | 54 |
55 | 56 | 57 | 58 |
59 | 60 |
61 | 62 | Save 63 | 64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | -------------------------------------------------------------------------------- /resources/views/livewire/questions/question-list.blade.php: -------------------------------------------------------------------------------- 1 |
2 | 3 |

4 | Questions 5 |

6 |
7 | 8 |
9 |
10 |
11 |
12 | 18 | 19 |
20 | 21 | 22 | 23 | 25 | 28 | 30 | 31 | 32 | 33 | 34 | @forelse($questions as $question) 35 | 36 | 39 | 42 | 50 | 51 | @empty 52 | 53 | 56 | 57 | @endforelse 58 | 59 |
24 | 26 | Question text 27 | 29 |
37 | {{ $question->id }} 38 | 40 | {{ $question->question_text }} 41 | 43 | 44 | Edit 45 | 46 | 49 |
54 | No questions were found. 55 |
60 |
61 | 62 | {{ $questions->links() }} 63 |
64 |
65 |
66 |
67 |
68 | -------------------------------------------------------------------------------- /resources/views/livewire/quiz/quiz-form.blade.php: -------------------------------------------------------------------------------- 1 |
2 | 3 |

4 | {{ $editing ? 'Edit Quiz' : 'Create Quiz' }} 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 | Save 56 | 57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | -------------------------------------------------------------------------------- /resources/views/profile/edit.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 |

4 | {{ __('Profile') }} 5 |

6 |
7 | 8 |
9 |
10 |
11 |
12 | @include('profile.partials.update-profile-information-form') 13 |
14 |
15 | 16 |
17 |
18 | @include('profile.partials.update-password-form') 19 |
20 |
21 | 22 |
23 |
24 | @include('profile.partials.delete-user-form') 25 |
26 |
27 |
28 |
29 |
30 | -------------------------------------------------------------------------------- /resources/views/profile/partials/delete-user-form.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |

4 | {{ __('Delete Account') }} 5 |

6 | 7 |

8 | {{ __('Once your account is deleted, all of its resources and data will be permanently deleted. Before deleting your account, please download any data or information that you wish to retain.') }} 9 |

10 |
11 | 12 | {{ __('Delete Account') }} 16 | 17 | 18 |
19 | @csrf 20 | @method('delete') 21 | 22 |

23 | {{ __('Are you sure you want to delete your account?') }} 24 |

25 | 26 |

27 | {{ __('Once your account is deleted, all of its resources and data will be permanently deleted. Please enter your password to confirm you would like to permanently delete your account.') }} 28 |

29 | 30 |
31 | 32 | 33 | 40 | 41 | 42 |
43 | 44 |
45 | 46 | {{ __('Cancel') }} 47 | 48 | 49 | 50 | {{ __('Delete Account') }} 51 | 52 |
53 |
54 |
55 |
56 | -------------------------------------------------------------------------------- /resources/views/profile/partials/update-password-form.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |

4 | {{ __('Update Password') }} 5 |

6 | 7 |

8 | {{ __('Ensure your account is using a long, random password to stay secure.') }} 9 |

10 |
11 | 12 |
13 | @csrf 14 | @method('put') 15 | 16 |
17 | 18 | 19 | 20 |
21 | 22 |
23 | 24 | 25 | 26 |
27 | 28 |
29 | 30 | 31 | 32 |
33 | 34 |
35 | {{ __('Save') }} 36 | 37 | @if (session('status') === 'password-updated') 38 |

{{ __('Saved.') }}

45 | @endif 46 |
47 |
48 |
49 | -------------------------------------------------------------------------------- /resources/views/profile/partials/update-profile-information-form.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |

4 | {{ __('Profile Information') }} 5 |

6 | 7 |

8 | {{ __("Update your account's profile information and email address.") }} 9 |

10 |
11 | 12 |
13 | @csrf 14 |
15 | 16 |
17 | @csrf 18 | @method('patch') 19 | 20 |
21 | 22 | 23 | 24 |
25 | 26 |
27 | 28 | 29 | 30 | 31 | @if ($user instanceof \Illuminate\Contracts\Auth\MustVerifyEmail && ! $user->hasVerifiedEmail()) 32 |
33 |

34 | {{ __('Your email address is unverified.') }} 35 | 36 | 39 |

40 | 41 | @if (session('status') === 'verification-link-sent') 42 |

43 | {{ __('A new verification link has been sent to your email address.') }} 44 |

45 | @endif 46 |
47 | @endif 48 |
49 | 50 |
51 | {{ __('Save') }} 52 | 53 | @if (session('status') === 'profile-updated') 54 |

{{ __('Saved.') }}

61 | @endif 62 |
63 |
64 |
65 | -------------------------------------------------------------------------------- /routes/App/Http/Livewire/Questions/Index.php: -------------------------------------------------------------------------------- 1 | get('/user', function (Request $request) { 18 | return $request->user(); 19 | }); 20 | -------------------------------------------------------------------------------- /routes/auth.php: -------------------------------------------------------------------------------- 1 | group(function () { 16 | Route::get('register', [RegisteredUserController::class, 'create']) 17 | ->name('register'); 18 | 19 | Route::post('register', [RegisteredUserController::class, 'store']); 20 | 21 | Route::get('login', [AuthenticatedSessionController::class, 'create']) 22 | ->name('login'); 23 | 24 | Route::post('login', [AuthenticatedSessionController::class, 'store']); 25 | 26 | Route::get('forgot-password', [PasswordResetLinkController::class, 'create']) 27 | ->name('password.request'); 28 | 29 | Route::post('forgot-password', [PasswordResetLinkController::class, 'store']) 30 | ->name('password.email'); 31 | 32 | Route::get('reset-password/{token}', [NewPasswordController::class, 'create']) 33 | ->name('password.reset'); 34 | 35 | Route::post('reset-password', [NewPasswordController::class, 'store']) 36 | ->name('password.store'); 37 | 38 | Route::get('auth/{provider}/redirect', [SocialiteController::class, 'loginSocial']) 39 | ->name('socialite.auth'); 40 | 41 | Route::get('auth/{provider}/callback', [SocialiteController::class, 'callbackSocial']) 42 | ->name('socialite.callback'); 43 | }); 44 | 45 | Route::middleware('auth')->group(function () { 46 | Route::get('verify-email', EmailVerificationPromptController::class) 47 | ->name('verification.notice'); 48 | 49 | Route::get('verify-email/{id}/{hash}', VerifyEmailController::class) 50 | ->middleware(['signed', 'throttle:6,1']) 51 | ->name('verification.verify'); 52 | 53 | Route::post('email/verification-notification', [EmailVerificationNotificationController::class, 'store']) 54 | ->middleware('throttle:6,1') 55 | ->name('verification.send'); 56 | 57 | Route::get('confirm-password', [ConfirmablePasswordController::class, 'show']) 58 | ->name('password.confirm'); 59 | 60 | Route::post('confirm-password', [ConfirmablePasswordController::class, 'store']); 61 | 62 | Route::put('password', [PasswordController::class, 'update'])->name('password.update'); 63 | 64 | Route::post('logout', [AuthenticatedSessionController::class, 'destroy']) 65 | ->name('logout'); 66 | }); 67 | -------------------------------------------------------------------------------- /routes/channels.php: -------------------------------------------------------------------------------- 1 | id === (int) $id; 18 | }); 19 | -------------------------------------------------------------------------------- /routes/console.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 19 | })->purpose('Display an inspiring quote'); 20 | -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | name('home'); 26 | Route::get('quiz/{quiz}/{slug?}', [HomeController::class, 'show'])->name('quiz.show'); 27 | Route::get('results/{test}', [ResultController::class, 'show'])->name('results.show'); 28 | Route::get('leaderboard', Leaderboard::class)->name('leaderboard'); 29 | 30 | Route::middleware('auth')->group(function () { 31 | Route::get('results', [ResultController::class, 'index'])->name('results.index'); 32 | 33 | Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit'); 34 | Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update'); 35 | Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy'); 36 | 37 | Route::middleware('isAdmin')->group(function () { 38 | Route::get('questions', QuestionList::class)->name('questions'); 39 | Route::get('questions/create', QuestionForm::class)->name('questions.create'); 40 | Route::get('questions/{question}', QuestionForm::class)->name('questions.edit'); 41 | 42 | Route::get('quizzes', QuizList::class)->name('quizzes'); 43 | Route::get('quizzes/create', QuizForm::class)->name('quiz.create'); 44 | Route::get('quizzes/{quiz}', QuizForm::class)->name('quiz.edit'); 45 | 46 | Route::get('tests', TestController::class)->name('tests'); 47 | }); 48 | }); 49 | 50 | require __DIR__.'/auth.php'; 51 | -------------------------------------------------------------------------------- /storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !public/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/app/public/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/debugbar/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/.gitignore: -------------------------------------------------------------------------------- 1 | compiled.php 2 | config.php 3 | down 4 | events.scanned.php 5 | maintenance.php 6 | routes.php 7 | routes.scanned.php 8 | schedule-* 9 | services.json 10 | -------------------------------------------------------------------------------- /storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !data/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/framework/cache/data/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/testing/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | const defaultTheme = require('tailwindcss/defaultTheme'); 2 | 3 | /** @type {import('tailwindcss').Config} */ 4 | module.exports = { 5 | content: [ 6 | './vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php', 7 | './storage/framework/views/*.php', 8 | './resources/views/**/*.blade.php', 9 | ], 10 | 11 | theme: { 12 | extend: { 13 | fontFamily: { 14 | sans: ['Figtree', ...defaultTheme.fontFamily.sans], 15 | }, 16 | }, 17 | }, 18 | 19 | plugins: [require('@tailwindcss/forms')], 20 | }; 21 | -------------------------------------------------------------------------------- /tests/CreatesApplication.php: -------------------------------------------------------------------------------- 1 | make(Kernel::class)->bootstrap(); 18 | 19 | return $app; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/Feature/AdminRoutesTest.php: -------------------------------------------------------------------------------- 1 | admin()->create(); 17 | 18 | $response = $this->actingAs($admin)->get(route('questions')); 19 | 20 | $response->assertOk(); 21 | 22 | $user = User::factory()->create(); 23 | 24 | $response = $this->actingAs($user)->get(route('questions')); 25 | 26 | $response->assertForbidden(); 27 | 28 | $response = $this->get(route('questions')); 29 | 30 | $response->assertForbidden(); 31 | } 32 | 33 | public function testAdminCanAndOthersCannotAccessQuizzesPage() 34 | { 35 | $admin = User::factory()->admin()->create(); 36 | 37 | $response = $this->actingAs($admin)->get(route('quizzes')); 38 | 39 | $response->assertOk(); 40 | 41 | $user = User::factory()->create(); 42 | 43 | $response = $this->actingAs($user)->get(route('quizzes')); 44 | 45 | $response->assertForbidden(); 46 | 47 | $response = $this->get(route('quizzes')); 48 | 49 | $response->assertForbidden(); 50 | } 51 | 52 | public function testAdminCanAndOthersCannotAccessTestsPage() 53 | { 54 | $admin = User::factory()->admin()->create(); 55 | 56 | $response = $this->actingAs($admin)->get(route('tests')); 57 | 58 | $response->assertOk(); 59 | 60 | $user = User::factory()->create(); 61 | 62 | $response = $this->actingAs($user)->get(route('tests')); 63 | 64 | $response->assertForbidden(); 65 | 66 | $response = $this->get(route('tests')); 67 | 68 | $response->assertForbidden(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/Feature/Auth/AuthenticationTest.php: -------------------------------------------------------------------------------- 1 | get('/login'); 17 | 18 | $response->assertStatus(200); 19 | } 20 | 21 | public function test_users_can_authenticate_using_the_login_screen(): void 22 | { 23 | $user = User::factory()->create(); 24 | 25 | $response = $this->post('/login', [ 26 | 'email' => $user->email, 27 | 'password' => 'password', 28 | ]); 29 | 30 | $this->assertAuthenticated(); 31 | $response->assertRedirect(RouteServiceProvider::HOME); 32 | } 33 | 34 | public function test_users_can_not_authenticate_with_invalid_password(): void 35 | { 36 | $user = User::factory()->create(); 37 | 38 | $this->post('/login', [ 39 | 'email' => $user->email, 40 | 'password' => 'wrong-password', 41 | ]); 42 | 43 | $this->assertGuest(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/Feature/Auth/EmailVerificationTest.php: -------------------------------------------------------------------------------- 1 | create([ 20 | 'email_verified_at' => null, 21 | ]); 22 | 23 | $response = $this->actingAs($user)->get('/verify-email'); 24 | 25 | $response->assertStatus(200); 26 | } 27 | 28 | public function test_email_can_be_verified(): void 29 | { 30 | $user = User::factory()->create([ 31 | 'email_verified_at' => null, 32 | ]); 33 | 34 | Event::fake(); 35 | 36 | $verificationUrl = URL::temporarySignedRoute( 37 | 'verification.verify', 38 | now()->addMinutes(60), 39 | ['id' => $user->id, 'hash' => sha1($user->email)] 40 | ); 41 | 42 | $response = $this->actingAs($user)->get($verificationUrl); 43 | 44 | Event::assertDispatched(Verified::class); 45 | $this->assertTrue($user->fresh()->hasVerifiedEmail()); 46 | $response->assertRedirect(RouteServiceProvider::HOME.'?verified=1'); 47 | } 48 | 49 | public function test_email_is_not_verified_with_invalid_hash(): void 50 | { 51 | $user = User::factory()->create([ 52 | 'email_verified_at' => null, 53 | ]); 54 | 55 | $verificationUrl = URL::temporarySignedRoute( 56 | 'verification.verify', 57 | now()->addMinutes(60), 58 | ['id' => $user->id, 'hash' => sha1('wrong-email')] 59 | ); 60 | 61 | $this->actingAs($user)->get($verificationUrl); 62 | 63 | $this->assertFalse($user->fresh()->hasVerifiedEmail()); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /tests/Feature/Auth/PasswordConfirmationTest.php: -------------------------------------------------------------------------------- 1 | create(); 16 | 17 | $response = $this->actingAs($user)->get('/confirm-password'); 18 | 19 | $response->assertStatus(200); 20 | } 21 | 22 | public function test_password_can_be_confirmed(): void 23 | { 24 | $user = User::factory()->create(); 25 | 26 | $response = $this->actingAs($user)->post('/confirm-password', [ 27 | 'password' => 'password', 28 | ]); 29 | 30 | $response->assertRedirect(); 31 | $response->assertSessionHasNoErrors(); 32 | } 33 | 34 | public function test_password_is_not_confirmed_with_invalid_password(): void 35 | { 36 | $user = User::factory()->create(); 37 | 38 | $response = $this->actingAs($user)->post('/confirm-password', [ 39 | 'password' => 'wrong-password', 40 | ]); 41 | 42 | $response->assertSessionHasErrors(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/Feature/Auth/PasswordResetTest.php: -------------------------------------------------------------------------------- 1 | get('/forgot-password'); 18 | 19 | $response->assertStatus(200); 20 | } 21 | 22 | public function test_reset_password_link_can_be_requested(): void 23 | { 24 | Notification::fake(); 25 | 26 | $user = User::factory()->create(); 27 | 28 | $this->post('/forgot-password', ['email' => $user->email]); 29 | 30 | Notification::assertSentTo($user, ResetPassword::class); 31 | } 32 | 33 | public function test_reset_password_screen_can_be_rendered(): void 34 | { 35 | Notification::fake(); 36 | 37 | $user = User::factory()->create(); 38 | 39 | $this->post('/forgot-password', ['email' => $user->email]); 40 | 41 | Notification::assertSentTo($user, ResetPassword::class, function ($notification) { 42 | $response = $this->get('/reset-password/'.$notification->token); 43 | 44 | $response->assertStatus(200); 45 | 46 | return true; 47 | }); 48 | } 49 | 50 | public function test_password_can_be_reset_with_valid_token(): void 51 | { 52 | Notification::fake(); 53 | 54 | $user = User::factory()->create(); 55 | 56 | $this->post('/forgot-password', ['email' => $user->email]); 57 | 58 | Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) { 59 | $response = $this->post('/reset-password', [ 60 | 'token' => $notification->token, 61 | 'email' => $user->email, 62 | 'password' => 'password', 63 | 'password_confirmation' => 'password', 64 | ]); 65 | 66 | $response->assertSessionHasNoErrors(); 67 | 68 | return true; 69 | }); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tests/Feature/Auth/PasswordUpdateTest.php: -------------------------------------------------------------------------------- 1 | create(); 17 | 18 | $response = $this 19 | ->actingAs($user) 20 | ->from('/profile') 21 | ->put('/password', [ 22 | 'current_password' => 'password', 23 | 'password' => 'new-password', 24 | 'password_confirmation' => 'new-password', 25 | ]); 26 | 27 | $response 28 | ->assertSessionHasNoErrors() 29 | ->assertRedirect('/profile'); 30 | 31 | $this->assertTrue(Hash::check('new-password', $user->refresh()->password)); 32 | } 33 | 34 | public function test_correct_password_must_be_provided_to_update_password(): void 35 | { 36 | $user = User::factory()->create(); 37 | 38 | $response = $this 39 | ->actingAs($user) 40 | ->from('/profile') 41 | ->put('/password', [ 42 | 'current_password' => 'wrong-password', 43 | 'password' => 'new-password', 44 | 'password_confirmation' => 'new-password', 45 | ]); 46 | 47 | $response 48 | ->assertSessionHasErrorsIn('updatePassword', 'current_password') 49 | ->assertRedirect('/profile'); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/Feature/Auth/RegistrationTest.php: -------------------------------------------------------------------------------- 1 | get('/register'); 16 | 17 | $response->assertStatus(200); 18 | } 19 | 20 | public function test_new_users_can_register(): void 21 | { 22 | $response = $this->post('/register', [ 23 | 'name' => 'Test User', 24 | 'email' => 'test@example.com', 25 | 'password' => 'password', 26 | 'password_confirmation' => 'password', 27 | ]); 28 | 29 | $this->assertAuthenticated(); 30 | $response->assertRedirect(RouteServiceProvider::HOME); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Feature/Livewire/QuestionsTest.php: -------------------------------------------------------------------------------- 1 | actingAs(User::factory()->admin()->create()); 20 | 21 | Livewire::test(QuestionForm::class) 22 | ->set('question_text', 'very secret question') 23 | ->set('questionOptions.0.option', 'first answer') 24 | ->call('save') 25 | ->assertHasNoErrors(['question_text', 'code_snippet', 'answer_explanation', 'more_info_link', 'topic_id', 'questionOptions', 'questionOptions.*.option']) 26 | ->assertRedirect(route('questions')); 27 | 28 | $this->assertDatabaseHas('questions', [ 29 | 'question_text' => 'very secret question', 30 | ]); 31 | } 32 | 33 | public function testQuestionTextIsRequired() 34 | { 35 | $this->actingAs(User::factory()->admin()->create()); 36 | 37 | Livewire::test(QuestionForm::class) 38 | ->set('question_text', '') 39 | ->call('save') 40 | ->assertHasErrors(['question_text' => 'required']); 41 | } 42 | 43 | public function testAdminCanEditQuestion() 44 | { 45 | $this->actingAs(User::factory()->admin()->create()); 46 | 47 | $question = Question::factory() 48 | ->has(QuestionOption::factory()) 49 | ->create(); 50 | 51 | Livewire::test(QuestionForm::class, [$question]) 52 | ->set('question_text', 'very secret question') 53 | ->call('save') 54 | ->assertHasNoErrors(['question_text', 'code_snippet', 'answer_explanation', 'more_info_link', 'topic_id', 'questionOptions', 'questionOptions.*.option']) 55 | ->assertRedirect(route('questions')); 56 | 57 | $this->assertDatabaseHas('questions', [ 58 | 'question_text' => 'very secret question', 59 | ]); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tests/Feature/Livewire/QuizzesTest.php: -------------------------------------------------------------------------------- 1 | actingAs(User::factory()->admin()->create()); 20 | 21 | Livewire::test(QuizForm::class) 22 | ->set('title', 'quiz title') 23 | ->call('save') 24 | ->assertHasNoErrors(['title', 'slug', 'description', 'published', 'public', 'questions']) 25 | ->assertRedirect(route('quizzes')); 26 | 27 | $this->assertDatabaseHas('quizzes', [ 28 | 'title' => 'quiz title', 29 | ]); 30 | } 31 | 32 | public function testTitleIsRequired() 33 | { 34 | $this->actingAs(User::factory()->admin()->create()); 35 | 36 | Livewire::test(QuizForm::class) 37 | ->set('title', '') 38 | ->call('save') 39 | ->assertHasErrors(['title' => 'required']); 40 | } 41 | 42 | public function testAdminCanEditQuiz() 43 | { 44 | $this->actingAs(User::factory()->admin()->create()); 45 | 46 | $quiz = Quiz::factory() 47 | ->has(Question::factory()) 48 | ->create(); 49 | 50 | Livewire::test(QuizForm::class, [$quiz]) 51 | ->set('title', 'new quiz') 52 | ->set('published', true) 53 | ->call('save') 54 | ->assertSet('published', true) 55 | ->assertHasNoErrors(['title', 'slug', 'description', 'published', 'public', 'questions']); 56 | 57 | $this->assertDatabaseHas('quizzes', [ 58 | 'title' => 'new quiz', 59 | 'published' => true, 60 | ]); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tests/Feature/ProfileTest.php: -------------------------------------------------------------------------------- 1 | create(); 16 | 17 | $response = $this 18 | ->actingAs($user) 19 | ->get('/profile'); 20 | 21 | $response->assertOk(); 22 | } 23 | 24 | public function test_profile_information_can_be_updated(): void 25 | { 26 | $user = User::factory()->create(); 27 | 28 | $response = $this 29 | ->actingAs($user) 30 | ->patch('/profile', [ 31 | 'name' => 'Test User', 32 | 'email' => 'test@example.com', 33 | ]); 34 | 35 | $response 36 | ->assertSessionHasNoErrors() 37 | ->assertRedirect('/profile'); 38 | 39 | $user->refresh(); 40 | 41 | $this->assertSame('Test User', $user->name); 42 | $this->assertSame('test@example.com', $user->email); 43 | $this->assertNull($user->email_verified_at); 44 | } 45 | 46 | public function test_email_verification_status_is_unchanged_when_the_email_address_is_unchanged(): void 47 | { 48 | $user = User::factory()->create(); 49 | 50 | $response = $this 51 | ->actingAs($user) 52 | ->patch('/profile', [ 53 | 'name' => 'Test User', 54 | 'email' => $user->email, 55 | ]); 56 | 57 | $response 58 | ->assertSessionHasNoErrors() 59 | ->assertRedirect('/profile'); 60 | 61 | $this->assertNotNull($user->refresh()->email_verified_at); 62 | } 63 | 64 | public function test_user_can_delete_their_account(): void 65 | { 66 | $user = User::factory()->create(); 67 | 68 | $response = $this 69 | ->actingAs($user) 70 | ->delete('/profile', [ 71 | 'password' => 'password', 72 | ]); 73 | 74 | $response 75 | ->assertSessionHasNoErrors() 76 | ->assertRedirect('/'); 77 | 78 | $this->assertGuest(); 79 | $this->assertNull($user->fresh()); 80 | } 81 | 82 | public function test_correct_password_must_be_provided_to_delete_account(): void 83 | { 84 | $user = User::factory()->create(); 85 | 86 | $response = $this 87 | ->actingAs($user) 88 | ->from('/profile') 89 | ->delete('/profile', [ 90 | 'password' => 'wrong-password', 91 | ]); 92 | 93 | $response 94 | ->assertSessionHasErrorsIn('userDeletion', 'password') 95 | ->assertRedirect('/profile'); 96 | 97 | $this->assertNotNull($user->fresh()); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite'; 2 | import laravel from 'laravel-vite-plugin'; 3 | 4 | export default defineConfig({ 5 | plugins: [ 6 | laravel({ 7 | input: [ 8 | 'resources/css/app.css', 9 | 'resources/js/app.js', 10 | ], 11 | refresh: true, 12 | }), 13 | ], 14 | }); 15 | --------------------------------------------------------------------------------