├── .editorconfig ├── .env.example ├── .gitattributes ├── .gitignore ├── .styleci.yml ├── README.md ├── app ├── Console │ └── Kernel.php ├── Exceptions │ ├── DuplicateVoteException.php │ ├── Handler.php │ └── VoteNotFoundException.php ├── Http │ ├── Controllers │ │ ├── Auth │ │ │ ├── AuthenticatedSessionController.php │ │ │ ├── ConfirmablePasswordController.php │ │ │ ├── EmailVerificationNotificationController.php │ │ │ ├── EmailVerificationPromptController.php │ │ │ ├── NewPasswordController.php │ │ │ ├── PasswordResetLinkController.php │ │ │ ├── RegisteredUserController.php │ │ │ └── VerifyEmailController.php │ │ ├── CategoryController.php │ │ ├── CommentController.php │ │ ├── Controller.php │ │ ├── IdeaController.php │ │ ├── StatusController.php │ │ └── VoteController.php │ ├── Kernel.php │ ├── Livewire │ │ ├── AddComment.php │ │ ├── CommentNotifications.php │ │ ├── CreateIdea.php │ │ ├── DeleteComment.php │ │ ├── DeleteIdea.php │ │ ├── EditComment.php │ │ ├── EditIdea.php │ │ ├── IdeaComment.php │ │ ├── IdeaComments.php │ │ ├── IdeaIndex.php │ │ ├── IdeaShow.php │ │ ├── IdeasIndex.php │ │ ├── MarkCommentAsNotSpam.php │ │ ├── MarkCommentAsSpam.php │ │ ├── MarkIdeaAsNotSpam.php │ │ ├── MarkIdeaAsSpam.php │ │ ├── SetStatus.php │ │ ├── StatusFilters.php │ │ └── Traits │ │ │ └── WithAuthRedirects.php │ ├── Middleware │ │ ├── Authenticate.php │ │ ├── EncryptCookies.php │ │ ├── PreventRequestsDuringMaintenance.php │ │ ├── RedirectIfAuthenticated.php │ │ ├── TrimStrings.php │ │ ├── TrustHosts.php │ │ ├── TrustProxies.php │ │ └── VerifyCsrfToken.php │ └── Requests │ │ └── Auth │ │ └── LoginRequest.php ├── Jobs │ └── NotifyAllVoters.php ├── Mail │ └── IdeaStatusUpdatedMailable.php ├── Models │ ├── Category.php │ ├── Comment.php │ ├── Idea.php │ ├── Status.php │ ├── User.php │ └── Vote.php ├── Notifications │ └── CommentAdded.php ├── Policies │ ├── CommentPolicy.php │ └── IdeaPolicy.php ├── Providers │ ├── AppServiceProvider.php │ ├── AuthServiceProvider.php │ ├── BroadcastServiceProvider.php │ ├── EventServiceProvider.php │ ├── HorizonServiceProvider.php │ └── RouteServiceProvider.php └── View │ └── Components │ ├── AppLayout.php │ └── GuestLayout.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 ├── horizon.php ├── logging.php ├── mail.php ├── queue.php ├── services.php ├── session.php └── view.php ├── database ├── .gitignore ├── factories │ ├── CategoryFactory.php │ ├── CommentFactory.php │ ├── IdeaFactory.php │ ├── StatusFactory.php │ ├── UserFactory.php │ └── VoteFactory.php ├── migrations │ ├── 2014_10_12_000000_create_users_table.php │ ├── 2014_10_12_100000_create_password_resets_table.php │ ├── 2019_08_19_000000_create_failed_jobs_table.php │ ├── 2021_02_24_012947_create_statuses_table.php │ ├── 2021_02_25_012947_create_categories_table.php │ ├── 2021_02_26_012947_create_ideas_table.php │ ├── 2021_03_05_061517_create_votes_table.php │ ├── 2021_05_04_065809_create_comments_table.php │ └── 2021_05_26_024309_create_notifications_table.php └── seeders │ ├── CategorySeeder.php │ ├── CommentSeeder.php │ ├── DatabaseSeeder.php │ ├── IdeaSeeder.php │ ├── StatusSeeder.php │ └── VoteSeeder.php ├── package-lock.json ├── package.json ├── phpunit.xml ├── public ├── .htaccess ├── android-chrome-192x192.png ├── android-chrome-512x512.png ├── apple-touch-icon.png ├── css │ └── app.css ├── favicon-16x16.png ├── favicon-32x32.png ├── favicon.ico ├── img │ ├── logo.svg │ └── no-ideas.svg ├── index.php ├── js │ └── app.js ├── mix-manifest.json ├── robots.txt ├── site.webmanifest ├── vendor │ └── horizon │ │ ├── app-dark.css │ │ ├── app.css │ │ ├── app.js │ │ ├── img │ │ ├── favicon.png │ │ ├── horizon.svg │ │ └── sprite.svg │ │ └── mix-manifest.json └── web.config ├── resources ├── css │ └── app.css ├── js │ ├── app.js │ └── bootstrap.js ├── lang │ └── en │ │ ├── auth.php │ │ ├── pagination.php │ │ ├── passwords.php │ │ └── validation.php └── views │ ├── 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-card.blade.php │ ├── auth-session-status.blade.php │ ├── auth-validation-errors.blade.php │ ├── button.blade.php │ ├── dropdown-link.blade.php │ ├── dropdown.blade.php │ ├── input.blade.php │ ├── label.blade.php │ ├── modal-confirm.blade.php │ ├── modals-container.blade.php │ ├── nav-link.blade.php │ ├── notification-success.blade.php │ └── responsive-nav-link.blade.php │ ├── dashboard.blade.php │ ├── emails │ ├── comment-added.blade.php │ └── idea-status-updated.blade.php │ ├── idea │ ├── index.blade.php │ └── show.blade.php │ ├── layouts │ ├── app.blade.php │ ├── guest.blade.php │ └── navigation.blade.php │ ├── livewire │ ├── add-comment.blade.php │ ├── comment-notifications.blade.php │ ├── create-idea.blade.php │ ├── delete-comment.blade.php │ ├── delete-idea.blade.php │ ├── edit-comment.blade.php │ ├── edit-idea.blade.php │ ├── idea-comment.blade.php │ ├── idea-comments.blade.php │ ├── idea-index.blade.php │ ├── idea-show.blade.php │ ├── ideas-index.blade.php │ ├── mark-comment-as-not-spam.blade.php │ ├── mark-comment-as-spam.blade.php │ ├── mark-idea-as-not-spam.blade.php │ ├── mark-idea-as-spam.blade.php │ ├── set-status.blade.php │ └── status-filters.blade.php │ └── welcome.blade.php ├── routes ├── api.php ├── auth.php ├── channels.php ├── console.php └── web.php ├── server.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 │ ├── AdminSetStatusTest.php │ ├── Auth │ │ ├── AuthenticationTest.php │ │ ├── EmailVerificationTest.php │ │ ├── PasswordConfirmationTest.php │ │ ├── PasswordResetTest.php │ │ └── RegistrationTest.php │ ├── CommentNotificationsTest.php │ ├── Comments │ │ ├── AddCommentTest.php │ │ ├── CommentsSpamManagementTest.php │ │ ├── DeleteCommentTest.php │ │ ├── EditCommentTest.php │ │ └── ShowCommentsTest.php │ ├── CreateIdeaTest.php │ ├── DeleteIdeaTest.php │ ├── EditIdeaTest.php │ ├── Filters │ │ ├── CategoryFiltersTest.php │ │ ├── OtherFiltersTest.php │ │ ├── SearchFilterTest.php │ │ └── StatusFiltersTest.php │ ├── GravatarTest.php │ ├── ShowIdeasTest.php │ ├── SpamManagementTest.php │ ├── VoteIndexPageTest.php │ └── VoteShowPageTest.php ├── TestCase.php └── Unit │ ├── IdeaTest.php │ ├── Jobs │ └── NotifyAllVotersTest.php │ ├── StatusTest.php │ └── UserTest.php └── webpack.mix.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_style = space 8 | indent_size = 4 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.{yml,yaml}] 15 | indent_size = 2 16 | -------------------------------------------------------------------------------- /.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_LEVEL=debug 9 | 10 | DB_CONNECTION=mysql 11 | DB_HOST=127.0.0.1 12 | DB_PORT=3306 13 | DB_DATABASE=lc_voting 14 | DB_USERNAME=root 15 | DB_PASSWORD= 16 | 17 | BROADCAST_DRIVER=log 18 | CACHE_DRIVER=file 19 | QUEUE_CONNECTION=sync 20 | SESSION_DRIVER=file 21 | SESSION_LIFETIME=120 22 | 23 | MEMCACHED_HOST=127.0.0.1 24 | 25 | REDIS_HOST=127.0.0.1 26 | REDIS_PASSWORD=null 27 | REDIS_PORT=6379 28 | 29 | MAIL_MAILER=smtp 30 | MAIL_HOST=mailhog 31 | MAIL_PORT=1025 32 | MAIL_USERNAME=null 33 | MAIL_PASSWORD=null 34 | MAIL_ENCRYPTION=null 35 | MAIL_FROM_ADDRESS=null 36 | MAIL_FROM_NAME="${APP_NAME}" 37 | 38 | AWS_ACCESS_KEY_ID= 39 | AWS_SECRET_ACCESS_KEY= 40 | AWS_DEFAULT_REGION=us-east-1 41 | AWS_BUCKET= 42 | 43 | PUSHER_APP_ID= 44 | PUSHER_APP_KEY= 45 | PUSHER_APP_SECRET= 46 | PUSHER_APP_CLUSTER=mt1 47 | 48 | MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" 49 | MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" 50 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.css linguist-vendored 3 | *.scss linguist-vendored 4 | *.js linguist-vendored 5 | CHANGELOG.md export-ignore 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /public/hot 3 | /public/storage 4 | /storage/*.key 5 | /vendor 6 | .env 7 | .env.backup 8 | .phpunit.result.cache 9 | docker-compose.override.yml 10 | Homestead.json 11 | Homestead.yaml 12 | npm-debug.log 13 | yarn-error.log 14 | -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | php: 2 | preset: laravel 3 | disabled: 4 | - no_unused_imports 5 | finder: 6 | not-name: 7 | - index.php 8 | - server.php 9 | js: 10 | finder: 11 | not-name: 12 | - webpack.mix.js 13 | css: true 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Build a Voting App 2 | 3 | Source Code for **"Build a Voting App"** series on Laracasts: https://laracasts.com/series/build-a-voting-app 4 | 5 | Each episode has a corresponding commit in git, so checkout the commit history for that. If you would like to go back to a particular point, you can do a `git checkout `. 6 | 7 | ## Installation 8 | 9 | 1. Clone the repo and `cd` into it 10 | 1. `composer install` 11 | 1. Rename or copy `.env.example` file to `.env` 12 | 1. `php artisan key:generate` 13 | 1. Setup a database and add your database credentials in your `.env` file 14 | 1. `php artisan migrate` or `php artisan migrate --seed` if you want seed data 15 | 1. `npm install` 16 | 1. `npm run dev` or `npm run watch` 17 | 1. `php artisan serve` or use Laravel Valet 18 | 1. Visit `localhost:8000` in your browser 19 | -------------------------------------------------------------------------------- /app/Console/Kernel.php: -------------------------------------------------------------------------------- 1 | command('inspire')->hourly(); 28 | } 29 | 30 | /** 31 | * Register the commands for the application. 32 | * 33 | * @return void 34 | */ 35 | protected function commands() 36 | { 37 | $this->load(__DIR__.'/Commands'); 38 | 39 | require base_path('routes/console.php'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/Exceptions/DuplicateVoteException.php: -------------------------------------------------------------------------------- 1 | reportable(function (Throwable $e) { 37 | // 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/Exceptions/VoteNotFoundException.php: -------------------------------------------------------------------------------- 1 | authenticate(); 32 | 33 | $request->session()->regenerate(); 34 | 35 | return redirect()->intended(RouteServiceProvider::HOME); 36 | } 37 | 38 | /** 39 | * Destroy an authenticated session. 40 | * 41 | * @param \Illuminate\Http\Request $request 42 | * @return \Illuminate\Http\RedirectResponse 43 | */ 44 | public function destroy(Request $request) 45 | { 46 | Auth::guard('web')->logout(); 47 | 48 | $request->session()->invalidate(); 49 | 50 | $request->session()->regenerateToken(); 51 | 52 | return redirect('/'); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ConfirmablePasswordController.php: -------------------------------------------------------------------------------- 1 | validate([ 33 | 'email' => $request->user()->email, 34 | 'password' => $request->password, 35 | ])) { 36 | throw ValidationException::withMessages([ 37 | 'password' => __('auth.password'), 38 | ]); 39 | } 40 | 41 | $request->session()->put('auth.password_confirmed_at', time()); 42 | 43 | return redirect()->intended(RouteServiceProvider::HOME); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/EmailVerificationNotificationController.php: -------------------------------------------------------------------------------- 1 | user()->hasVerifiedEmail()) { 20 | return redirect()->intended(RouteServiceProvider::HOME); 21 | } 22 | 23 | $request->user()->sendEmailVerificationNotification(); 24 | 25 | return back()->with('status', 'verification-link-sent'); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/EmailVerificationPromptController.php: -------------------------------------------------------------------------------- 1 | user()->hasVerifiedEmail() 20 | ? redirect()->intended(RouteServiceProvider::HOME) 21 | : view('auth.verify-email'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/NewPasswordController.php: -------------------------------------------------------------------------------- 1 | $request]); 22 | } 23 | 24 | /** 25 | * Handle an incoming new password request. 26 | * 27 | * @param \Illuminate\Http\Request $request 28 | * @return \Illuminate\Http\RedirectResponse 29 | * 30 | * @throws \Illuminate\Validation\ValidationException 31 | */ 32 | public function store(Request $request) 33 | { 34 | $request->validate([ 35 | 'token' => 'required', 36 | 'email' => 'required|email', 37 | 'password' => 'required|string|confirmed|min:8', 38 | ]); 39 | 40 | // Here we will attempt to reset the user's password. If it is successful we 41 | // will update the password on an actual user model and persist it to the 42 | // database. Otherwise we will parse the error and return the response. 43 | $status = Password::reset( 44 | $request->only('email', 'password', 'password_confirmation', 'token'), 45 | function ($user) use ($request) { 46 | $user->forceFill([ 47 | 'password' => Hash::make($request->password), 48 | 'remember_token' => Str::random(60), 49 | ])->save(); 50 | 51 | event(new PasswordReset($user)); 52 | } 53 | ); 54 | 55 | // If the password was successfully reset, we will redirect the user back to 56 | // the application's home authenticated view. If there is an error we can 57 | // redirect them back to where they came from with their error message. 58 | return $status == Password::PASSWORD_RESET 59 | ? redirect()->route('login')->with('status', __($status)) 60 | : back()->withInput($request->only('email')) 61 | ->withErrors(['email' => __($status)]); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/PasswordResetLinkController.php: -------------------------------------------------------------------------------- 1 | validate([ 32 | 'email' => 'required|email', 33 | ]); 34 | 35 | // We will send the password reset link to this user. Once we have attempted 36 | // to send the link, we will examine the response then see the message we 37 | // need to show to the user. Finally, we'll send out a proper response. 38 | $status = Password::sendResetLink( 39 | $request->only('email') 40 | ); 41 | 42 | return $status == Password::RESET_LINK_SENT 43 | ? back()->with('status', __($status)) 44 | : back()->withInput($request->only('email')) 45 | ->withErrors(['email' => __($status)]); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/RegisteredUserController.php: -------------------------------------------------------------------------------- 1 | validate([ 36 | 'name' => 'required|string|max:255', 37 | 'email' => 'required|string|email|max:255|unique:users', 38 | 'password' => 'required|string|confirmed|min:8', 39 | ]); 40 | 41 | Auth::login($user = User::create([ 42 | 'name' => $request->name, 43 | 'email' => $request->email, 44 | 'password' => Hash::make($request->password), 45 | ])); 46 | 47 | event(new Registered($user)); 48 | 49 | return redirect()->intended(RouteServiceProvider::HOME); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/VerifyEmailController.php: -------------------------------------------------------------------------------- 1 | user()->hasVerifiedEmail()) { 21 | return redirect()->intended(RouteServiceProvider::HOME.'?verified=1'); 22 | } 23 | 24 | if ($request->user()->markEmailAsVerified()) { 25 | event(new Verified($request->user())); 26 | } 27 | 28 | return redirect()->intended(RouteServiceProvider::HOME.'?verified=1'); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Http/Controllers/CategoryController.php: -------------------------------------------------------------------------------- 1 | $idea, 52 | 'votesCount' => $idea->votes()->count(), 53 | 'backUrl' => url()->previous() !== url()->full() && url()->previous() !== route('login') 54 | ? url()->previous() 55 | : route('idea.index'), 56 | ]); 57 | } 58 | 59 | /** 60 | * Show the form for editing the specified resource. 61 | * 62 | * @param \App\Models\Idea $idea 63 | * @return \Illuminate\Http\Response 64 | */ 65 | public function edit(Idea $idea) 66 | { 67 | // 68 | } 69 | 70 | /** 71 | * Update the specified resource in storage. 72 | * 73 | * @param \Illuminate\Http\Request $request 74 | * @param \App\Models\Idea $idea 75 | * @return \Illuminate\Http\Response 76 | */ 77 | public function update(Request $request, Idea $idea) 78 | { 79 | // 80 | } 81 | 82 | /** 83 | * Remove the specified resource from storage. 84 | * 85 | * @param \App\Models\Idea $idea 86 | * @return \Illuminate\Http\Response 87 | */ 88 | public function destroy(Idea $idea) 89 | { 90 | // 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /app/Http/Controllers/StatusController.php: -------------------------------------------------------------------------------- 1 | [ 33 | \App\Http\Middleware\EncryptCookies::class, 34 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 35 | \Illuminate\Session\Middleware\StartSession::class, 36 | // \Illuminate\Session\Middleware\AuthenticateSession::class, 37 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, 38 | \App\Http\Middleware\VerifyCsrfToken::class, 39 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 40 | ], 41 | 42 | 'api' => [ 43 | 'throttle:api', 44 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 45 | ], 46 | ]; 47 | 48 | /** 49 | * The application's route middleware. 50 | * 51 | * These middleware may be assigned to groups or used individually. 52 | * 53 | * @var array 54 | */ 55 | protected $routeMiddleware = [ 56 | 'auth' => \App\Http\Middleware\Authenticate::class, 57 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 58 | 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 59 | 'can' => \Illuminate\Auth\Middleware\Authorize::class, 60 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 61 | 'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class, 62 | 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 63 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 64 | 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, 65 | ]; 66 | } 67 | -------------------------------------------------------------------------------- /app/Http/Livewire/AddComment.php: -------------------------------------------------------------------------------- 1 | 'required|min:4', 20 | ]; 21 | 22 | public function mount(Idea $idea) 23 | { 24 | $this->idea = $idea; 25 | } 26 | 27 | public function addComment() 28 | { 29 | if (auth()->guest()) { 30 | abort(Response::HTTP_FORBIDDEN); 31 | } 32 | 33 | $this->validate(); 34 | 35 | $newComment = Comment::create([ 36 | 'user_id' => auth()->id(), 37 | 'idea_id' => $this->idea->id, 38 | 'status_id' => 1, 39 | 'body' => $this->comment, 40 | ]); 41 | 42 | $this->reset('comment'); 43 | 44 | $this->idea->user->notify(new CommentAdded($newComment)); 45 | 46 | $this->emit('commentWasAdded', 'Comment was posted!'); 47 | } 48 | 49 | public function render() 50 | { 51 | return view('livewire.add-comment'); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/Http/Livewire/CommentNotifications.php: -------------------------------------------------------------------------------- 1 | notifications = collect([]); 23 | $this->isLoading = true; 24 | $this->getNotificationCount(); 25 | } 26 | 27 | public function getNotificationCount() 28 | { 29 | $this->notificationCount = auth()->user()->unreadNotifications()->count(); 30 | 31 | if ($this->notificationCount > self::NOTIFICATION_THRESHOLD) { 32 | $this->notificationCount = self::NOTIFICATION_THRESHOLD.'+'; 33 | } 34 | } 35 | 36 | public function getNotifications() 37 | { 38 | $this->notifications = auth()->user() 39 | ->unreadNotifications() 40 | ->latest() 41 | ->take(self::NOTIFICATION_THRESHOLD) 42 | ->get(); 43 | 44 | $this->isLoading = false; 45 | } 46 | 47 | public function markAsRead($notificationId) 48 | { 49 | if (auth()->guest()) { 50 | abort(Response::HTTP_FORBIDDEN); 51 | } 52 | 53 | $notification = DatabaseNotification::findOrFail($notificationId); 54 | $notification->markAsRead(); 55 | 56 | $this->scrollToComment($notification); 57 | } 58 | 59 | public function scrollToComment($notification) 60 | { 61 | $idea = Idea::find($notification->data['idea_id']); 62 | if (! $idea) { 63 | session()->flash('error_message', 'This idea no longer exists!'); 64 | 65 | return redirect()->route('idea.index'); 66 | } 67 | 68 | $comment = Comment::find($notification->data['comment_id']); 69 | if (! $comment) { 70 | session()->flash('error_message', 'This comment no longer exists!'); 71 | 72 | return redirect()->route('idea.index'); 73 | } 74 | 75 | $comments = $idea->comments()->pluck('id'); 76 | $indexOfComment = $comments->search($comment->id); 77 | 78 | $page = (int) ($indexOfComment / $comment->getPerPage()) + 1; 79 | 80 | session()->flash('scrollToComment', $comment->id); 81 | 82 | return redirect()->route('idea.show', [ 83 | 'idea' => $notification->data['idea_slug'], 84 | 'page' => $page, 85 | ]); 86 | } 87 | 88 | public function markAllAsRead() 89 | { 90 | if (auth()->guest()) { 91 | abort(Response::HTTP_FORBIDDEN); 92 | } 93 | 94 | auth()->user()->unreadNotifications->markAsRead(); 95 | $this->getNotificationCount(); 96 | $this->getNotifications(); 97 | } 98 | 99 | public function render() 100 | { 101 | return view('livewire.comment-notifications'); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /app/Http/Livewire/CreateIdea.php: -------------------------------------------------------------------------------- 1 | 'required|min:4', 22 | 'category' => 'required|integer|exists:categories,id', 23 | 'description' => 'required|min:4', 24 | ]; 25 | 26 | public function createIdea() 27 | { 28 | if (auth()->guest()) { 29 | abort(Response::HTTP_FORBIDDEN); 30 | } 31 | 32 | $this->validate(); 33 | 34 | $idea = Idea::create([ 35 | 'user_id' => auth()->id(), 36 | 'category_id' => $this->category, 37 | 'status_id' => 1, 38 | 'title' => $this->title, 39 | 'description' => $this->description, 40 | ]); 41 | 42 | $idea->vote(auth()->user()); 43 | 44 | session()->flash('success_message', 'Idea was added successfully!'); 45 | 46 | $this->reset(); 47 | 48 | return redirect()->route('idea.index'); 49 | } 50 | 51 | public function render() 52 | { 53 | return view('livewire.create-idea', [ 54 | 'categories' => Category::all(), 55 | ]); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/Http/Livewire/DeleteComment.php: -------------------------------------------------------------------------------- 1 | comment = Comment::findOrFail($commentId); 18 | 19 | $this->emit('deleteCommentWasSet'); 20 | } 21 | 22 | public function deleteComment() 23 | { 24 | if (auth()->guest() || auth()->user()->cannot('delete', $this->comment)) { 25 | abort(Response::HTTP_FORBIDDEN); 26 | } 27 | 28 | Comment::destroy($this->comment->id); 29 | $this->comment = null; 30 | 31 | $this->emit('commentWasDeleted', 'Comment was deleted!'); 32 | } 33 | 34 | public function render() 35 | { 36 | return view('livewire.delete-comment'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/Http/Livewire/DeleteIdea.php: -------------------------------------------------------------------------------- 1 | idea = $idea; 18 | } 19 | 20 | public function deleteIdea() 21 | { 22 | if (auth()->guest() || auth()->user()->cannot('delete', $this->idea)) { 23 | abort(Response::HTTP_FORBIDDEN); 24 | } 25 | 26 | Idea::destroy($this->idea->id); 27 | 28 | session()->flash('success_message', 'Idea was deleted successfully!'); 29 | 30 | return redirect()->route('idea.index'); 31 | } 32 | 33 | public function render() 34 | { 35 | return view('livewire.delete-idea'); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/Http/Livewire/EditComment.php: -------------------------------------------------------------------------------- 1 | 'required|min:4', 16 | ]; 17 | 18 | protected $listeners = ['setEditComment']; 19 | 20 | public function setEditComment($commentId) 21 | { 22 | $this->comment = Comment::findOrFail($commentId); 23 | $this->body = $this->comment->body; 24 | 25 | $this->emit('editCommentWasSet'); 26 | } 27 | 28 | public function updateComment() 29 | { 30 | if (auth()->guest() || auth()->user()->cannot('update', $this->comment)) { 31 | abort(Response::HTTP_FORBIDDEN); 32 | } 33 | 34 | $this->validate(); 35 | 36 | $this->comment->body = $this->body; 37 | $this->comment->save(); 38 | 39 | $this->emit('commentWasUpdated', 'Comment was updated!'); 40 | } 41 | 42 | public function render() 43 | { 44 | return view('livewire.edit-comment'); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/Http/Livewire/EditIdea.php: -------------------------------------------------------------------------------- 1 | 'required|min:4', 19 | 'category' => 'required|integer|exists:categories,id', 20 | 'description' => 'required|min:4', 21 | ]; 22 | 23 | public function mount(Idea $idea) 24 | { 25 | $this->idea = $idea; 26 | $this->title = $idea->title; 27 | $this->category = $idea->category_id; 28 | $this->description = $idea->description; 29 | } 30 | 31 | public function updateIdea() 32 | { 33 | if (auth()->guest() || auth()->user()->cannot('update', $this->idea)) { 34 | abort(Response::HTTP_FORBIDDEN); 35 | } 36 | 37 | $this->validate(); 38 | 39 | $this->idea->update([ 40 | 'title' => $this->title, 41 | 'category_id' => $this->category, 42 | 'description' => $this->description, 43 | ]); 44 | 45 | $this->emit('ideaWasUpdated', 'Idea was updated successfully!'); 46 | } 47 | 48 | public function render() 49 | { 50 | return view('livewire.edit-idea', [ 51 | 'categories' => Category::all(), 52 | ]); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/Http/Livewire/IdeaComment.php: -------------------------------------------------------------------------------- 1 | comment->refresh(); 22 | } 23 | 24 | public function commentWasMarkedAsSpam() 25 | { 26 | $this->comment->refresh(); 27 | } 28 | 29 | public function commentWasMarkedAsNotSpam() 30 | { 31 | $this->comment->refresh(); 32 | } 33 | 34 | public function mount(Comment $comment, $ideaUserId) 35 | { 36 | $this->comment = $comment; 37 | $this->ideaUserId = $ideaUserId; 38 | } 39 | 40 | public function render() 41 | { 42 | return view('livewire.idea-comment'); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/Http/Livewire/IdeaComments.php: -------------------------------------------------------------------------------- 1 | idea->refresh(); 21 | $this->goToPage($this->idea->comments()->paginate()->lastPage()); 22 | } 23 | 24 | public function statusWasUpdated() 25 | { 26 | $this->idea->refresh(); 27 | $this->goToPage($this->idea->comments()->paginate()->lastPage()); 28 | } 29 | 30 | public function commentWasDeleted() 31 | { 32 | $this->idea->refresh(); 33 | $this->goToPage(1); 34 | } 35 | 36 | public function mount(Idea $idea) 37 | { 38 | $this->idea = $idea; 39 | } 40 | 41 | public function render() 42 | { 43 | return view('livewire.idea-comments', [ 44 | // 'comments' => $this->idea->comments()->paginate()->withQueryString(), 45 | 'comments' => Comment::with(['user', 'status'])->where('idea_id', $this->idea->id)->paginate()->withQueryString(), 46 | ]); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/Http/Livewire/IdeaIndex.php: -------------------------------------------------------------------------------- 1 | idea = $idea; 22 | $this->votesCount = $votesCount; 23 | $this->hasVoted = $idea->voted_by_user; 24 | } 25 | 26 | public function vote() 27 | { 28 | if (auth()->guest()) { 29 | return $this->redirectToLogin(); 30 | } 31 | 32 | if ($this->hasVoted) { 33 | try { 34 | $this->idea->removeVote(auth()->user()); 35 | } catch (VoteNotFoundException $e) { 36 | // do nothing 37 | } 38 | $this->votesCount--; 39 | $this->hasVoted = false; 40 | } else { 41 | try { 42 | $this->idea->vote(auth()->user()); 43 | } catch (DuplicateVoteException $e) { 44 | // do nothing 45 | } 46 | $this->votesCount++; 47 | $this->hasVoted = true; 48 | } 49 | } 50 | 51 | public function render() 52 | { 53 | return view('livewire.idea-index'); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/Http/Livewire/IdeaShow.php: -------------------------------------------------------------------------------- 1 | idea = $idea; 32 | $this->votesCount = $votesCount; 33 | $this->hasVoted = $idea->isVotedByUser(auth()->user()); 34 | } 35 | 36 | public function statusWasUpdated() 37 | { 38 | $this->idea->refresh(); 39 | } 40 | 41 | public function statusWasUpdatedError() 42 | { 43 | $this->idea->refresh(); 44 | } 45 | 46 | public function ideaWasUpdated() 47 | { 48 | $this->idea->refresh(); 49 | } 50 | 51 | public function ideaWasMarkedAsSpam() 52 | { 53 | $this->idea->refresh(); 54 | } 55 | 56 | public function ideaWasMarkedAsNotSpam() 57 | { 58 | $this->idea->refresh(); 59 | } 60 | 61 | public function commentWasAdded() 62 | { 63 | $this->idea->refresh(); 64 | } 65 | 66 | public function commentWasDeleted() 67 | { 68 | $this->idea->refresh(); 69 | } 70 | 71 | public function vote() 72 | { 73 | if (auth()->guest()) { 74 | return $this->redirectToLogin(); 75 | } 76 | 77 | if ($this->hasVoted) { 78 | try { 79 | $this->idea->removeVote(auth()->user()); 80 | } catch (VoteNotFoundException $e) { 81 | // do nothing 82 | } 83 | $this->votesCount--; 84 | $this->hasVoted = false; 85 | } else { 86 | try { 87 | $this->idea->vote(auth()->user()); 88 | } catch (DuplicateVoteException $e) { 89 | // do nothing 90 | } 91 | $this->votesCount++; 92 | $this->hasVoted = true; 93 | } 94 | } 95 | 96 | public function render() 97 | { 98 | return view('livewire.idea-show'); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /app/Http/Livewire/MarkCommentAsNotSpam.php: -------------------------------------------------------------------------------- 1 | comment = Comment::findOrFail($commentId); 18 | 19 | $this->emit('markAsNotSpamCommentWasSet'); 20 | } 21 | 22 | public function markAsNotSpam() 23 | { 24 | if (auth()->guest() || ! auth()->user()->isAdmin()) { 25 | abort(Response::HTTP_FORBIDDEN); 26 | } 27 | 28 | $this->comment->spam_reports = 0; 29 | $this->comment->save(); 30 | 31 | $this->emit('commentWasMarkedAsNotSpam', 'Comment spam counter was reset!'); 32 | } 33 | 34 | public function render() 35 | { 36 | return view('livewire.mark-comment-as-not-spam'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/Http/Livewire/MarkCommentAsSpam.php: -------------------------------------------------------------------------------- 1 | comment = Comment::findOrFail($commentId); 18 | 19 | $this->emit('markAsSpamCommentWasSet'); 20 | } 21 | 22 | public function markAsSpam() 23 | { 24 | if (auth()->guest()) { 25 | abort(Response::HTTP_FORBIDDEN); 26 | } 27 | 28 | $this->comment->spam_reports++; 29 | $this->comment->save(); 30 | 31 | $this->emit('commentWasMarkedAsSpam', 'Comment was marked as spam!'); 32 | } 33 | 34 | public function render() 35 | { 36 | return view('livewire.mark-comment-as-spam'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/Http/Livewire/MarkIdeaAsNotSpam.php: -------------------------------------------------------------------------------- 1 | idea = $idea; 16 | } 17 | 18 | public function markAsNotSpam() 19 | { 20 | if (auth()->guest() || ! auth()->user()->isAdmin()) { 21 | abort(Response::HTTP_FORBIDDEN); 22 | } 23 | 24 | $this->idea->spam_reports = 0; 25 | $this->idea->save(); 26 | 27 | $this->emit('ideaWasMarkedAsNotSpam', 'Spam Counter was reset!'); 28 | } 29 | 30 | public function render() 31 | { 32 | return view('livewire.mark-idea-as-not-spam'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/Http/Livewire/MarkIdeaAsSpam.php: -------------------------------------------------------------------------------- 1 | idea = $idea; 16 | } 17 | 18 | public function markAsSpam() 19 | { 20 | if (auth()->guest()) { 21 | abort(Response::HTTP_FORBIDDEN); 22 | } 23 | 24 | $this->idea->spam_reports++; 25 | $this->idea->save(); 26 | 27 | $this->emit('ideaWasMarkedAsSpam', 'Idea was marked as spam!'); 28 | } 29 | 30 | public function render() 31 | { 32 | return view('livewire.mark-idea-as-spam'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/Http/Livewire/SetStatus.php: -------------------------------------------------------------------------------- 1 | idea = $idea; 21 | $this->status = $this->idea->status_id; 22 | } 23 | 24 | public function setStatus() 25 | { 26 | if (auth()->guest() || ! auth()->user()->isAdmin()) { 27 | abort(Response::HTTP_FORBIDDEN); 28 | } 29 | 30 | if ($this->idea->status_id === (int) $this->status) { 31 | $this->emit('statusWasUpdatedError', 'Status is the same!'); 32 | 33 | return; 34 | } 35 | 36 | $this->idea->status_id = $this->status; 37 | $this->idea->save(); 38 | 39 | if ($this->notifyAllVoters) { 40 | NotifyAllVoters::dispatch($this->idea); 41 | } 42 | 43 | Comment::create([ 44 | 'user_id' => auth()->id(), 45 | 'idea_id' => $this->idea->id, 46 | 'status_id' => $this->status, 47 | 'body' => $this->comment ?? 'No comment was added.', 48 | 'is_status_update' => true, 49 | ]); 50 | 51 | $this->reset('comment'); 52 | 53 | $this->emit('statusWasUpdated', 'Status was updated successfully!'); 54 | } 55 | 56 | public function render() 57 | { 58 | return view('livewire.set-status'); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/Http/Livewire/StatusFilters.php: -------------------------------------------------------------------------------- 1 | statusCount = Status::getCount(); 18 | $this->status = request()->status ?? 'All'; 19 | 20 | if (Route::currentRouteName() === 'idea.show') { 21 | $this->status = null; 22 | } 23 | } 24 | 25 | public function setStatus($newStatus) 26 | { 27 | $this->status = $newStatus; 28 | $this->emit('queryStringUpdatedStatus', $this->status); 29 | 30 | if ($this->getPreviousRouteName() === 'idea.show') { 31 | return redirect()->route('idea.index', [ 32 | 'status' => $this->status, 33 | ]); 34 | } 35 | } 36 | 37 | public function render() 38 | { 39 | return view('livewire.status-filters'); 40 | } 41 | 42 | public function getPreviousRouteName() 43 | { 44 | return app('router')->getRoutes()->match(app('request')->create(url()->previous()))->getName(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /app/Http/Livewire/Traits/WithAuthRedirects.php: -------------------------------------------------------------------------------- 1 | setIntendedUrl(url()->previous()); 10 | 11 | return redirect()->route('login'); 12 | } 13 | 14 | public function redirectToRegister() 15 | { 16 | redirect()->setIntendedUrl(url()->previous()); 17 | 18 | return redirect()->route('register'); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/Http/Middleware/Authenticate.php: -------------------------------------------------------------------------------- 1 | expectsJson()) { 18 | return route('login'); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/Http/Middleware/EncryptCookies.php: -------------------------------------------------------------------------------- 1 | check()) { 26 | return redirect(RouteServiceProvider::HOME); 27 | } 28 | } 29 | 30 | return $next($request); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrimStrings.php: -------------------------------------------------------------------------------- 1 | allSubdomainsOfApplicationUrl(), 18 | ]; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrustProxies.php: -------------------------------------------------------------------------------- 1 | 'required|string|email', 33 | 'password' => 'required|string', 34 | ]; 35 | } 36 | 37 | /** 38 | * Attempt to authenticate the request's credentials. 39 | * 40 | * @return void 41 | * 42 | * @throws \Illuminate\Validation\ValidationException 43 | */ 44 | public function authenticate() 45 | { 46 | $this->ensureIsNotRateLimited(); 47 | 48 | if (! Auth::attempt($this->only('email', 'password'), $this->filled('remember'))) { 49 | RateLimiter::hit($this->throttleKey()); 50 | 51 | throw ValidationException::withMessages([ 52 | 'email' => __('auth.failed'), 53 | ]); 54 | } 55 | 56 | RateLimiter::clear($this->throttleKey()); 57 | } 58 | 59 | /** 60 | * Ensure the login request is not rate limited. 61 | * 62 | * @return void 63 | * 64 | * @throws \Illuminate\Validation\ValidationException 65 | */ 66 | public function ensureIsNotRateLimited() 67 | { 68 | if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) { 69 | return; 70 | } 71 | 72 | event(new Lockout($this)); 73 | 74 | $seconds = RateLimiter::availableIn($this->throttleKey()); 75 | 76 | throw ValidationException::withMessages([ 77 | 'email' => trans('auth.throttle', [ 78 | 'seconds' => $seconds, 79 | 'minutes' => ceil($seconds / 60), 80 | ]), 81 | ]); 82 | } 83 | 84 | /** 85 | * Get the rate limiting throttle key for the request. 86 | * 87 | * @return string 88 | */ 89 | public function throttleKey() 90 | { 91 | return Str::lower($this->input('email')).'|'.$this->ip(); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /app/Jobs/NotifyAllVoters.php: -------------------------------------------------------------------------------- 1 | idea = $idea; 29 | } 30 | 31 | /** 32 | * Execute the job. 33 | * 34 | * @return void 35 | */ 36 | public function handle() 37 | { 38 | $this->idea->votes() 39 | ->select('name', 'email') 40 | ->chunk(100, function ($voters) { 41 | foreach ($voters as $user) { 42 | Mail::to($user) 43 | ->queue(new IdeaStatusUpdatedMailable($this->idea)); 44 | } 45 | }); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/Mail/IdeaStatusUpdatedMailable.php: -------------------------------------------------------------------------------- 1 | idea = $idea; 25 | } 26 | 27 | /** 28 | * Build the message. 29 | * 30 | * @return $this 31 | */ 32 | public function build() 33 | { 34 | return $this->subject('An idea you voted for has a new status') 35 | ->markdown('emails.idea-status-updated'); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/Models/Category.php: -------------------------------------------------------------------------------- 1 | hasMany(Idea::class); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /app/Models/Comment.php: -------------------------------------------------------------------------------- 1 | belongsTo(User::class); 19 | } 20 | 21 | public function idea() 22 | { 23 | return $this->belongsTo(Idea::class); 24 | } 25 | 26 | public function status() 27 | { 28 | return $this->belongsTo(Status::class); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Models/Idea.php: -------------------------------------------------------------------------------- 1 | hasMany(Comment::class); 21 | } 22 | 23 | /** 24 | * Return the sluggable configuration array for this model. 25 | * 26 | * @return array 27 | */ 28 | public function sluggable(): array 29 | { 30 | return [ 31 | 'slug' => [ 32 | 'source' => 'title' 33 | ] 34 | ]; 35 | } 36 | 37 | public function user() 38 | { 39 | return $this->belongsTo(User::class); 40 | } 41 | 42 | public function category() 43 | { 44 | return $this->belongsTo(Category::class); 45 | } 46 | 47 | public function status() 48 | { 49 | return $this->belongsTo(Status::class); 50 | } 51 | 52 | public function votes() 53 | { 54 | return $this->belongsToMany(User::class, 'votes'); 55 | } 56 | 57 | public function isVotedByUser(?User $user) 58 | { 59 | if (!$user) { 60 | return false; 61 | } 62 | 63 | return Vote::where('user_id', $user->id) 64 | ->where('idea_id', $this->id) 65 | ->exists(); 66 | } 67 | 68 | public function vote(User $user) 69 | { 70 | if ($this->isVotedByUser($user)) { 71 | throw new DuplicateVoteException; 72 | } 73 | 74 | Vote::create([ 75 | 'idea_id' => $this->id, 76 | 'user_id' => $user->id, 77 | ]); 78 | } 79 | 80 | public function removeVote(User $user) 81 | { 82 | $voteToDelete = Vote::where('idea_id', $this->id) 83 | ->where('user_id', $user->id) 84 | ->first(); 85 | 86 | if ($voteToDelete) { 87 | $voteToDelete->delete(); 88 | } else { 89 | throw new VoteNotFoundException; 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /app/Models/Status.php: -------------------------------------------------------------------------------- 1 | hasMany(Idea::class); 15 | } 16 | 17 | public static function getCount() 18 | { 19 | return Idea::query() 20 | ->selectRaw("count(*) as all_statuses") 21 | ->selectRaw("count(case when status_id = 1 then 1 end) as open") 22 | ->selectRaw("count(case when status_id = 2 then 1 end) as considering") 23 | ->selectRaw("count(case when status_id = 3 then 1 end) as in_progress") 24 | ->selectRaw("count(case when status_id = 4 then 1 end) as implemented") 25 | ->selectRaw("count(case when status_id = 5 then 1 end) as closed") 26 | ->first() 27 | ->toArray(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/Models/User.php: -------------------------------------------------------------------------------- 1 | 'datetime', 42 | ]; 43 | 44 | public function ideas() 45 | { 46 | return $this->hasMany(Idea::class); 47 | } 48 | 49 | public function comments() 50 | { 51 | return $this->hasMany(Comment::class); 52 | } 53 | 54 | public function votes() 55 | { 56 | return $this->belongsToMany(Idea::class, 'votes'); 57 | } 58 | 59 | public function getAvatar() 60 | { 61 | $firstCharacter = $this->email[0]; 62 | 63 | $integerToUse = is_numeric($firstCharacter) 64 | ? ord(strtolower($firstCharacter)) - 21 65 | : ord(strtolower($firstCharacter)) - 96; 66 | 67 | return 'https://www.gravatar.com/avatar/' 68 | .md5($this->email) 69 | .'?s=200' 70 | .'&d=https://s3.amazonaws.com/laracasts/images/forum/avatars/default-avatar-' 71 | .$integerToUse 72 | .'.png'; 73 | } 74 | 75 | public function isAdmin() 76 | { 77 | return in_array($this->email, [ 78 | 'jeffrey@laracasts.com', 79 | 'andre_madarang@hotmail.com', 80 | 'adrian@laracasts.com,' 81 | ]); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/Models/Vote.php: -------------------------------------------------------------------------------- 1 | comment = $comment; 25 | } 26 | 27 | /** 28 | * Get the notification's delivery channels. 29 | * 30 | * @param mixed $notifiable 31 | * @return array 32 | */ 33 | public function via($notifiable) 34 | { 35 | return ['database']; 36 | } 37 | 38 | /** 39 | * Get the mail representation of the notification. 40 | * 41 | * @param mixed $notifiable 42 | * @return \Illuminate\Notifications\Messages\MailMessage 43 | */ 44 | public function toMail($notifiable) 45 | { 46 | return (new MailMessage) 47 | ->subject('Laracasts Voting: A comment was posted on your idea') 48 | ->markdown('emails.comment-added', [ 49 | 'comment' => $this->comment, 50 | ]); 51 | } 52 | 53 | /** 54 | * Get the array representation of the notification. 55 | * 56 | * @param mixed $notifiable 57 | * @return array 58 | */ 59 | public function toArray($notifiable) 60 | { 61 | return [ 62 | 'comment_id' => $this->comment->id, 63 | 'comment_body' => $this->comment->body, 64 | 'user_avatar' => $this->comment->user->getAvatar(), 65 | 'user_name' => $this->comment->user->name, 66 | 'idea_id' => $this->comment->idea->id, 67 | 'idea_slug' => $this->comment->idea->slug, 68 | 'idea_title' => $this->comment->idea->title, 69 | ]; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/Policies/CommentPolicy.php: -------------------------------------------------------------------------------- 1 | id === (int) $comment->user_id; 57 | } 58 | 59 | /** 60 | * Determine whether the user can delete the model. 61 | * 62 | * @param \App\Models\User $user 63 | * @param \App\Models\Comment $comment 64 | * @return mixed 65 | */ 66 | public function delete(User $user, Comment $comment) 67 | { 68 | return $user->id === (int) $comment->user_id || $user->isAdmin(); 69 | } 70 | 71 | /** 72 | * Determine whether the user can restore the model. 73 | * 74 | * @param \App\Models\User $user 75 | * @param \App\Models\Comment $comment 76 | * @return mixed 77 | */ 78 | public function restore(User $user, Comment $comment) 79 | { 80 | // 81 | } 82 | 83 | /** 84 | * Determine whether the user can permanently delete the model. 85 | * 86 | * @param \App\Models\User $user 87 | * @param \App\Models\Comment $comment 88 | * @return mixed 89 | */ 90 | public function forceDelete(User $user, Comment $comment) 91 | { 92 | // 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /app/Policies/IdeaPolicy.php: -------------------------------------------------------------------------------- 1 | id === (int) $idea->user_id 57 | && now()->subHour() <= $idea->created_at; 58 | } 59 | 60 | /** 61 | * Determine whether the user can delete the model. 62 | * 63 | * @param \App\Models\User $user 64 | * @param \App\Models\Idea $idea 65 | * @return mixed 66 | */ 67 | public function delete(User $user, Idea $idea) 68 | { 69 | return $user->id === (int) $idea->user_id || $user->isAdmin(); 70 | } 71 | 72 | /** 73 | * Determine whether the user can restore the model. 74 | * 75 | * @param \App\Models\User $user 76 | * @param \App\Models\Idea $idea 77 | * @return mixed 78 | */ 79 | public function restore(User $user, Idea $idea) 80 | { 81 | // 82 | } 83 | 84 | /** 85 | * Determine whether the user can permanently delete the model. 86 | * 87 | * @param \App\Models\User $user 88 | * @param \App\Models\Idea $idea 89 | * @return mixed 90 | */ 91 | public function forceDelete(User $user, Idea $idea) 92 | { 93 | // 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | check() && auth()->user()->isAdmin(); 29 | }); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/Providers/AuthServiceProvider.php: -------------------------------------------------------------------------------- 1 | 'App\Policies\ModelPolicy', 17 | ]; 18 | 19 | /** 20 | * Register any authentication / authorization services. 21 | * 22 | * @return void 23 | */ 24 | public function boot() 25 | { 26 | $this->registerPolicies(); 27 | 28 | // 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Providers/BroadcastServiceProvider.php: -------------------------------------------------------------------------------- 1 | [ 19 | SendEmailVerificationNotification::class, 20 | ], 21 | ]; 22 | 23 | /** 24 | * Register any events for your application. 25 | * 26 | * @return void 27 | */ 28 | public function boot() 29 | { 30 | // 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Providers/HorizonServiceProvider.php: -------------------------------------------------------------------------------- 1 | email, [ 38 | 'jeffrey@laracasts.com', 39 | 'andre_madarang@hotmail.com', 40 | 'adrian@laracasts.com,' 41 | ]); 42 | }); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/Providers/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | configureRateLimiting(); 39 | 40 | $this->routes(function () { 41 | Route::prefix('api') 42 | ->middleware('api') 43 | ->namespace($this->namespace) 44 | ->group(base_path('routes/api.php')); 45 | 46 | Route::middleware('web') 47 | ->namespace($this->namespace) 48 | ->group(base_path('routes/web.php')); 49 | }); 50 | } 51 | 52 | /** 53 | * Configure the rate limiters for the application. 54 | * 55 | * @return void 56 | */ 57 | protected function configureRateLimiting() 58 | { 59 | RateLimiter::for('api', function (Request $request) { 60 | return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip()); 61 | }); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /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": [ 6 | "framework", 7 | "laravel" 8 | ], 9 | "license": "MIT", 10 | "require": { 11 | "php": "^7.3|^8.0", 12 | "cviebrock/eloquent-sluggable": "^8.0", 13 | "fideloper/proxy": "^4.4", 14 | "fruitcake/laravel-cors": "^2.0", 15 | "guzzlehttp/guzzle": "^7.0.1", 16 | "laravel/framework": "^8.12", 17 | "laravel/horizon": "^5.7", 18 | "laravel/tinker": "^2.5", 19 | "livewire/livewire": "^2.4" 20 | }, 21 | "require-dev": { 22 | "barryvdh/laravel-debugbar": "^3.5", 23 | "brianium/paratest": "^6.2", 24 | "facade/ignition": "^2.5", 25 | "fakerphp/faker": "^1.9.1", 26 | "laravel/breeze": "^1.1", 27 | "laravel/sail": "^1.0.1", 28 | "mockery/mockery": "^1.4.2", 29 | "nunomaduro/collision": "^5.0", 30 | "phpunit/phpunit": "^9.3.3" 31 | }, 32 | "config": { 33 | "optimize-autoloader": true, 34 | "preferred-install": "dist", 35 | "sort-packages": true 36 | }, 37 | "extra": { 38 | "laravel": { 39 | "dont-discover": [] 40 | } 41 | }, 42 | "autoload": { 43 | "psr-4": { 44 | "App\\": "app/", 45 | "Database\\Factories\\": "database/factories/", 46 | "Database\\Seeders\\": "database/seeders/" 47 | } 48 | }, 49 | "autoload-dev": { 50 | "psr-4": { 51 | "Tests\\": "tests/" 52 | } 53 | }, 54 | "minimum-stability": "dev", 55 | "prefer-stable": true, 56 | "scripts": { 57 | "post-autoload-dump": [ 58 | "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", 59 | "@php artisan package:discover --ansi" 60 | ], 61 | "post-root-package-install": [ 62 | "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 63 | ], 64 | "post-create-project-cmd": [ 65 | "@php artisan key:generate --ansi" 66 | ] 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /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 | 'cluster' => env('PUSHER_APP_CLUSTER'), 40 | 'useTLS' => true, 41 | ], 42 | ], 43 | 44 | 'ably' => [ 45 | 'driver' => 'ably', 46 | 'key' => env('ABLY_KEY'), 47 | ], 48 | 49 | 'redis' => [ 50 | 'driver' => 'redis', 51 | 'connection' => 'default', 52 | ], 53 | 54 | 'log' => [ 55 | 'driver' => 'log', 56 | ], 57 | 58 | 'null' => [ 59 | 'driver' => 'null', 60 | ], 61 | 62 | ], 63 | 64 | ]; 65 | -------------------------------------------------------------------------------- /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_DRIVER', '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 setup for each driver as an example of the required options. 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 | ], 37 | 38 | 'public' => [ 39 | 'driver' => 'local', 40 | 'root' => storage_path('app/public'), 41 | 'url' => env('APP_URL').'/storage', 42 | 'visibility' => 'public', 43 | ], 44 | 45 | 's3' => [ 46 | 'driver' => 's3', 47 | 'key' => env('AWS_ACCESS_KEY_ID'), 48 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 49 | 'region' => env('AWS_DEFAULT_REGION'), 50 | 'bucket' => env('AWS_BUCKET'), 51 | 'url' => env('AWS_URL'), 52 | 'endpoint' => env('AWS_ENDPOINT'), 53 | ], 54 | 55 | ], 56 | 57 | /* 58 | |-------------------------------------------------------------------------- 59 | | Symbolic Links 60 | |-------------------------------------------------------------------------- 61 | | 62 | | Here you may configure the symbolic links that will be created when the 63 | | `storage:link` Artisan command is executed. The array keys should be 64 | | the locations of the links and the values should be their targets. 65 | | 66 | */ 67 | 68 | 'links' => [ 69 | public_path('storage') => storage_path('app/public'), 70 | ], 71 | 72 | ]; 73 | -------------------------------------------------------------------------------- /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' => 1024, 48 | 'threads' => 2, 49 | 'time' => 2, 50 | ], 51 | 52 | ]; 53 | -------------------------------------------------------------------------------- /config/logging.php: -------------------------------------------------------------------------------- 1 | env('LOG_CHANNEL', 'stack'), 21 | 22 | /* 23 | |-------------------------------------------------------------------------- 24 | | Log Channels 25 | |-------------------------------------------------------------------------- 26 | | 27 | | Here you may configure the log channels for your application. Out of 28 | | the box, Laravel uses the Monolog PHP logging library. This gives 29 | | you a variety of powerful log handlers / formatters to utilize. 30 | | 31 | | Available Drivers: "single", "daily", "slack", "syslog", 32 | | "errorlog", "monolog", 33 | | "custom", "stack" 34 | | 35 | */ 36 | 37 | 'channels' => [ 38 | 'stack' => [ 39 | 'driver' => 'stack', 40 | 'channels' => ['single'], 41 | 'ignore_exceptions' => false, 42 | ], 43 | 44 | 'single' => [ 45 | 'driver' => 'single', 46 | 'path' => storage_path('logs/laravel.log'), 47 | 'level' => env('LOG_LEVEL', 'debug'), 48 | ], 49 | 50 | 'daily' => [ 51 | 'driver' => 'daily', 52 | 'path' => storage_path('logs/laravel.log'), 53 | 'level' => env('LOG_LEVEL', 'debug'), 54 | 'days' => 14, 55 | ], 56 | 57 | 'slack' => [ 58 | 'driver' => 'slack', 59 | 'url' => env('LOG_SLACK_WEBHOOK_URL'), 60 | 'username' => 'Laravel Log', 61 | 'emoji' => ':boom:', 62 | 'level' => env('LOG_LEVEL', 'critical'), 63 | ], 64 | 65 | 'papertrail' => [ 66 | 'driver' => 'monolog', 67 | 'level' => env('LOG_LEVEL', 'debug'), 68 | 'handler' => SyslogUdpHandler::class, 69 | 'handler_with' => [ 70 | 'host' => env('PAPERTRAIL_URL'), 71 | 'port' => env('PAPERTRAIL_PORT'), 72 | ], 73 | ], 74 | 75 | 'stderr' => [ 76 | 'driver' => 'monolog', 77 | 'handler' => StreamHandler::class, 78 | 'formatter' => env('LOG_STDERR_FORMATTER'), 79 | 'with' => [ 80 | 'stream' => 'php://stderr', 81 | ], 82 | ], 83 | 84 | 'syslog' => [ 85 | 'driver' => 'syslog', 86 | 'level' => env('LOG_LEVEL', 'debug'), 87 | ], 88 | 89 | 'errorlog' => [ 90 | 'driver' => 'errorlog', 91 | 'level' => env('LOG_LEVEL', 'debug'), 92 | ], 93 | 94 | 'null' => [ 95 | 'driver' => 'monolog', 96 | 'handler' => NullHandler::class, 97 | ], 98 | 99 | 'emergency' => [ 100 | 'path' => storage_path('logs/laravel.log'), 101 | ], 102 | ], 103 | 104 | ]; 105 | -------------------------------------------------------------------------------- /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 | ], 43 | 44 | 'beanstalkd' => [ 45 | 'driver' => 'beanstalkd', 46 | 'host' => 'localhost', 47 | 'queue' => 'default', 48 | 'retry_after' => 90, 49 | 'block_for' => 0, 50 | ], 51 | 52 | 'sqs' => [ 53 | 'driver' => 'sqs', 54 | 'key' => env('AWS_ACCESS_KEY_ID'), 55 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 56 | 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), 57 | 'queue' => env('SQS_QUEUE', 'your-queue-name'), 58 | 'suffix' => env('SQS_SUFFIX'), 59 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 60 | ], 61 | 62 | 'redis' => [ 63 | 'driver' => 'redis', 64 | 'connection' => 'default', 65 | 'queue' => env('REDIS_QUEUE', 'default'), 66 | 'retry_after' => 90, 67 | 'block_for' => null, 68 | ], 69 | 70 | ], 71 | 72 | /* 73 | |-------------------------------------------------------------------------- 74 | | Failed Queue Jobs 75 | |-------------------------------------------------------------------------- 76 | | 77 | | These options configure the behavior of failed queue job logging so you 78 | | can control which database and table are used to store the jobs that 79 | | have failed. You may change them to any database / table you wish. 80 | | 81 | */ 82 | 83 | 'failed' => [ 84 | 'driver' => env('QUEUE_FAILED_DRIVER', 'database-uuids'), 85 | 'database' => env('DB_CONNECTION', 'mysql'), 86 | 'table' => 'failed_jobs', 87 | ], 88 | 89 | ]; 90 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'domain' => env('MAILGUN_DOMAIN'), 19 | 'secret' => env('MAILGUN_SECRET'), 20 | 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), 21 | ], 22 | 23 | 'postmark' => [ 24 | 'token' => env('POSTMARK_TOKEN'), 25 | ], 26 | 27 | 'ses' => [ 28 | 'key' => env('AWS_ACCESS_KEY_ID'), 29 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 30 | 'region' => env('AWS_DEFAULT_REGION', 'us-east-1'), 31 | ], 32 | 33 | ]; 34 | -------------------------------------------------------------------------------- /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 | *.sqlite-journal 3 | -------------------------------------------------------------------------------- /database/factories/CategoryFactory.php: -------------------------------------------------------------------------------- 1 | $this->faker->words(2, true), 26 | ]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /database/factories/CommentFactory.php: -------------------------------------------------------------------------------- 1 | User::factory(), 29 | 'idea_id' => Idea::factory(), 30 | 'status_id' => Status::factory(), 31 | 'body' => $this->faker->paragraph(5), 32 | ]; 33 | } 34 | 35 | public function existing() 36 | { 37 | return $this->state(function (array $attributes) { 38 | return [ 39 | 'user_id' => $this->faker->numberBetween(1, 20), 40 | 'status_id' => 1, 41 | ]; 42 | }); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /database/factories/IdeaFactory.php: -------------------------------------------------------------------------------- 1 | User::factory(), 29 | 'category_id' => Category::factory(), 30 | 'status_id' => Status::factory(), 31 | 'title' => ucwords($this->faker->words(4, true)), 32 | 'description' => $this->faker->paragraph(5), 33 | ]; 34 | } 35 | 36 | public function existing() 37 | { 38 | return $this->state(function (array $attributes) { 39 | return [ 40 | 'user_id' => $this->faker->numberBetween(1, 20), 41 | 'category_id' => $this->faker->numberBetween(1, 4), 42 | 'status_id' => $this->faker->numberBetween(1, 5), 43 | ]; 44 | }); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /database/factories/StatusFactory.php: -------------------------------------------------------------------------------- 1 | $this->faker->words(2, true), 26 | ]; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | $this->faker->firstName, 27 | 'email' => $this->faker->unique()->safeEmail, 28 | 'email_verified_at' => now(), 29 | 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password 30 | 'remember_token' => Str::random(10), 31 | ]; 32 | } 33 | 34 | public function admin() 35 | { 36 | return $this->state(function (array $attributes) { 37 | return [ 38 | 'email' => 'andre_madarang@hotmail.com', 39 | ]; 40 | }); 41 | } 42 | 43 | /** 44 | * Indicate that the model's email address should be unverified. 45 | * 46 | * @return \Illuminate\Database\Eloquent\Factories\Factory 47 | */ 48 | public function unverified() 49 | { 50 | return $this->state(function (array $attributes) { 51 | return [ 52 | 'email_verified_at' => null, 53 | ]; 54 | }); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /database/factories/VoteFactory.php: -------------------------------------------------------------------------------- 1 | $this->faker->numberBetween(1, 100), 26 | 'user_id' => $this->faker->numberBetween(1, 20), 27 | ]; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('name'); 19 | $table->string('email')->unique(); 20 | $table->timestamp('email_verified_at')->nullable(); 21 | $table->string('password'); 22 | $table->rememberToken(); 23 | $table->timestamps(); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('users'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_100000_create_password_resets_table.php: -------------------------------------------------------------------------------- 1 | string('email')->index(); 18 | $table->string('token'); 19 | $table->timestamp('created_at')->nullable(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | * 26 | * @return void 27 | */ 28 | public function down() 29 | { 30 | Schema::dropIfExists('password_resets'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/migrations/2019_08_19_000000_create_failed_jobs_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('uuid')->unique(); 19 | $table->text('connection'); 20 | $table->text('queue'); 21 | $table->longText('payload'); 22 | $table->longText('exception'); 23 | $table->timestamp('failed_at')->useCurrent(); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('failed_jobs'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /database/migrations/2021_02_24_012947_create_statuses_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('name'); 19 | $table->timestamps(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | * 26 | * @return void 27 | */ 28 | public function down() 29 | { 30 | Schema::dropIfExists('statuses'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/migrations/2021_02_25_012947_create_categories_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->string('name'); 19 | $table->timestamps(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | * 26 | * @return void 27 | */ 28 | public function down() 29 | { 30 | Schema::dropIfExists('categories'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/migrations/2021_02_26_012947_create_ideas_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->foreignId('user_id')->constrained(); 19 | $table->foreignId('category_id')->constrained(); 20 | $table->foreignId('status_id')->constrained(); 21 | $table->string('title'); 22 | $table->string('slug')->nullable(); 23 | $table->text('description'); 24 | $table->integer('spam_reports')->default(0); 25 | $table->timestamps(); 26 | }); 27 | } 28 | 29 | /** 30 | * Reverse the migrations. 31 | * 32 | * @return void 33 | */ 34 | public function down() 35 | { 36 | Schema::dropIfExists('ideas'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /database/migrations/2021_03_05_061517_create_votes_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->unique(['idea_id', 'user_id']); 19 | $table->foreignId('idea_id')->constrained()->onDelete('cascade'); 20 | $table->foreignId('user_id')->constrained(); 21 | $table->timestamps(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | * 28 | * @return void 29 | */ 30 | public function down() 31 | { 32 | Schema::dropIfExists('votes'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /database/migrations/2021_05_04_065809_create_comments_table.php: -------------------------------------------------------------------------------- 1 | id(); 18 | $table->foreignId('user_id')->constrained(); 19 | $table->foreignId('idea_id')->constrained()->onDelete('cascade'); 20 | $table->foreignId('status_id')->constrained(); 21 | $table->text('body'); 22 | $table->integer('spam_reports')->default(0); 23 | $table->boolean('is_status_update')->default(false); 24 | $table->timestamps(); 25 | }); 26 | } 27 | 28 | /** 29 | * Reverse the migrations. 30 | * 31 | * @return void 32 | */ 33 | public function down() 34 | { 35 | Schema::dropIfExists('comments'); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /database/migrations/2021_05_26_024309_create_notifications_table.php: -------------------------------------------------------------------------------- 1 | uuid('id')->primary(); 18 | $table->string('type'); 19 | $table->morphs('notifiable'); 20 | $table->text('data'); 21 | $table->timestamp('read_at')->nullable(); 22 | $table->timestamps(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | Schema::dropIfExists('notifications'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /database/seeders/CategorySeeder.php: -------------------------------------------------------------------------------- 1 | create([ 23 | 'name' => 'Andre', 24 | 'email' => 'andre_madarang@hotmail.com', 25 | ]); 26 | 27 | User::factory(19)->create(); 28 | 29 | Category::factory()->create(['name' => 'Category 1']); 30 | Category::factory()->create(['name' => 'Category 2']); 31 | Category::factory()->create(['name' => 'Category 3']); 32 | Category::factory()->create(['name' => 'Category 4']); 33 | 34 | Status::factory()->create(['name' => 'Open']); 35 | Status::factory()->create(['name' => 'Considering']); 36 | Status::factory()->create(['name' => 'In Progress']); 37 | Status::factory()->create(['name' => 'Implemented']); 38 | Status::factory()->create(['name' => 'Closed']); 39 | 40 | Idea::factory(100)->existing()->create(); 41 | 42 | // Generate unique votes. Ensure idea_id and user_id are unique for each row 43 | foreach (range(1, 20) as $user_id) { 44 | foreach (range(1, 100) as $idea_id) { 45 | if ($idea_id % 2 === 0) { 46 | Vote::factory()->create([ 47 | 'user_id' => $user_id, 48 | 'idea_id' => $idea_id, 49 | ]); 50 | } 51 | } 52 | } 53 | 54 | // Generate comments for ideas 55 | foreach (Idea::all() as $idea) { 56 | Comment::factory(5)->existing()->create(['idea_id' => $idea->id]); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /database/seeders/IdeaSeeder.php: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | ./tests/Unit 10 | 11 | 12 | ./tests/Feature 13 | 14 | 15 | 16 | 17 | ./app 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /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/android-chrome-192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drehimself/lc-voting/6b83643a9f993bcbc26673745ac5b3d4ff7116fc/public/android-chrome-192x192.png -------------------------------------------------------------------------------- /public/android-chrome-512x512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drehimself/lc-voting/6b83643a9f993bcbc26673745ac5b3d4ff7116fc/public/android-chrome-512x512.png -------------------------------------------------------------------------------- /public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drehimself/lc-voting/6b83643a9f993bcbc26673745ac5b3d4ff7116fc/public/apple-touch-icon.png -------------------------------------------------------------------------------- /public/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drehimself/lc-voting/6b83643a9f993bcbc26673745ac5b3d4ff7116fc/public/favicon-16x16.png -------------------------------------------------------------------------------- /public/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drehimself/lc-voting/6b83643a9f993bcbc26673745ac5b3d4ff7116fc/public/favicon-32x32.png -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drehimself/lc-voting/6b83643a9f993bcbc26673745ac5b3d4ff7116fc/public/favicon.ico -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | make(Kernel::class); 50 | 51 | $response = tap($kernel->handle( 52 | $request = Request::capture() 53 | ))->send(); 54 | 55 | $kernel->terminate($request, $response); 56 | -------------------------------------------------------------------------------- /public/mix-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "/js/app.js": "/js/app.js", 3 | "/css/app.css": "/css/app.css" 4 | } 5 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /public/site.webmanifest: -------------------------------------------------------------------------------- 1 | {"name":"","short_name":"","icons":[{"src":"/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"} -------------------------------------------------------------------------------- /public/vendor/horizon/img/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drehimself/lc-voting/6b83643a9f993bcbc26673745ac5b3d4ff7116fc/public/vendor/horizon/img/favicon.png -------------------------------------------------------------------------------- /public/vendor/horizon/img/horizon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /public/vendor/horizon/mix-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "/app.js": "/app.js?id=99fb159344b4a6ba38fb", 3 | "/app-dark.css": "/app-dark.css?id=edbb1f9207a3bd43def0", 4 | "/app.css": "/app.css?id=3e3a5d91794d59a5417d", 5 | "/img/favicon.png": "/img/favicon.png?id=1542bfe8a0010dcbee71" 6 | } 7 | -------------------------------------------------------------------------------- /public/web.config: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /resources/css/app.css: -------------------------------------------------------------------------------- 1 | @import 'tailwindcss/base'; 2 | @import 'tailwindcss/components'; 3 | @import 'tailwindcss/utilities'; 4 | 5 | [x-cloak] { 6 | display: none !important; 7 | } 8 | 9 | /* vertical line to the left of the comments */ 10 | .comments-container::before { 11 | position: absolute; 12 | display: block; 13 | top: 0; 14 | left: -40px; 15 | content: ""; 16 | width: 3px; 17 | height: 100%; 18 | background: #edf0f5; 19 | } 20 | 21 | .is-status-update.comment-container:last-child::after { 22 | left: -41px; 23 | } 24 | 25 | /* horizontal line to the left of the comments */ 26 | .comment-container::before { 27 | position: absolute; 28 | display: block; 29 | top: 57px; 30 | content: ""; 31 | width: 23px; 32 | height: 3px; 33 | background: #edf0f5; 34 | left: -40px; 35 | } 36 | 37 | /* remove last vertical line */ 38 | .comment-container:last-child::after { 39 | position: absolute; 40 | display: block; 41 | top: 60px; 42 | left: -40px; 43 | content: ""; 44 | width: 3px; 45 | height: calc(100% - 60px); 46 | background: theme('colors.gray-background'); 47 | } 48 | 49 | .is-status-update::before { 50 | position: absolute; 51 | width: 38px; 52 | height: 38px; 53 | border-radius: 38px; 54 | border: 7px solid white; 55 | box-shadow: 4px 4px 15px 0 rgba(36, 37, 38, 0.08); 56 | left: -58px; 57 | background: theme('colors.purple'); 58 | opacity: 1; 59 | z-index: 1; 60 | } 61 | 62 | .is-status-update { 63 | border-width: 1px; 64 | border-image-source: linear-gradient(266deg, #21c8f6 98%, #637bff -52%); 65 | background-image: linear-gradient(to bottom, #ffffff, #ffffff), linear-gradient(266deg, #21c8f6 98%, #637bff -52%); 66 | background-origin: border-box; 67 | background-clip: content-box, border-box; 68 | } 69 | 70 | .status-open, .status-open:before { 71 | @apply bg-gray-200; 72 | } 73 | 74 | .status-considering, .status-considering:before { 75 | @apply bg-purple text-white; 76 | } 77 | 78 | .status-in-progress, .status-in-progress:before { 79 | @apply bg-yellow text-white; 80 | } 81 | 82 | .status-implemented, .status-implemented:before { 83 | @apply bg-green text-white; 84 | } 85 | 86 | .status-closed, .status-closed:before { 87 | @apply bg-red text-white; 88 | } 89 | -------------------------------------------------------------------------------- /resources/js/app.js: -------------------------------------------------------------------------------- 1 | require('./bootstrap'); 2 | 3 | require('alpinejs'); 4 | -------------------------------------------------------------------------------- /resources/js/bootstrap.js: -------------------------------------------------------------------------------- 1 | window._ = require('lodash'); 2 | 3 | /** 4 | * We'll load the axios HTTP library which allows us to easily issue requests 5 | * to our Laravel back-end. This library automatically handles sending the 6 | * CSRF token as a header based on the value of the "XSRF" token cookie. 7 | */ 8 | 9 | window.axios = require('axios'); 10 | 11 | window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 12 | 13 | /** 14 | * Echo exposes an expressive API for subscribing to channels and listening 15 | * for events that are broadcast by Laravel. Echo and event broadcasting 16 | * allows your team to easily build robust real-time web applications. 17 | */ 18 | 19 | // import Echo from 'laravel-echo'; 20 | 21 | // window.Pusher = require('pusher-js'); 22 | 23 | // window.Echo = new Echo({ 24 | // broadcaster: 'pusher', 25 | // key: process.env.MIX_PUSHER_APP_KEY, 26 | // cluster: process.env.MIX_PUSHER_APP_CLUSTER, 27 | // forceTLS: true 28 | // }); 29 | -------------------------------------------------------------------------------- /resources/lang/en/auth.php: -------------------------------------------------------------------------------- 1 | 'These credentials do not match our records.', 17 | 'password' => 'The provided password is incorrect.', 18 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 19 | 20 | ]; 21 | -------------------------------------------------------------------------------- /resources/lang/en/pagination.php: -------------------------------------------------------------------------------- 1 | '« Previous', 17 | 'next' => 'Next »', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /resources/lang/en/passwords.php: -------------------------------------------------------------------------------- 1 | 'Your password has been reset!', 17 | 'sent' => 'We have emailed your password reset link!', 18 | 'throttled' => 'Please wait before retrying.', 19 | 'token' => 'This password reset token is invalid.', 20 | 'user' => "We can't find a user with that email address.", 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /resources/views/auth/confirm-password.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | {{ __('This is a secure area of the application. Please confirm your password before continuing.') }} 11 |
12 | 13 | 14 | 15 | 16 |
17 | @csrf 18 | 19 | 20 |
21 | 22 | 23 | 27 |
28 | 29 |
30 | 31 | {{ __('Confirm') }} 32 | 33 |
34 |
35 |
36 |
37 | -------------------------------------------------------------------------------- /resources/views/auth/forgot-password.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | {{ __('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.') }} 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | @csrf 21 | 22 | 23 |
24 | 25 | 26 | 27 |
28 | 29 |
30 | 31 | {{ __('Email Password Reset Link') }} 32 | 33 |
34 |
35 |
36 |
37 | -------------------------------------------------------------------------------- /resources/views/auth/login.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | @csrf 17 | 18 | 19 |
20 | 21 | 22 | 23 |
24 | 25 | 26 |
27 | 28 | 29 | 33 |
34 | 35 | 36 |
37 | 41 |
42 | 43 |
44 | @if (Route::has('password.request')) 45 | 46 | {{ __('Forgot your password?') }} 47 | 48 | @endif 49 | 50 | 51 | {{ __('Log in') }} 52 | 53 |
54 |
55 |
56 |
57 | -------------------------------------------------------------------------------- /resources/views/auth/register.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | @csrf 14 | 15 | 16 |
17 | 18 | 19 | 20 |
21 | 22 | 23 |
24 | 25 | 26 | 27 |
28 | 29 | 30 |
31 | 32 | 33 | 37 |
38 | 39 | 40 |
41 | 42 | 43 | 46 |
47 | 48 |
49 | 50 | {{ __('Already registered?') }} 51 | 52 | 53 | 54 | {{ __('Register') }} 55 | 56 |
57 |
58 |
59 |
60 | -------------------------------------------------------------------------------- /resources/views/auth/reset-password.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | @csrf 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 |
24 | 25 | 26 |
27 | 28 | 29 | 30 |
31 | 32 | 33 |
34 | 35 | 36 | 39 |
40 | 41 |
42 | 43 | {{ __('Reset Password') }} 44 | 45 |
46 |
47 |
48 |
49 | -------------------------------------------------------------------------------- /resources/views/auth/verify-email.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | {{ __('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.') }} 11 |
12 | 13 | @if (session('status') == 'verification-link-sent') 14 |
15 | {{ __('A new verification link has been sent to the email address you provided during registration.') }} 16 |
17 | @endif 18 | 19 |
20 |
21 | @csrf 22 | 23 |
24 | 25 | {{ __('Resend Verification Email') }} 26 | 27 |
28 |
29 | 30 |
31 | @csrf 32 | 33 | 36 |
37 |
38 |
39 |
40 | -------------------------------------------------------------------------------- /resources/views/components/application-logo.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources/views/components/auth-card.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | {{ $logo }} 4 |
5 | 6 |
7 | {{ $slot }} 8 |
9 |
10 | -------------------------------------------------------------------------------- /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/auth-validation-errors.blade.php: -------------------------------------------------------------------------------- 1 | @props(['errors']) 2 | 3 | @if ($errors->any()) 4 |
5 |
6 | {{ __('Whoops! Something went wrong.') }} 7 |
8 | 9 | 14 |
15 | @endif 16 | -------------------------------------------------------------------------------- /resources/views/components/button.blade.php: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /resources/views/components/dropdown-link.blade.php: -------------------------------------------------------------------------------- 1 | merge(['class' => 'block px-4 py-2 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.blade.php: -------------------------------------------------------------------------------- 1 | @props(['disabled' => false]) 2 | 3 | merge(['class' => 'rounded-md shadow-sm border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50']) !!}> 4 | -------------------------------------------------------------------------------- /resources/views/components/label.blade.php: -------------------------------------------------------------------------------- 1 | @props(['value']) 2 | 3 | 6 | -------------------------------------------------------------------------------- /resources/views/components/modals-container.blade.php: -------------------------------------------------------------------------------- 1 | @can('update', $idea) 2 | 3 | @endcan 4 | 5 | @can('delete', $idea) 6 | 7 | @endcan 8 | 9 | @auth 10 | 11 | @endauth 12 | 13 | @admin 14 | 15 | @endadmin 16 | 17 | @auth 18 | 19 | @endauth 20 | 21 | @auth 22 | 23 | @endauth 24 | 25 | @auth 26 | 27 | @endauth 28 | 29 | @admin 30 | 31 | @endadmin 32 | -------------------------------------------------------------------------------- /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/responsive-nav-link.blade.php: -------------------------------------------------------------------------------- 1 | @props(['active']) 2 | 3 | @php 4 | $classes = ($active ?? false) 5 | ? 'block pl-3 pr-4 py-2 border-l-4 border-indigo-400 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 pl-3 pr-4 py-2 border-l-4 border-transparent 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/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/emails/comment-added.blade.php: -------------------------------------------------------------------------------- 1 | @component('mail::message') 2 | # A comment was posted on your idea 3 | 4 | {{ $comment->user->name }} commented on your idea: 5 | 6 | **{{ $comment->idea->title }}** 7 | 8 | Comment: {{ $comment->body }} 9 | 10 | @component('mail::button', ['url' => route('idea.show', $comment->idea)]) 11 | Go to Idea 12 | @endcomponent 13 | 14 | Thanks,
15 | {{ config('app.name') }} 16 | @endcomponent 17 | -------------------------------------------------------------------------------- /resources/views/emails/idea-status-updated.blade.php: -------------------------------------------------------------------------------- 1 | @component('mail::message') 2 | # Idea Status Updated 3 | 4 | The idea: {{ $idea->title }} 5 | 6 | has been updated to a status of: 7 | 8 | {{ $idea->status->name }} 9 | 10 | @component('mail::button', ['url' => route('idea.show', $idea)]) 11 | View Idea 12 | @endcomponent 13 | 14 | Thanks,
15 | {{ config('app.name') }} 16 | @endcomponent 17 | -------------------------------------------------------------------------------- /resources/views/idea/index.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /resources/views/idea/show.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | {{ $idea->title }} | Laracasts Voting 4 | 5 | 13 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /resources/views/layouts/guest.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Laracasts Voting 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | {{ $slot }} 27 |
28 | 29 | 30 | -------------------------------------------------------------------------------- /resources/views/livewire/delete-comment.blade.php: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /resources/views/livewire/delete-idea.blade.php: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /resources/views/livewire/idea-comments.blade.php: -------------------------------------------------------------------------------- 1 |
2 | @if ($comments->isNotEmpty()) 3 | 4 |
5 | 6 | @foreach ($comments as $comment) 7 | 12 | @endforeach 13 |
14 | 15 |
16 | {{ $comments->onEachSide(1)->links() }} 17 |
18 | @else 19 |
20 | No Ideas 21 |
No comments yet...
22 |
23 | @endif 24 |
25 | -------------------------------------------------------------------------------- /resources/views/livewire/ideas-index.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 10 |
11 |
12 | 21 |
22 |
23 | 24 |
25 | 26 | 27 | 28 |
29 |
30 |
31 | 32 |
33 | @forelse ($ideas as $idea) 34 | 39 | @empty 40 |
41 | No Ideas 42 |
No ideas were found...
43 |
44 | @endforelse 45 |
46 | 47 |
48 | {{ $ideas->links() }} 49 |
50 |
51 | -------------------------------------------------------------------------------- /resources/views/livewire/mark-comment-as-not-spam.blade.php: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /resources/views/livewire/mark-comment-as-spam.blade.php: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /resources/views/livewire/mark-idea-as-not-spam.blade.php: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /resources/views/livewire/mark-idea-as-spam.blade.php: -------------------------------------------------------------------------------- 1 | 9 | -------------------------------------------------------------------------------- /resources/views/livewire/status-filters.blade.php: -------------------------------------------------------------------------------- 1 | 13 | -------------------------------------------------------------------------------- /routes/api.php: -------------------------------------------------------------------------------- 1 | get('/user', function (Request $request) { 18 | return $request->user(); 19 | }); 20 | -------------------------------------------------------------------------------- /routes/auth.php: -------------------------------------------------------------------------------- 1 | middleware('guest') 15 | ->name('register'); 16 | 17 | Route::post('/register', [RegisteredUserController::class, 'store']) 18 | ->middleware('guest'); 19 | 20 | Route::get('/login', [AuthenticatedSessionController::class, 'create']) 21 | ->middleware('guest') 22 | ->name('login'); 23 | 24 | Route::post('/login', [AuthenticatedSessionController::class, 'store']) 25 | ->middleware('guest'); 26 | 27 | Route::get('/forgot-password', [PasswordResetLinkController::class, 'create']) 28 | ->middleware('guest') 29 | ->name('password.request'); 30 | 31 | Route::post('/forgot-password', [PasswordResetLinkController::class, 'store']) 32 | ->middleware('guest') 33 | ->name('password.email'); 34 | 35 | Route::get('/reset-password/{token}', [NewPasswordController::class, 'create']) 36 | ->middleware('guest') 37 | ->name('password.reset'); 38 | 39 | Route::post('/reset-password', [NewPasswordController::class, 'store']) 40 | ->middleware('guest') 41 | ->name('password.update'); 42 | 43 | Route::get('/verify-email', [EmailVerificationPromptController::class, '__invoke']) 44 | ->middleware('auth') 45 | ->name('verification.notice'); 46 | 47 | Route::get('/verify-email/{id}/{hash}', [VerifyEmailController::class, '__invoke']) 48 | ->middleware(['auth', 'signed', 'throttle:6,1']) 49 | ->name('verification.verify'); 50 | 51 | Route::post('/email/verification-notification', [EmailVerificationNotificationController::class, 'store']) 52 | ->middleware(['auth', 'throttle:6,1']) 53 | ->name('verification.send'); 54 | 55 | Route::get('/confirm-password', [ConfirmablePasswordController::class, 'show']) 56 | ->middleware('auth') 57 | ->name('password.confirm'); 58 | 59 | Route::post('/confirm-password', [ConfirmablePasswordController::class, 'store']) 60 | ->middleware('auth'); 61 | 62 | Route::post('/logout', [AuthenticatedSessionController::class, 'destroy']) 63 | ->middleware('auth') 64 | ->name('logout'); 65 | -------------------------------------------------------------------------------- /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('idea.index'); 18 | Route::get('/ideas/{idea:slug}', [IdeaController::class, 'show'])->name('idea.show'); 19 | 20 | require __DIR__.'/auth.php'; 21 | -------------------------------------------------------------------------------- /server.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | $uri = urldecode( 11 | parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) 12 | ); 13 | 14 | // This file allows us to emulate Apache's "mod_rewrite" functionality from the 15 | // built-in PHP web server. This provides a convenient way to test a Laravel 16 | // application without having installed a "real" web server software here. 17 | if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { 18 | return false; 19 | } 20 | 21 | require_once __DIR__.'/public/index.php'; 22 | -------------------------------------------------------------------------------- /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 | const colors = require('tailwindcss/colors'); 3 | 4 | module.exports = { 5 | mode: 'jit', 6 | purge: [ 7 | './vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php', 8 | './storage/framework/views/*.php', 9 | './resources/views/**/*.blade.php', 10 | ], 11 | 12 | theme: { 13 | extend: { 14 | colors: { 15 | transparent: 'transparent', 16 | current: 'currentColor', 17 | 18 | black: colors.black, 19 | white: colors.white, 20 | gray: colors.trueGray, 21 | 'gray-background': '#f7f8fc', 22 | 'blue': '#328af1', 23 | 'blue-hover': '#2879bd', 24 | 'yellow' : '#ffc73c', 25 | 'red' : '#ec454f', 26 | 'red-100' : '#fee2e2', 27 | 'green' : '#1aab8b', 28 | 'green-50': '#f0fdf4', 29 | 'purple' : '#8b60ed', 30 | }, 31 | spacing: { 32 | 22: '5.5rem', 33 | 44: '11rem', 34 | 70: '17.5rem', 35 | 76: '19rem', 36 | 104: '26rem', 37 | 128: '32rem', 38 | 175: '43.75rem', 39 | }, 40 | maxWidth: { 41 | custom: '68.5rem', 42 | }, 43 | boxShadow: { 44 | card: '4px 4px 15px 0 rgba(36, 37, 38, 0.08)', 45 | dialog: '3px 4px 15px 0 rgba(36, 37, 38, 0.22)', 46 | }, 47 | fontFamily: { 48 | sans: ['Open Sans', ...defaultTheme.fontFamily.sans], 49 | }, 50 | fontSize: { 51 | xxs: ['0.625rem', { lineHeight: '1rem' }], 52 | }, 53 | }, 54 | }, 55 | 56 | variants: { 57 | extend: { 58 | opacity: ['disabled'], 59 | }, 60 | }, 61 | 62 | plugins: [ 63 | require('@tailwindcss/forms'), 64 | require('@tailwindcss/line-clamp'), 65 | ], 66 | }; 67 | -------------------------------------------------------------------------------- /tests/CreatesApplication.php: -------------------------------------------------------------------------------- 1 | make(Kernel::class)->bootstrap(); 19 | 20 | return $app; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /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() 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() 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() 29 | { 30 | Event::fake(); 31 | 32 | $user = User::factory()->create([ 33 | 'email_verified_at' => null, 34 | ]); 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() 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() 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() 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() 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() 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() 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/RegistrationTest.php: -------------------------------------------------------------------------------- 1 | get('/register'); 16 | 17 | $response->assertStatus(200); 18 | } 19 | 20 | public function test_new_users_can_register() 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/Comments/AddCommentTest.php: -------------------------------------------------------------------------------- 1 | create(); 24 | 25 | $response = $this->get(route('idea.show', $idea)); 26 | 27 | $response->assertSeeLivewire('add-comment'); 28 | } 29 | 30 | /** @test */ 31 | public function add_comment_form_renders_when_user_is_logged_in() 32 | { 33 | $user = User::factory()->create(); 34 | $idea = Idea::factory()->create(); 35 | 36 | $response = $this->actingAs($user)->get(route('idea.show', $idea)); 37 | 38 | $response->assertSee('Share your thoughts'); 39 | } 40 | 41 | /** @test */ 42 | public function add_comment_form_does_not_render_when_user_is_logged_out() 43 | { 44 | $idea = Idea::factory()->create(); 45 | 46 | $response = $this->get(route('idea.show', $idea)); 47 | 48 | $response->assertSee('Please login or create an account to post a comment'); 49 | } 50 | 51 | /** @test */ 52 | public function add_comment_form_validation_works() 53 | { 54 | $user = User::factory()->create(); 55 | $idea = Idea::factory()->create(); 56 | 57 | Livewire::actingAs($user) 58 | ->test(AddComment::class, [ 59 | 'idea' => $idea, 60 | ]) 61 | ->set('comment', '') 62 | ->call('addComment') 63 | ->assertHasErrors(['comment']) 64 | ->set('comment', 'ab') 65 | ->call('addComment') 66 | ->assertHasErrors(['comment']); 67 | } 68 | 69 | /** @test */ 70 | public function add_comment_form__works() 71 | { 72 | $user = User::factory()->create(); 73 | $idea = Idea::factory()->create(); 74 | 75 | Notification::fake(); 76 | 77 | Notification::assertNothingSent(); 78 | 79 | Livewire::actingAs($user) 80 | ->test(AddComment::class, [ 81 | 'idea' => $idea, 82 | ]) 83 | ->set('comment', 'This is my first comment') 84 | ->call('addComment') 85 | ->assertEmitted('commentWasAdded'); 86 | 87 | Notification::assertSentTo( 88 | [$idea->user], 89 | CommentAdded::class 90 | ); 91 | 92 | $this->assertEquals(1, Comment::count()); 93 | $this->assertEquals('This is my first comment', $idea->comments->first()->body); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /tests/Feature/Filters/SearchFilterTest.php: -------------------------------------------------------------------------------- 1 | create([ 22 | 'title' => 'My First Idea', 23 | ]); 24 | 25 | $ideaTwo = Idea::factory()->create([ 26 | 'title' => 'My Second Idea', 27 | ]); 28 | 29 | $ideaThree = Idea::factory()->create([ 30 | 'title' => 'My Third Idea', 31 | ]); 32 | 33 | Livewire::test(IdeasIndex::class) 34 | ->set('search', 'Second') 35 | ->assertViewHas('ideas', function ($ideas) { 36 | return $ideas->count() === 1 37 | && $ideas->first()->title === 'My Second Idea'; 38 | }); 39 | } 40 | 41 | /** @test */ 42 | public function does_not_perform_search_if_less_than_3_characters() 43 | { 44 | $ideaOne = Idea::factory()->create([ 45 | 'title' => 'My First Idea', 46 | ]); 47 | 48 | $ideaTwo = Idea::factory()->create([ 49 | 'title' => 'My Second Idea', 50 | ]); 51 | 52 | $ideaThree = Idea::factory()->create([ 53 | 'title' => 'My Third Idea', 54 | ]); 55 | 56 | Livewire::test(IdeasIndex::class) 57 | ->set('search', 'ab') 58 | ->assertViewHas('ideas', function ($ideas) { 59 | return $ideas->count() === 3; 60 | }); 61 | } 62 | 63 | /** @test */ 64 | public function search_works_correctly_with_category_filters() 65 | { 66 | $categoryOne = Category::factory()->create(['name' => 'Category 1']); 67 | $categoryTwo = Category::factory()->create(['name' => 'Category 2']); 68 | 69 | $statusOpen = Status::factory()->create(['name' => 'Open']); 70 | 71 | $ideaOne = Idea::factory()->create([ 72 | 'category_id' => $categoryOne->id, 73 | 'title' => 'My First Idea', 74 | ]); 75 | 76 | $ideaTwo = Idea::factory()->create([ 77 | 'category_id' => $categoryOne->id, 78 | 'title' => 'My Second Idea', 79 | ]); 80 | 81 | $ideaThree = Idea::factory()->create([ 82 | 'category_id' => $categoryTwo->id, 83 | 'title' => 'My Third Idea', 84 | ]); 85 | 86 | Livewire::test(IdeasIndex::class) 87 | ->set('category', 'Category 1') 88 | ->set('search', 'Idea') 89 | ->assertViewHas('ideas', function ($ideas) { 90 | return $ideas->count() === 2; 91 | }); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /tests/Feature/GravatarTest.php: -------------------------------------------------------------------------------- 1 | create([ 19 | 'email' => 'afakeemail@fakeemail.com', 20 | ]); 21 | 22 | $gravatarUrl = $user->getAvatar(); 23 | 24 | $this->assertEquals( 25 | 'https://www.gravatar.com/avatar/'.md5($user->email).'?s=200&d=https://s3.amazonaws.com/laracasts/images/forum/avatars/default-avatar-1.png', 26 | $gravatarUrl 27 | ); 28 | 29 | $response = Http::get($user->getAvatar()); 30 | 31 | $this->assertTrue($response->successful()); 32 | } 33 | 34 | /** @test */ 35 | public function user_can_generate_gravatar_default_image_when_no_email_found_first_character_z() 36 | { 37 | $user = User::factory()->create([ 38 | 'email' => 'zfakeemail@fakeemail.com', 39 | ]); 40 | 41 | $gravatarUrl = $user->getAvatar(); 42 | 43 | $this->assertEquals( 44 | 'https://www.gravatar.com/avatar/'.md5($user->email).'?s=200&d=https://s3.amazonaws.com/laracasts/images/forum/avatars/default-avatar-26.png', 45 | $gravatarUrl 46 | ); 47 | 48 | $response = Http::get($user->getAvatar()); 49 | 50 | $this->assertTrue($response->successful()); 51 | } 52 | 53 | /** @test */ 54 | public function user_can_generate_gravatar_default_image_when_no_email_found_first_character_0() 55 | { 56 | $user = User::factory()->create([ 57 | 'email' => '0fakeemail@fakeemail.com', 58 | ]); 59 | 60 | $gravatarUrl = $user->getAvatar(); 61 | 62 | $this->assertEquals( 63 | 'https://www.gravatar.com/avatar/'.md5($user->email).'?s=200&d=https://s3.amazonaws.com/laracasts/images/forum/avatars/default-avatar-27.png', 64 | $gravatarUrl 65 | ); 66 | 67 | $response = Http::get($user->getAvatar()); 68 | 69 | $this->assertTrue($response->successful()); 70 | } 71 | 72 | /** @test */ 73 | public function user_can_generate_gravatar_default_image_when_no_email_found_first_character_9() 74 | { 75 | $user = User::factory()->create([ 76 | 'email' => '9fakeemail@fakeemail.com', 77 | ]); 78 | 79 | $gravatarUrl = $user->getAvatar(); 80 | 81 | $this->assertEquals( 82 | 'https://www.gravatar.com/avatar/'.md5($user->email).'?s=200&d=https://s3.amazonaws.com/laracasts/images/forum/avatars/default-avatar-36.png', 83 | $gravatarUrl 84 | ); 85 | 86 | $response = Http::get($user->getAvatar()); 87 | 88 | $this->assertTrue($response->successful()); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | create(); 23 | $userB = User::factory()->create(); 24 | 25 | $idea = Idea::factory()->create(); 26 | 27 | Vote::factory()->create([ 28 | 'idea_id' => $idea->id, 29 | 'user_id' => $user->id, 30 | ]); 31 | 32 | $this->assertTrue($idea->isVotedByUser($user)); 33 | $this->assertFalse($idea->isVotedByUser($userB)); 34 | $this->assertFalse($idea->isVotedByUser(null)); 35 | } 36 | 37 | /** @test */ 38 | public function user_can_vote_for_idea() 39 | { 40 | $user = User::factory()->create(); 41 | 42 | $idea = Idea::factory()->create(); 43 | 44 | $this->assertFalse($idea->isVotedByUser($user)); 45 | $idea->vote($user); 46 | $this->assertTrue($idea->isVotedByUser($user)); 47 | } 48 | 49 | /** @test */ 50 | public function voting_for_an_idea_thats_already_voted_for_throws_exception() 51 | { 52 | $user = User::factory()->create(); 53 | 54 | $idea = Idea::factory()->create(); 55 | 56 | Vote::factory()->create([ 57 | 'idea_id' => $idea->id, 58 | 'user_id' => $user->id, 59 | ]); 60 | 61 | $this->expectException(DuplicateVoteException::class); 62 | 63 | $idea->vote($user); 64 | } 65 | 66 | /** @test */ 67 | public function user_can_remove_vote_for_idea() 68 | { 69 | $user = User::factory()->create(); 70 | 71 | $idea = Idea::factory()->create(); 72 | 73 | Vote::factory()->create([ 74 | 'idea_id' => $idea->id, 75 | 'user_id' => $user->id, 76 | ]); 77 | 78 | $this->assertTrue($idea->isVotedByUser($user)); 79 | $idea->removeVote($user); 80 | $this->assertFalse($idea->isVotedByUser($user)); 81 | } 82 | 83 | /** @test */ 84 | public function removing_a_vote_that_doesnt_exist_throws_exception() 85 | { 86 | $user = User::factory()->create(); 87 | 88 | $idea = Idea::factory()->create(); 89 | 90 | $this->expectException(VoteNotFoundException::class); 91 | 92 | $idea->removeVote($user); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /tests/Unit/Jobs/NotifyAllVotersTest.php: -------------------------------------------------------------------------------- 1 | create([ 24 | 'email' => 'andre_madarang@hotmail.com', 25 | ]); 26 | 27 | $userB = User::factory()->create([ 28 | 'email' => 'user@user.com', 29 | ]); 30 | 31 | $idea = Idea::factory()->create(); 32 | 33 | Vote::create([ 34 | 'idea_id' => $idea->id, 35 | 'user_id' => $user->id, 36 | ]); 37 | 38 | Vote::create([ 39 | 'idea_id' => $idea->id, 40 | 'user_id' => $userB->id, 41 | ]); 42 | 43 | Mail::fake(); 44 | 45 | NotifyAllVoters::dispatch($idea); 46 | 47 | Mail::assertQueued(IdeaStatusUpdatedMailable::class, function ($mail) { 48 | return $mail->hasTo('andre_madarang@hotmail.com') 49 | && $mail->build()->subject === 'An idea you voted for has a new status'; 50 | }); 51 | 52 | Mail::assertQueued(IdeaStatusUpdatedMailable::class, function ($mail) { 53 | return $mail->hasTo('user@user.com') 54 | && $mail->build()->subject === 'An idea you voted for has a new status'; 55 | }); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tests/Unit/StatusTest.php: -------------------------------------------------------------------------------- 1 | create(['name' => 'Open']); 20 | $statusConsidering = Status::factory()->create(['name' => 'Considering']); 21 | $statusInProgress = Status::factory()->create(['name' => 'Considering']); 22 | $statusImplemented = Status::factory()->create(['name' => 'Implemented']); 23 | $statusClosed = Status::factory()->create(['name' => 'Closed']); 24 | 25 | Idea::factory()->create([ 26 | 'status_id' => $statusOpen->id, 27 | ]); 28 | 29 | Idea::factory(2)->create([ 30 | 'status_id' => $statusConsidering->id, 31 | ]); 32 | 33 | Idea::factory(3)->create([ 34 | 'status_id' => $statusInProgress->id, 35 | ]); 36 | 37 | Idea::factory(4)->create([ 38 | 'status_id' => $statusImplemented->id, 39 | ]); 40 | 41 | Idea::factory(5)->create([ 42 | 'status_id' => $statusClosed->id, 43 | ]); 44 | 45 | $this->assertEquals(15, Status::getCount()['all_statuses']); 46 | $this->assertEquals(1, Status::getCount()['open']); 47 | $this->assertEquals(2, Status::getCount()['considering']); 48 | $this->assertEquals(3, Status::getCount()['in_progress']); 49 | $this->assertEquals(4, Status::getCount()['implemented']); 50 | $this->assertEquals(5, Status::getCount()['closed']); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Unit/UserTest.php: -------------------------------------------------------------------------------- 1 | make([ 17 | 'email' => 'andre_madarang@hotmail.com', 18 | ]); 19 | 20 | $userB = User::factory()->make([ 21 | 'email' => 'user@user.com', 22 | ]); 23 | 24 | $this->assertTrue($user->isAdmin()); 25 | $this->assertFalse($userB->isAdmin()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /webpack.mix.js: -------------------------------------------------------------------------------- 1 | const mix = require('laravel-mix'); 2 | 3 | /* 4 | |-------------------------------------------------------------------------- 5 | | Mix Asset Management 6 | |-------------------------------------------------------------------------- 7 | | 8 | | Mix provides a clean, fluent API for defining some Webpack build steps 9 | | for your Laravel applications. By default, we are compiling the CSS 10 | | file for the application as well as bundling up all the JS files. 11 | | 12 | */ 13 | 14 | mix.js('resources/js/app.js', 'public/js').postCss('resources/css/app.css', 'public/css', [ 15 | require('postcss-import'), 16 | require('tailwindcss'), 17 | require('autoprefixer'), 18 | ]); 19 | --------------------------------------------------------------------------------