├── .env.example ├── .gitattributes ├── .gitignore ├── Procfile ├── README.md ├── app ├── Activity.php ├── Channel.php ├── Console │ └── Kernel.php ├── Exceptions │ └── Handler.php ├── Favoritable.php ├── Favorite.php ├── Filters │ ├── Filters.php │ └── ThreadFilters.php ├── Http │ ├── Controllers │ │ ├── Auth │ │ │ ├── ForgotPasswordController.php │ │ │ ├── LoginController.php │ │ │ ├── RegisterController.php │ │ │ └── ResetPasswordController.php │ │ ├── Controller.php │ │ ├── FavoritesController.php │ │ ├── HomeController.php │ │ ├── ProfilesController.php │ │ ├── RepliesController.php │ │ ├── ThreadController.php │ │ ├── ThreadSubscriptionsController.php │ │ └── UserNotificationsController.php │ ├── Kernel.php │ └── Middleware │ │ ├── EncryptCookies.php │ │ ├── RedirectIfAuthenticated.php │ │ ├── TrimStrings.php │ │ └── VerifyCsrfToken.php ├── Notifications │ └── ThreadWasUpdated.php ├── Policies │ ├── ReplyPolicy.php │ └── ThreadPolicy.php ├── Providers │ ├── AppServiceProvider.php │ ├── AuthServiceProvider.php │ ├── BroadcastServiceProvider.php │ ├── EventServiceProvider.php │ └── RouteServiceProvider.php ├── RecordsActivity.php ├── Reply.php ├── Thread.php ├── ThreadSubscription.php └── User.php ├── artisan ├── bootstrap ├── app.php ├── autoload.php └── cache │ └── .gitignore ├── composer.json ├── composer.lock ├── config ├── app.php ├── auth.php ├── broadcasting.php ├── cache.php ├── database.php ├── filesystems.php ├── mail.php ├── queue.php ├── services.php ├── session.php └── view.php ├── database ├── .gitignore ├── factories │ └── ModelFactory.php ├── migrations │ ├── 2014_10_12_000000_create_users_table.php │ ├── 2014_10_12_100000_create_password_resets_table.php │ ├── 2017_04_21_224745_create_threads_table.php │ ├── 2017_04_21_233654_create_replies_table.php │ ├── 2017_05_29_025659_create_channels_table.php │ ├── 2017_06_30_195457_create_favorites_table.php │ ├── 2017_07_05_151909_create_activities_table.php │ ├── 2017_10_24_160355_create_thread_subscriptions_table.php │ └── 2017_10_31_171936_create_notifications_table.php └── seeds │ └── DatabaseSeeder.php ├── package.json ├── phpunit.xml ├── public ├── .htaccess ├── css │ └── app.css ├── favicon.ico ├── fonts │ └── vendor │ │ └── bootstrap-sass │ │ └── bootstrap │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ └── glyphicons-halflings-regular.woff2 ├── index.php ├── js │ └── app.js ├── mix-manifest.json └── robots.txt ├── resources ├── assets │ ├── js │ │ ├── app.js │ │ ├── bootstrap.js │ │ ├── components │ │ │ ├── Favorite.vue │ │ │ ├── Flash.vue │ │ │ ├── NewReply.vue │ │ │ ├── Paginator.vue │ │ │ ├── Replies.vue │ │ │ ├── Reply.vue │ │ │ ├── SubscribeButton.vue │ │ │ └── UserNotifications.vue │ │ ├── mixins │ │ │ └── Collection.js │ │ └── pages │ │ │ └── Thread.vue │ └── sass │ │ ├── _variables.scss │ │ └── app.scss ├── lang │ └── en │ │ ├── auth.php │ │ ├── pagination.php │ │ ├── passwords.php │ │ └── validation.php └── views │ ├── auth │ ├── login.blade.php │ ├── passwords │ │ ├── email.blade.php │ │ └── reset.blade.php │ └── register.blade.php │ ├── home.blade.php │ ├── layouts │ ├── app.blade.php │ └── nav.blade.php │ ├── profiles │ ├── activities │ │ ├── activity.blade.php │ │ ├── created_reply.blade.php │ │ └── created_thread.blade.php │ └── show.blade.php │ ├── threads │ ├── create.blade.php │ ├── index.blade.php │ ├── reply.blade.php │ └── show.blade.php │ └── welcome.blade.php ├── routes ├── api.php ├── channels.php ├── console.php └── web.php ├── server.php ├── storage ├── app │ ├── .gitignore │ └── public │ │ └── .gitignore ├── debugbar │ └── .gitignore ├── framework │ ├── .gitignore │ ├── cache │ │ └── .gitignore │ ├── sessions │ │ └── .gitignore │ ├── testing │ │ └── .gitignore │ └── views │ │ └── .gitignore └── logs │ └── .gitignore ├── tests ├── CreatesApplication.php ├── Feature │ ├── CreateThreadsTest.php │ ├── FavoritesTest.php │ ├── NotificationsTest.php │ ├── ParticipateInForumTest.php │ ├── ProfilesTest.php │ ├── ReadThreadsTest.php │ └── SubscribeToThreadsTest.php ├── TestCase.php ├── Unit │ ├── ActivityTest.php │ ├── ChannelTest.php │ ├── ReplyTest.php │ └── ThreadTest.php └── utilities │ └── functions.php ├── webpack.mix.js └── yarn.lock /.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | APP_DEBUG=true 5 | APP_LOG_LEVEL=debug 6 | APP_URL=http://localhost 7 | 8 | DB_CONNECTION=mysql 9 | DB_HOST=127.0.0.1 10 | DB_PORT=3306 11 | DB_DATABASE=forum 12 | DB_USERNAME=root 13 | DB_PASSWORD= 14 | 15 | BROADCAST_DRIVER=log 16 | CACHE_DRIVER=file 17 | SESSION_DRIVER=file 18 | QUEUE_DRIVER=sync 19 | 20 | REDIS_HOST=127.0.0.1 21 | REDIS_PASSWORD=null 22 | REDIS_PORT=6379 23 | 24 | MAIL_DRIVER=smtp 25 | MAIL_HOST=smtp.mailtrap.io 26 | MAIL_PORT=2525 27 | MAIL_USERNAME=null 28 | MAIL_PASSWORD=null 29 | MAIL_ENCRYPTION=null 30 | 31 | PUSHER_APP_ID= 32 | PUSHER_APP_KEY= 33 | PUSHER_APP_SECRET= 34 | -------------------------------------------------------------------------------- /.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 | /.idea 7 | /.vagrant 8 | Homestead.json 9 | Homestead.yaml 10 | npm-debug.log 11 | .env 12 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: vendor/bin/heroku-php-apache2 public/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Laravel Forum 2 | === 3 | 4 | I'm blogging my way through the advanced Laracast course: [Let's Build A Forum with Laravel and TDD](https://laracasts.com/series/lets-build-a-forum-with-laravel/) 5 | 6 | ![](https://user-images.githubusercontent.com/3578908/26895669-24e15fb2-4b77-11e7-8b9f-5a3873f279d4.png) 7 | 8 | ## Build an online forum with Laravel 9 | 10 | ### [Part 1](https://medium.com/@connorleech/build-an-online-forum-with-laravel-initial-setup-and-seeding-part-1-a53138d1fffc): Initial Setup and Seeding 11 | 12 | ### [Part 2](https://medium.com/@connorleech/test-driven-development-tdd-in-laravel-b5a2bf9ab65b): Create routes, views, controllers. Generate auth. Write test 13 | 14 | ### [Part 3](https://medium.com/@connorleech/build-an-online-forum-with-laravel-analyzing-the-application-part-3-9317a0f893b4): Post and Show Replies to Threads 15 | 16 | ### [Part 4](https://medium.com/@connorleech/build-an-online-forum-with-laravel-give-the-user-the-ability-to-create-threads-part-4-ccdb6badc618): Give the User the ability to create Threads 17 | 18 | ### [Part 5](https://medium.com/@connorleech/testing-helpers-in-laravel-5-4-363ac47a8504): Testing Helpers in Laravel 5.4 19 | 20 | ### Helpful commands 21 | 22 | ``` 23 | # Clear cache 24 | $ php artisan cache:clear 25 | 26 | # Run tests 27 | $ phpunit 28 | // OR 29 | $ ./vendor/bin/phpunit 30 | 31 | # Clear config 32 | $ php artisan config:clear 33 | 34 | # Migrate or refresh database 35 | $ php artisan migrate:refresh 36 | $ php artisan migrate:rollback 37 | 38 | # Seed database with db seeders 39 | $ php artisan db:seed 40 | 41 | # Seed database with model factories 42 | $ php artisan tinker 43 | > factory('App\Thread', 50)->create(); 44 | 45 | ``` 46 | -------------------------------------------------------------------------------- /app/Activity.php: -------------------------------------------------------------------------------- 1 | morphTo(); 15 | } 16 | 17 | // Fetch activity feed for the given user 18 | public static function feed($user, $take = 50) 19 | { 20 | return static::where('user_id', $user->id) 21 | ->latest() 22 | ->with('subject') 23 | ->take($take) 24 | ->get() 25 | ->groupBy(function($activity){ 26 | // group by day 27 | return $activity->created_at->format('Y-m-d'); 28 | }); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Channel.php: -------------------------------------------------------------------------------- 1 | hasMany(Thread::class); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/Console/Kernel.php: -------------------------------------------------------------------------------- 1 | command('inspire') 28 | // ->hourly(); 29 | } 30 | 31 | /** 32 | * Register the Closure based commands for the application. 33 | * 34 | * @return void 35 | */ 36 | protected function commands() 37 | { 38 | require base_path('routes/console.php'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/Exceptions/Handler.php: -------------------------------------------------------------------------------- 1 | expectsJson()) { 60 | return response()->json(['error' => 'Unauthenticated.'], 401); 61 | } 62 | 63 | return redirect()->guest(route('login')); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /app/Favoritable.php: -------------------------------------------------------------------------------- 1 | favorites->each->delete(); 15 | }); 16 | } 17 | 18 | public function favorites() 19 | { 20 | // polymorphic relation 21 | return $this->morphMany(Favorite::class, 'favorited'); 22 | } 23 | 24 | public function favorite() 25 | { 26 | $attributes = ['user_id' => auth()->id()]; 27 | 28 | // check that user has not already favorited the reply 29 | if(! $this->favorites()->where($attributes)->exists()){ 30 | // add favorite 31 | $this->favorites()->create($attributes); 32 | } 33 | } 34 | 35 | public function unfavorite() 36 | { 37 | $attributes = ['user_id' => auth()->id()]; 38 | 39 | // get favorites of reply, find the logged in user's favorite, delete it 40 | // also deletes associated activity (have to call delete on favorites instance itself) 41 | $this->favorites()->where($attributes)->get()->each->delete(); 42 | } 43 | 44 | public function isFavorited() 45 | { 46 | return !! $this->favorites->where('user_id', auth()->id())->count(); 47 | } 48 | 49 | public function getIsFavoritedAttribute() 50 | { 51 | return $this->isFavorited(); 52 | } 53 | 54 | public function getFavoritesCountAttribute() 55 | { 56 | return $this->favorites->count(); 57 | } 58 | } -------------------------------------------------------------------------------- /app/Favorite.php: -------------------------------------------------------------------------------- 1 | request = $request; 22 | } 23 | 24 | // Apply the filters 25 | public function apply($builder) 26 | { 27 | $this->builder = $builder; 28 | 29 | foreach ($this->getFilters() as $filter => $value){ 30 | if(method_exists($this, $filter)){ 31 | $this->$filter($value); 32 | } 33 | } 34 | 35 | return $this->builder; 36 | } 37 | 38 | // Fetch all relevant filters from the request 39 | public function getFilters() 40 | { 41 | return $this->request->intersect($this->filters); 42 | } 43 | } -------------------------------------------------------------------------------- /app/Filters/ThreadFilters.php: -------------------------------------------------------------------------------- 1 | firstOrFail(); 16 | 17 | return $this->builder->where('user_id', $user->id); 18 | } 19 | 20 | // Filter query according to most popular threads 21 | protected function popular() 22 | { 23 | // remove orders 24 | $this->builder->getQuery()->orders = []; 25 | 26 | // order by popularity 27 | return $this->builder->orderBy('replies_count', 'desc'); 28 | } 29 | 30 | protected function unanswered() 31 | { 32 | return $this->builder->where('replies_count', 0); 33 | } 34 | } -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ForgotPasswordController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/LoginController.php: -------------------------------------------------------------------------------- 1 | middleware('guest')->except('logout'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/RegisterController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 40 | } 41 | 42 | /** 43 | * Get a validator for an incoming registration request. 44 | * 45 | * @param array $data 46 | * @return \Illuminate\Contracts\Validation\Validator 47 | */ 48 | protected function validator(array $data) 49 | { 50 | return Validator::make($data, [ 51 | 'name' => 'required|string|max:255', 52 | 'email' => 'required|string|email|max:255|unique:users', 53 | 'password' => 'required|string|min:6|confirmed', 54 | ]); 55 | } 56 | 57 | /** 58 | * Create a new user instance after a valid registration. 59 | * 60 | * @param array $data 61 | * @return User 62 | */ 63 | protected function create(array $data) 64 | { 65 | return User::create([ 66 | 'name' => $data['name'], 67 | 'email' => $data['email'], 68 | 'password' => bcrypt($data['password']), 69 | ]); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ResetPasswordController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 16 | } 17 | 18 | public function store(Reply $reply) 19 | { 20 | $reply->favorite(); 21 | 22 | return back(); 23 | } 24 | 25 | public function destroy(Reply $reply) 26 | { 27 | $reply->unfavorite(); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/Http/Controllers/HomeController.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 17 | } 18 | 19 | /** 20 | * Show the application dashboard. 21 | * 22 | * @return \Illuminate\Http\Response 23 | */ 24 | public function index() 25 | { 26 | return view('home'); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/Http/Controllers/ProfilesController.php: -------------------------------------------------------------------------------- 1 | $user, 16 | 'activities' => Activity::feed($user) 17 | ]); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/Http/Controllers/RepliesController.php: -------------------------------------------------------------------------------- 1 | middleware('auth', ['except' => 'index']); 13 | } 14 | 15 | public function index($channelId, Thread $thread) 16 | { 17 | return $thread->replies()->paginate(20); 18 | } 19 | 20 | public function store($channelId, Thread $thread) 21 | { 22 | $this->validate(request(), [ 23 | 'body' => 'required' 24 | ]); 25 | 26 | $reply = $thread->addReply([ 27 | 'body' => request('body'), 28 | 'user_id' => auth()->id() 29 | ]); 30 | 31 | if(request()->expectsJson()){ 32 | // send reply with owner data for ajax requests 33 | return $reply->load('owner'); 34 | } 35 | 36 | return back()->with('flash', 'Your reply has been left'); 37 | } 38 | 39 | public function update(Reply $reply) 40 | { 41 | $this->authorize('update', $reply); 42 | 43 | $this->validate(request(), ['body' => 'required']); 44 | 45 | $reply->update([ 46 | 'body' => request('body') 47 | ]); 48 | } 49 | 50 | public function destroy(Reply $reply){ 51 | 52 | $this->authorize('update', $reply); 53 | $reply->delete(); 54 | 55 | // for ajax delete 56 | if(request()->expectsJson()){ 57 | return response(['status' => 'Reply deleted']); 58 | } 59 | 60 | return back(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/Http/Controllers/ThreadController.php: -------------------------------------------------------------------------------- 1 | middleware('auth')->except(['index', 'show']); 19 | } 20 | 21 | /** 22 | * Display a listing of the resource. 23 | */ 24 | public function index(Channel $channel, ThreadFilters $filters) 25 | { 26 | 27 | $threads = $this->getThreads($channel, $filters); 28 | 29 | if(request()->wantsJson()){ 30 | return $threads; 31 | } 32 | 33 | return view('threads.index', compact('threads')); 34 | } 35 | 36 | /** 37 | * Show the form for creating a new resource. 38 | */ 39 | public function create() 40 | { 41 | return view('threads.create'); 42 | } 43 | 44 | /** 45 | * Store a newly created resource in storage. 46 | */ 47 | public function store(Request $request) 48 | { 49 | $this->validate($request, [ 50 | 'title' => 'required', 51 | 'body' => 'required', 52 | 'channel_id' => 'required|exists:channels,id' // laravel validation helpers 53 | ]); 54 | 55 | $thread = Thread::create([ 56 | 'user_id' => auth()->id(), 57 | 'channel_id' => request('channel_id'), 58 | 'title' => request('title'), 59 | 'body' => request('body') 60 | ]); 61 | 62 | return redirect($thread->path()) 63 | ->with('flash', 'Your thread has been published!'); 64 | } 65 | 66 | /** 67 | * Display the specified resource. 68 | */ 69 | public function show($channel, Thread $thread) 70 | { 71 | return view('threads.show', compact('thread')); 72 | } 73 | 74 | /** 75 | * Show the form for editing the specified resource. 76 | */ 77 | public function edit(Thread $thread) 78 | { 79 | // 80 | } 81 | 82 | /** 83 | * Update the specified resource in storage. 84 | */ 85 | public function update(Request $request, Thread $thread) 86 | { 87 | // 88 | } 89 | 90 | /** 91 | * Remove the specified resource from storage. 92 | */ 93 | public function destroy($channel, Thread $thread) 94 | { 95 | // check that it is signed in user's thread 96 | // https://laravel.com/docs/5.4/authorization#via-controller-helpers 97 | $this->authorize('update', $thread); 98 | 99 | $thread->delete(); 100 | 101 | if(request()->wantsJson()){ 102 | return response([], 204); 103 | } 104 | 105 | return redirect('/threads'); 106 | } 107 | 108 | // Fetch all relevant threads 109 | public function getThreads(Channel $channel, ThreadFilters $filters) 110 | { 111 | $threads = Thread::latest()->filter($filters); 112 | if($channel->exists){ 113 | $threads->where('channel_id', $channel->id); 114 | } 115 | 116 | return $threads->get(); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /app/Http/Controllers/ThreadSubscriptionsController.php: -------------------------------------------------------------------------------- 1 | subscribe(); 12 | } 13 | 14 | public function destroy($channelId, Thread $thread) 15 | { 16 | $thread->unsubscribe(); 17 | } 18 | } -------------------------------------------------------------------------------- /app/Http/Controllers/UserNotificationsController.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 13 | } 14 | 15 | public function index(User $user) 16 | { 17 | return auth()->user()->unreadNotifications; 18 | } 19 | 20 | public function destroy(User $user, $notificationId) 21 | { 22 | auth()->user()->notifications()->findOrFail($notificationId)->markAsRead(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/Http/Kernel.php: -------------------------------------------------------------------------------- 1 | [ 30 | \App\Http\Middleware\EncryptCookies::class, 31 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 32 | \Illuminate\Session\Middleware\StartSession::class, 33 | // \Illuminate\Session\Middleware\AuthenticateSession::class, 34 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, 35 | \App\Http\Middleware\VerifyCsrfToken::class, 36 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 37 | ], 38 | 39 | 'api' => [ 40 | 'throttle:60,1', 41 | 'bindings', 42 | ], 43 | ]; 44 | 45 | /** 46 | * The application's route middleware. 47 | * 48 | * These middleware may be assigned to groups or used individually. 49 | * 50 | * @var array 51 | */ 52 | protected $routeMiddleware = [ 53 | 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 54 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 55 | 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 56 | 'can' => \Illuminate\Auth\Middleware\Authorize::class, 57 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 58 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 59 | ]; 60 | } 61 | -------------------------------------------------------------------------------- /app/Http/Middleware/EncryptCookies.php: -------------------------------------------------------------------------------- 1 | check()) { 21 | return redirect('/home'); 22 | } 23 | 24 | return $next($request); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrimStrings.php: -------------------------------------------------------------------------------- 1 | thread = $thread; 25 | $this->reply = $reply; 26 | } 27 | 28 | /** 29 | * Get the notification's delivery channels. 30 | * 31 | * @param mixed $notifiable 32 | * @return array 33 | */ 34 | public function via($notifiable) 35 | { 36 | return ['database']; 37 | } 38 | 39 | /** 40 | * Get the array representation of the notification. 41 | * 42 | * @param mixed $notifiable 43 | * @return array 44 | */ 45 | public function toArray() 46 | { 47 | return [ 48 | 'message' => $this->reply->owner->name . " replied to " . $this->thread->title, 49 | 'link' => $this->reply->path() 50 | ]; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/Policies/ReplyPolicy.php: -------------------------------------------------------------------------------- 1 | user_id == $user->id; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/Policies/ThreadPolicy.php: -------------------------------------------------------------------------------- 1 | user_id == $user->id; 46 | } 47 | 48 | /** 49 | * Determine whether the user can delete the thread. 50 | * 51 | * @param \App\User $user 52 | * @param \App\Thread $thread 53 | * @return mixed 54 | */ 55 | public function delete(User $user, Thread $thread) 56 | { 57 | // 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | with('channels', $channels); 23 | }); 24 | 25 | // For Heroku 26 | // https://laravel-news.com/laravel-5-4-key-too-long-error 27 | \Schema::defaultStringLength(191); 28 | } 29 | 30 | /** 31 | * Register any application services. 32 | * 33 | * @return void 34 | */ 35 | public function register() 36 | { 37 | if($this->app->isLocal()){ 38 | $this->app->register(\Barryvdh\Debugbar\ServiceProvider::class); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/Providers/AuthServiceProvider.php: -------------------------------------------------------------------------------- 1 | 'App\Policies\ThreadPolicy', 17 | 'App\Reply' => 'App\Policies\ReplyPolicy', 18 | 19 | ]; 20 | 21 | /** 22 | * Register any authentication / authorization services. 23 | * 24 | * @return void 25 | */ 26 | public function boot() 27 | { 28 | $this->registerPolicies(); 29 | 30 | // if return true in before method, instantly authorized 31 | // Gate::before(function($user){ 32 | // if($user->name == 'Connor Leech') return true; 33 | // }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/Providers/BroadcastServiceProvider.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'App\Listeners\EventListener', 18 | ], 19 | ]; 20 | 21 | /** 22 | * Register any events for your application. 23 | * 24 | * @return void 25 | */ 26 | public function boot() 27 | { 28 | parent::boot(); 29 | 30 | // 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Providers/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | mapApiRoutes(); 39 | 40 | $this->mapWebRoutes(); 41 | 42 | // 43 | } 44 | 45 | /** 46 | * Define the "web" routes for the application. 47 | * 48 | * These routes all receive session state, CSRF protection, etc. 49 | * 50 | * @return void 51 | */ 52 | protected function mapWebRoutes() 53 | { 54 | Route::middleware('web') 55 | ->namespace($this->namespace) 56 | ->group(base_path('routes/web.php')); 57 | } 58 | 59 | /** 60 | * Define the "api" routes for the application. 61 | * 62 | * These routes are typically stateless. 63 | * 64 | * @return void 65 | */ 66 | protected function mapApiRoutes() 67 | { 68 | Route::prefix('api') 69 | ->middleware('api') 70 | ->namespace($this->namespace) 71 | ->group(base_path('routes/api.php')); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /app/RecordsActivity.php: -------------------------------------------------------------------------------- 1 | guest()) return; 12 | 13 | foreach (static::getActivitiesToRecord() as $event) { 14 | static::$event(function($model) use ($event){ 15 | $model->recordActivity($event); 16 | }); 17 | } 18 | 19 | static::deleting(function($model){ 20 | $model->activity()->delete(); 21 | }); 22 | } 23 | 24 | // Fetch all model events that require activity recording 25 | protected static function getActivitiesToRecord() 26 | { 27 | return ['created']; 28 | } 29 | 30 | // Record new activity for the model 31 | protected function recordActivity($event) 32 | { 33 | $this->activity()->create([ 34 | 'user_id' => auth()->id(), 35 | 'type' => $this->getActivityType($event) 36 | ]); 37 | } 38 | 39 | // Fetch the activity relationship 40 | protected function activity() 41 | { 42 | // https://laravel.com/docs/5.4/eloquent-relationships#polymorphic-relations 43 | return $this->morphMany('App\Activity', 'subject'); 44 | } 45 | 46 | // Determine the activity type 47 | protected function getActivityType($event) 48 | { 49 | $type = strtolower((new \ReflectionClass($this))->getShortName()); 50 | return "{$event}_{$type}"; 51 | } 52 | } -------------------------------------------------------------------------------- /app/Reply.php: -------------------------------------------------------------------------------- 1 | thread->increment('replies_count'); 27 | }); 28 | 29 | static::deleted(function($reply){ 30 | $reply->thread->decrement('replies_count'); 31 | }); 32 | } 33 | 34 | // A Reply has an owner 35 | public function owner() 36 | { 37 | return $this->belongsTo(User::class, 'user_id'); 38 | } 39 | 40 | public function thread() 41 | { 42 | return $this->belongsTo(Thread::class); 43 | } 44 | 45 | public function path() 46 | { 47 | return $this->thread->path() . "#reply-{$this->id}"; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/Thread.php: -------------------------------------------------------------------------------- 1 | replies->each->delete(); 30 | }); 31 | } 32 | 33 | public function path() 34 | { 35 | return "/threads/{$this->channel->slug}/{$this->id}"; 36 | } 37 | 38 | public function replies() 39 | { 40 | return $this->hasMany(Reply::class); 41 | } 42 | 43 | public function creator() 44 | { 45 | return $this->belongsTo(User::class, 'user_id'); 46 | } 47 | 48 | public function channel() 49 | { 50 | return $this->belongsTo(Channel::class); 51 | } 52 | 53 | public function addReply($reply) 54 | { 55 | // create and save the reply 56 | $reply = $this->replies()->create($reply); 57 | 58 | $this->subscriptions 59 | // get subscribers that did not leave the reply 60 | ->where('user_id', '!=', $reply->user_id) 61 | // send each of them a notification 62 | ->each->notify($reply); 63 | 64 | return $reply; 65 | } 66 | 67 | // Apply all the relevant thread filters 68 | public function scopeFilter($query, ThreadFilters $filters) 69 | { 70 | return $filters->apply($query); 71 | } 72 | 73 | // a thread can have many subscriptions 74 | public function subscriptions() 75 | { 76 | return $this->hasMany(ThreadSubscription::class); 77 | } 78 | 79 | // Determine if current user is subscribed to a thread 80 | // 'custom eloquent accessor' 81 | public function getIsSubscribedToAttribute() 82 | { 83 | return $this->subscriptions() 84 | ->where('user_id', auth()->id()) 85 | ->exists(); 86 | } 87 | 88 | public function subscribe($userId = null) 89 | { 90 | $this->subscriptions()->create([ 91 | 'user_id' => $userId ?: auth()->id() 92 | ]); 93 | 94 | return $this; 95 | } 96 | 97 | public function unsubscribe($userId = null) 98 | { 99 | $this->subscriptions() 100 | ->where('user_id', $userId ?: auth()->id()) 101 | ->delete(); 102 | 103 | return $this; 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /app/ThreadSubscription.php: -------------------------------------------------------------------------------- 1 | belongsTo(User::class); 16 | } 17 | 18 | public function thread() 19 | { 20 | return $this->belongsTo(Thread::class); 21 | } 22 | 23 | // send notification to user 24 | public function notify($reply) 25 | { 26 | $this->user->notify(new ThreadWasUpdated($this->thread, $reply)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/User.php: -------------------------------------------------------------------------------- 1 | hasMany(Thread::class)->latest(); 37 | } 38 | 39 | // Get route key name for Laravel 40 | public function getRouteKeyName() 41 | { 42 | return 'name'; 43 | } 44 | 45 | // Get all activity for the user 46 | public function activity() 47 | { 48 | return $this->hasMany(Activity::class); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /artisan: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | make(Illuminate\Contracts\Console\Kernel::class); 32 | 33 | $status = $kernel->handle( 34 | $input = new Symfony\Component\Console\Input\ArgvInput, 35 | new Symfony\Component\Console\Output\ConsoleOutput 36 | ); 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Shutdown The Application 41 | |-------------------------------------------------------------------------- 42 | | 43 | | Once Artisan has finished running. We will fire off the shutdown events 44 | | so that any final work may be done by the application before we shut 45 | | down the process. This is the last thing to happen to the request. 46 | | 47 | */ 48 | 49 | $kernel->terminate($input, $status); 50 | 51 | exit($status); 52 | -------------------------------------------------------------------------------- /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/autoload.php: -------------------------------------------------------------------------------- 1 | =5.6.4", 9 | "laravel/framework": "5.4.*", 10 | "laravel/tinker": "~1.0", 11 | "rap2hpoutre/laravel-log-viewer": "^0.10.4" 12 | }, 13 | "require-dev": { 14 | "fzaninotto/faker": "~1.4", 15 | "mockery/mockery": "0.9.*", 16 | "phpunit/phpunit": "~5.7" 17 | }, 18 | "autoload": { 19 | "classmap": [ 20 | "database" 21 | ], 22 | "psr-4": { 23 | "App\\": "app/" 24 | } 25 | }, 26 | "autoload-dev": { 27 | "psr-4": { 28 | "Tests\\": "tests/" 29 | }, 30 | "files": ["tests/utilities/functions.php"] 31 | }, 32 | "scripts": { 33 | "post-root-package-install": [ 34 | "php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 35 | ], 36 | "post-create-project-cmd": [ 37 | "php artisan key:generate" 38 | ], 39 | "post-install-cmd": [ 40 | "Illuminate\\Foundation\\ComposerScripts::postInstall", 41 | "php artisan optimize" 42 | ], 43 | "post-update-cmd": [ 44 | "Illuminate\\Foundation\\ComposerScripts::postUpdate", 45 | "php artisan optimize" 46 | ] 47 | }, 48 | "config": { 49 | "preferred-install": "dist", 50 | "sort-packages": true, 51 | "optimize-autoloader": true 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /config/app.php: -------------------------------------------------------------------------------- 1 | env('APP_NAME', 'Laravel Forum'), 16 | 17 | /* 18 | |-------------------------------------------------------------------------- 19 | | Application Environment 20 | |-------------------------------------------------------------------------- 21 | | 22 | | This value determines the "environment" your application is currently 23 | | running in. This may determine how you prefer to configure various 24 | | services your application utilizes. Set this in your ".env" file. 25 | | 26 | */ 27 | 28 | 'env' => env('APP_ENV', 'production'), 29 | 30 | /* 31 | |-------------------------------------------------------------------------- 32 | | Application Debug Mode 33 | |-------------------------------------------------------------------------- 34 | | 35 | | When your application is in debug mode, detailed error messages with 36 | | stack traces will be shown on every error that occurs within your 37 | | application. If disabled, a simple generic error page is shown. 38 | | 39 | */ 40 | 41 | 'debug' => env('APP_DEBUG', true), 42 | 43 | /* 44 | |-------------------------------------------------------------------------- 45 | | Application URL 46 | |-------------------------------------------------------------------------- 47 | | 48 | | This URL is used by the console to properly generate URLs when using 49 | | the Artisan command line tool. You should set this to the root of 50 | | your application so that it is used when running Artisan tasks. 51 | | 52 | */ 53 | 54 | 'url' => env('APP_URL', 'http://localhost'), 55 | 56 | /* 57 | |-------------------------------------------------------------------------- 58 | | Application Timezone 59 | |-------------------------------------------------------------------------- 60 | | 61 | | Here you may specify the default timezone for your application, which 62 | | will be used by the PHP date and date-time functions. We have gone 63 | | ahead and set this to a sensible default for you out of the box. 64 | | 65 | */ 66 | 67 | 'timezone' => 'UTC', 68 | 69 | /* 70 | |-------------------------------------------------------------------------- 71 | | Application Locale Configuration 72 | |-------------------------------------------------------------------------- 73 | | 74 | | The application locale determines the default locale that will be used 75 | | by the translation service provider. You are free to set this value 76 | | to any of the locales which will be supported by the application. 77 | | 78 | */ 79 | 80 | 'locale' => 'en', 81 | 82 | /* 83 | |-------------------------------------------------------------------------- 84 | | Application Fallback Locale 85 | |-------------------------------------------------------------------------- 86 | | 87 | | The fallback locale determines the locale to use when the current one 88 | | is not available. You may change the value to correspond to any of 89 | | the language folders that are provided through your application. 90 | | 91 | */ 92 | 93 | 'fallback_locale' => 'en', 94 | 95 | /* 96 | |-------------------------------------------------------------------------- 97 | | Encryption Key 98 | |-------------------------------------------------------------------------- 99 | | 100 | | This key is used by the Illuminate encrypter service and should be set 101 | | to a random, 32 character string, otherwise these encrypted strings 102 | | will not be safe. Please do this before deploying an application! 103 | | 104 | */ 105 | 106 | 'key' => env('APP_KEY'), 107 | 108 | 'cipher' => 'AES-256-CBC', 109 | 110 | /* 111 | |-------------------------------------------------------------------------- 112 | | Logging Configuration 113 | |-------------------------------------------------------------------------- 114 | | 115 | | Here you may configure the log settings for your application. Out of 116 | | the box, Laravel uses the Monolog PHP logging library. This gives 117 | | you a variety of powerful log handlers / formatters to utilize. 118 | | 119 | | Available Settings: "single", "daily", "syslog", "errorlog" 120 | | 121 | */ 122 | 123 | 'log' => env('APP_LOG', 'single'), 124 | 125 | 'log_level' => env('APP_LOG_LEVEL', 'debug'), 126 | 127 | /* 128 | |-------------------------------------------------------------------------- 129 | | Autoloaded Service Providers 130 | |-------------------------------------------------------------------------- 131 | | 132 | | The service providers listed here will be automatically loaded on the 133 | | request to your application. Feel free to add your own services to 134 | | this array to grant expanded functionality to your applications. 135 | | 136 | */ 137 | 138 | 'providers' => [ 139 | 140 | /* 141 | * Laravel Framework Service Providers... 142 | */ 143 | Illuminate\Auth\AuthServiceProvider::class, 144 | Illuminate\Broadcasting\BroadcastServiceProvider::class, 145 | Illuminate\Bus\BusServiceProvider::class, 146 | Illuminate\Cache\CacheServiceProvider::class, 147 | Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, 148 | Illuminate\Cookie\CookieServiceProvider::class, 149 | Illuminate\Database\DatabaseServiceProvider::class, 150 | Illuminate\Encryption\EncryptionServiceProvider::class, 151 | Illuminate\Filesystem\FilesystemServiceProvider::class, 152 | Illuminate\Foundation\Providers\FoundationServiceProvider::class, 153 | Illuminate\Hashing\HashServiceProvider::class, 154 | Illuminate\Mail\MailServiceProvider::class, 155 | Illuminate\Notifications\NotificationServiceProvider::class, 156 | Illuminate\Pagination\PaginationServiceProvider::class, 157 | Illuminate\Pipeline\PipelineServiceProvider::class, 158 | Illuminate\Queue\QueueServiceProvider::class, 159 | Illuminate\Redis\RedisServiceProvider::class, 160 | Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, 161 | Illuminate\Session\SessionServiceProvider::class, 162 | Illuminate\Translation\TranslationServiceProvider::class, 163 | Illuminate\Validation\ValidationServiceProvider::class, 164 | Illuminate\View\ViewServiceProvider::class, 165 | 166 | /* 167 | * Package Service Providers... 168 | */ 169 | Laravel\Tinker\TinkerServiceProvider::class, 170 | Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider::class, 171 | 172 | /* 173 | * Application Service Providers... 174 | */ 175 | App\Providers\AppServiceProvider::class, 176 | App\Providers\AuthServiceProvider::class, 177 | // App\Providers\BroadcastServiceProvider::class, 178 | App\Providers\EventServiceProvider::class, 179 | App\Providers\RouteServiceProvider::class, 180 | 181 | ], 182 | 183 | /* 184 | |-------------------------------------------------------------------------- 185 | | Class Aliases 186 | |-------------------------------------------------------------------------- 187 | | 188 | | This array of class aliases will be registered when this application 189 | | is started. However, feel free to register as many as you wish as 190 | | the aliases are "lazy" loaded so they don't hinder performance. 191 | | 192 | */ 193 | 194 | 'aliases' => [ 195 | 196 | 'App' => Illuminate\Support\Facades\App::class, 197 | 'Artisan' => Illuminate\Support\Facades\Artisan::class, 198 | 'Auth' => Illuminate\Support\Facades\Auth::class, 199 | 'Blade' => Illuminate\Support\Facades\Blade::class, 200 | 'Broadcast' => Illuminate\Support\Facades\Broadcast::class, 201 | 'Bus' => Illuminate\Support\Facades\Bus::class, 202 | 'Cache' => Illuminate\Support\Facades\Cache::class, 203 | 'Config' => Illuminate\Support\Facades\Config::class, 204 | 'Cookie' => Illuminate\Support\Facades\Cookie::class, 205 | 'Crypt' => Illuminate\Support\Facades\Crypt::class, 206 | 'DB' => Illuminate\Support\Facades\DB::class, 207 | 'Eloquent' => Illuminate\Database\Eloquent\Model::class, 208 | 'Event' => Illuminate\Support\Facades\Event::class, 209 | 'File' => Illuminate\Support\Facades\File::class, 210 | 'Gate' => Illuminate\Support\Facades\Gate::class, 211 | 'Hash' => Illuminate\Support\Facades\Hash::class, 212 | 'Lang' => Illuminate\Support\Facades\Lang::class, 213 | 'Log' => Illuminate\Support\Facades\Log::class, 214 | 'Mail' => Illuminate\Support\Facades\Mail::class, 215 | 'Notification' => Illuminate\Support\Facades\Notification::class, 216 | 'Password' => Illuminate\Support\Facades\Password::class, 217 | 'Queue' => Illuminate\Support\Facades\Queue::class, 218 | 'Redirect' => Illuminate\Support\Facades\Redirect::class, 219 | 'Redis' => Illuminate\Support\Facades\Redis::class, 220 | 'Request' => Illuminate\Support\Facades\Request::class, 221 | 'Response' => Illuminate\Support\Facades\Response::class, 222 | 'Route' => Illuminate\Support\Facades\Route::class, 223 | 'Schema' => Illuminate\Support\Facades\Schema::class, 224 | 'Session' => Illuminate\Support\Facades\Session::class, 225 | 'Storage' => Illuminate\Support\Facades\Storage::class, 226 | 'URL' => Illuminate\Support\Facades\URL::class, 227 | 'Validator' => Illuminate\Support\Facades\Validator::class, 228 | 'View' => Illuminate\Support\Facades\View::class, 229 | 230 | ], 231 | 232 | ]; 233 | -------------------------------------------------------------------------------- /config/auth.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'guard' => 'web', 18 | 'passwords' => 'users', 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Authentication Guards 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Next, you may define every authentication guard for your application. 27 | | Of course, a great default configuration has been defined for you 28 | | here which uses session storage and the Eloquent user provider. 29 | | 30 | | All authentication drivers have a user provider. This defines how the 31 | | users are actually retrieved out of your database or other storage 32 | | mechanisms used by this application to persist your user's data. 33 | | 34 | | Supported: "session", "token" 35 | | 36 | */ 37 | 38 | 'guards' => [ 39 | 'web' => [ 40 | 'driver' => 'session', 41 | 'provider' => 'users', 42 | ], 43 | 44 | 'api' => [ 45 | 'driver' => 'token', 46 | 'provider' => 'users', 47 | ], 48 | ], 49 | 50 | /* 51 | |-------------------------------------------------------------------------- 52 | | User Providers 53 | |-------------------------------------------------------------------------- 54 | | 55 | | All authentication drivers have a user provider. This defines how the 56 | | users are actually retrieved out of your database or other storage 57 | | mechanisms used by this application to persist your user's data. 58 | | 59 | | If you have multiple user tables or models you may configure multiple 60 | | sources which represent each model / table. These sources may then 61 | | be assigned to any extra authentication guards you have defined. 62 | | 63 | | Supported: "database", "eloquent" 64 | | 65 | */ 66 | 67 | 'providers' => [ 68 | 'users' => [ 69 | 'driver' => 'eloquent', 70 | 'model' => App\User::class, 71 | ], 72 | 73 | // 'users' => [ 74 | // 'driver' => 'database', 75 | // 'table' => 'users', 76 | // ], 77 | ], 78 | 79 | /* 80 | |-------------------------------------------------------------------------- 81 | | Resetting Passwords 82 | |-------------------------------------------------------------------------- 83 | | 84 | | You may specify multiple password reset configurations if you have more 85 | | than one user table or model in the application and you want to have 86 | | separate password reset settings based on the specific user types. 87 | | 88 | | The expire time is the number of minutes that the reset token should be 89 | | considered valid. This security feature keeps tokens short-lived so 90 | | they have less time to be guessed. You may change this as needed. 91 | | 92 | */ 93 | 94 | 'passwords' => [ 95 | 'users' => [ 96 | 'provider' => 'users', 97 | 'table' => 'password_resets', 98 | 'expire' => 60, 99 | ], 100 | ], 101 | 102 | ]; 103 | -------------------------------------------------------------------------------- /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 | // 40 | ], 41 | ], 42 | 43 | 'redis' => [ 44 | 'driver' => 'redis', 45 | 'connection' => 'default', 46 | ], 47 | 48 | 'log' => [ 49 | 'driver' => 'log', 50 | ], 51 | 52 | 'null' => [ 53 | 'driver' => 'null', 54 | ], 55 | 56 | ], 57 | 58 | ]; 59 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_DRIVER', 'file'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Cache Stores 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the cache "stores" for your application as 26 | | well as their drivers. You may even define multiple stores for the 27 | | same cache driver to group types of items stored in your caches. 28 | | 29 | */ 30 | 31 | 'stores' => [ 32 | 33 | 'apc' => [ 34 | 'driver' => 'apc', 35 | ], 36 | 37 | 'array' => [ 38 | 'driver' => 'array', 39 | ], 40 | 41 | 'database' => [ 42 | 'driver' => 'database', 43 | 'table' => 'cache', 44 | 'connection' => null, 45 | ], 46 | 47 | 'file' => [ 48 | 'driver' => 'file', 49 | 'path' => storage_path('framework/cache/data'), 50 | ], 51 | 52 | 'memcached' => [ 53 | 'driver' => 'memcached', 54 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 55 | 'sasl' => [ 56 | env('MEMCACHED_USERNAME'), 57 | env('MEMCACHED_PASSWORD'), 58 | ], 59 | 'options' => [ 60 | // Memcached::OPT_CONNECT_TIMEOUT => 2000, 61 | ], 62 | 'servers' => [ 63 | [ 64 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 65 | 'port' => env('MEMCACHED_PORT', 11211), 66 | 'weight' => 100, 67 | ], 68 | ], 69 | ], 70 | 71 | 'redis' => [ 72 | 'driver' => 'redis', 73 | 'connection' => 'default', 74 | ], 75 | 76 | ], 77 | 78 | /* 79 | |-------------------------------------------------------------------------- 80 | | Cache Key Prefix 81 | |-------------------------------------------------------------------------- 82 | | 83 | | When utilizing a RAM based store such as APC or Memcached, there might 84 | | be other applications utilizing the same cache. So, we'll specify a 85 | | value to get prefixed to all our keys so we can avoid collisions. 86 | | 87 | */ 88 | 89 | 'prefix' => 'laravel', 90 | 91 | ]; 92 | -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | 'mysql', 13 | 'host' => $host, 14 | 'database' => $database, 15 | 'username' => $username, 16 | 'password' => $password, 17 | 'port' => env('DB_PORT', 3306), 18 | 'charset' => 'utf8mb4', 19 | 'collation' => 'utf8mb4_unicode_ci', 20 | 'prefix' => '' 21 | ]; 22 | 23 | } else { 24 | 25 | $mySqlConfig = [ 26 | 'driver' => 'mysql', 27 | 'host' => env('DB_HOST', '127.0.0.1'), 28 | 'port' => env('DB_PORT', '3306'), 29 | 'database' => env('DB_DATABASE', 'forge'), 30 | 'username' => env('DB_USERNAME', 'forge'), 31 | 'password' => env('DB_PASSWORD', ''), 32 | 'unix_socket' => env('DB_SOCKET', ''), 33 | 'charset' => 'utf8mb4', 34 | 'collation' => 'utf8mb4_unicode_ci', 35 | 'prefix' => '', 36 | 'strict' => true, 37 | 'engine' => null, 38 | ]; 39 | } 40 | 41 | return [ 42 | 43 | /* 44 | |-------------------------------------------------------------------------- 45 | | Default Database Connection Name 46 | |-------------------------------------------------------------------------- 47 | | 48 | | Here you may specify which of the database connections below you wish 49 | | to use as your default connection for all database work. Of course 50 | | you may use many connections at once using the Database library. 51 | | 52 | */ 53 | 54 | 'default' => env('DB_CONNECTION', 'mysql'), 55 | 56 | /* 57 | |-------------------------------------------------------------------------- 58 | | Database Connections 59 | |-------------------------------------------------------------------------- 60 | | 61 | | Here are each of the database connections setup for your application. 62 | | Of course, examples of configuring each database platform that is 63 | | supported by Laravel is shown below to make development simple. 64 | | 65 | | 66 | | All database work in Laravel is done through the PHP PDO facilities 67 | | so make sure you have the driver for your particular database of 68 | | choice installed on your machine before you begin development. 69 | | 70 | */ 71 | 72 | 'connections' => [ 73 | 74 | 'sqlite' => [ 75 | 'driver' => 'sqlite', 76 | 'database' => env('DB_DATABASE', database_path('database.sqlite')), 77 | 'prefix' => '', 78 | ], 79 | 80 | 'mysql' => $mySqlConfig, 81 | 82 | 'pgsql' => [ 83 | 'driver' => 'pgsql', 84 | 'host' => env('DB_HOST', '127.0.0.1'), 85 | 'port' => env('DB_PORT', '5432'), 86 | 'database' => env('DB_DATABASE', 'forge'), 87 | 'username' => env('DB_USERNAME', 'forge'), 88 | 'password' => env('DB_PASSWORD', ''), 89 | 'charset' => 'utf8', 90 | 'prefix' => '', 91 | 'schema' => 'public', 92 | 'sslmode' => 'prefer', 93 | ], 94 | 95 | ], 96 | 97 | /* 98 | |-------------------------------------------------------------------------- 99 | | Migration Repository Table 100 | |-------------------------------------------------------------------------- 101 | | 102 | | This table keeps track of all the migrations that have already run for 103 | | your application. Using this information, we can determine which of 104 | | the migrations on disk haven't actually been run in the database. 105 | | 106 | */ 107 | 108 | 'migrations' => 'migrations', 109 | 110 | /* 111 | |-------------------------------------------------------------------------- 112 | | Redis Databases 113 | |-------------------------------------------------------------------------- 114 | | 115 | | Redis is an open source, fast, and advanced key-value store that also 116 | | provides a richer set of commands than a typical key-value systems 117 | | such as APC or Memcached. Laravel makes it easy to dig right in. 118 | | 119 | */ 120 | 121 | 'redis' => [ 122 | 123 | 'client' => 'predis', 124 | 125 | 'default' => [ 126 | 'host' => env('REDIS_HOST', '127.0.0.1'), 127 | 'password' => env('REDIS_PASSWORD', null), 128 | 'port' => env('REDIS_PORT', 6379), 129 | 'database' => 0, 130 | ], 131 | 132 | ], 133 | 134 | ]; 135 | -------------------------------------------------------------------------------- /config/filesystems.php: -------------------------------------------------------------------------------- 1 | 'local', 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Default Cloud Filesystem Disk 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Many applications store files both locally and in the cloud. For this 24 | | reason, you may specify a default "cloud" driver here. This driver 25 | | will be bound as the Cloud disk implementation in the container. 26 | | 27 | */ 28 | 29 | 'cloud' => 's3', 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Filesystem Disks 34 | |-------------------------------------------------------------------------- 35 | | 36 | | Here you may configure as many filesystem "disks" as you wish, and you 37 | | may even configure multiple disks of the same driver. Defaults have 38 | | been setup for each driver as an example of the required options. 39 | | 40 | | Supported Drivers: "local", "ftp", "s3", "rackspace" 41 | | 42 | */ 43 | 44 | 'disks' => [ 45 | 46 | 'local' => [ 47 | 'driver' => 'local', 48 | 'root' => storage_path('app'), 49 | ], 50 | 51 | 'public' => [ 52 | 'driver' => 'local', 53 | 'root' => storage_path('app/public'), 54 | 'url' => env('APP_URL').'/storage', 55 | 'visibility' => 'public', 56 | ], 57 | 58 | 's3' => [ 59 | 'driver' => 's3', 60 | 'key' => env('AWS_KEY'), 61 | 'secret' => env('AWS_SECRET'), 62 | 'region' => env('AWS_REGION'), 63 | 'bucket' => env('AWS_BUCKET'), 64 | ], 65 | 66 | ], 67 | 68 | ]; 69 | -------------------------------------------------------------------------------- /config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_DRIVER', 'smtp'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | SMTP Host Address 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may provide the host address of the SMTP server used by your 27 | | applications. A default option is provided that is compatible with 28 | | the Mailgun mail service which will provide reliable deliveries. 29 | | 30 | */ 31 | 32 | 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 33 | 34 | /* 35 | |-------------------------------------------------------------------------- 36 | | SMTP Host Port 37 | |-------------------------------------------------------------------------- 38 | | 39 | | This is the SMTP port used by your application to deliver e-mails to 40 | | users of the application. Like the host we have set this value to 41 | | stay compatible with the Mailgun e-mail application by default. 42 | | 43 | */ 44 | 45 | 'port' => env('MAIL_PORT', 587), 46 | 47 | /* 48 | |-------------------------------------------------------------------------- 49 | | Global "From" Address 50 | |-------------------------------------------------------------------------- 51 | | 52 | | You may wish for all e-mails sent by your application to be sent from 53 | | the same address. Here, you may specify a name and address that is 54 | | used globally for all e-mails that are sent by your application. 55 | | 56 | */ 57 | 58 | 'from' => [ 59 | 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), 60 | 'name' => env('MAIL_FROM_NAME', 'Example'), 61 | ], 62 | 63 | /* 64 | |-------------------------------------------------------------------------- 65 | | E-Mail Encryption Protocol 66 | |-------------------------------------------------------------------------- 67 | | 68 | | Here you may specify the encryption protocol that should be used when 69 | | the application send e-mail messages. A sensible default using the 70 | | transport layer security protocol should provide great security. 71 | | 72 | */ 73 | 74 | 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 75 | 76 | /* 77 | |-------------------------------------------------------------------------- 78 | | SMTP Server Username 79 | |-------------------------------------------------------------------------- 80 | | 81 | | If your SMTP server requires a username for authentication, you should 82 | | set it here. This will get used to authenticate with your server on 83 | | connection. You may also set the "password" value below this one. 84 | | 85 | */ 86 | 87 | 'username' => env('MAIL_USERNAME'), 88 | 89 | 'password' => env('MAIL_PASSWORD'), 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | Sendmail System Path 94 | |-------------------------------------------------------------------------- 95 | | 96 | | When using the "sendmail" driver to send e-mails, we will need to know 97 | | the path to where Sendmail lives on this server. A default path has 98 | | been provided here, which will work well on most of your systems. 99 | | 100 | */ 101 | 102 | 'sendmail' => '/usr/sbin/sendmail -bs', 103 | 104 | /* 105 | |-------------------------------------------------------------------------- 106 | | Markdown Mail Settings 107 | |-------------------------------------------------------------------------- 108 | | 109 | | If you are using Markdown based email rendering, you may configure your 110 | | theme and component paths here, allowing you to customize the design 111 | | of the emails. Or, you may simply stick with the Laravel defaults! 112 | | 113 | */ 114 | 115 | 'markdown' => [ 116 | 'theme' => 'default', 117 | 118 | 'paths' => [ 119 | resource_path('views/vendor/mail'), 120 | ], 121 | ], 122 | 123 | ]; 124 | -------------------------------------------------------------------------------- /config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_DRIVER', 'sync'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Queue Prefix 23 | |-------------------------------------------------------------------------- 24 | | 25 | | If you are running multiple sites on a single server you should consider 26 | | specifying a queue prefix. This string will be prepended to the queue 27 | | names to prevent cross-talk when using certain local queue drivers. 28 | | 29 | */ 30 | 31 | 'prefix' => env('QUEUE_PREFIX', ''), 32 | 33 | /* 34 | |-------------------------------------------------------------------------- 35 | | Queue Connections 36 | |-------------------------------------------------------------------------- 37 | | 38 | | Here you may configure the connection information for each server that 39 | | is used by your application. A default configuration has been added 40 | | for each back-end shipped with Laravel. You are free to add more. 41 | | 42 | */ 43 | 44 | 'connections' => [ 45 | 46 | 'sync' => [ 47 | 'driver' => 'sync', 48 | ], 49 | 50 | 'database' => [ 51 | 'driver' => 'database', 52 | 'table' => 'jobs', 53 | 'queue' => 'default', 54 | 'retry_after' => 90, 55 | ], 56 | 57 | 'beanstalkd' => [ 58 | 'driver' => 'beanstalkd', 59 | 'host' => 'localhost', 60 | 'queue' => 'default', 61 | 'retry_after' => 90, 62 | ], 63 | 64 | 'sqs' => [ 65 | 'driver' => 'sqs', 66 | 'key' => 'your-public-key', 67 | 'secret' => 'your-secret-key', 68 | 'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id', 69 | 'queue' => 'your-queue-name', 70 | 'region' => 'us-east-1', 71 | ], 72 | 73 | 'redis' => [ 74 | 'driver' => 'redis', 75 | 'connection' => 'default', 76 | 'queue' => 'default', 77 | 'retry_after' => 90, 78 | ], 79 | 80 | ], 81 | 82 | /* 83 | |-------------------------------------------------------------------------- 84 | | Failed Queue Jobs 85 | |-------------------------------------------------------------------------- 86 | | 87 | | These options configure the behavior of failed queue job logging so you 88 | | can control which database and table are used to store the jobs that 89 | | have failed. You may change them to any database / table you wish. 90 | | 91 | */ 92 | 93 | 'failed' => [ 94 | 'database' => env('DB_CONNECTION', 'mysql'), 95 | 'table' => 'failed_jobs', 96 | ], 97 | 98 | ]; 99 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'domain' => env('MAILGUN_DOMAIN'), 19 | 'secret' => env('MAILGUN_SECRET'), 20 | ], 21 | 22 | 'ses' => [ 23 | 'key' => env('SES_KEY'), 24 | 'secret' => env('SES_SECRET'), 25 | 'region' => 'us-east-1', 26 | ], 27 | 28 | 'sparkpost' => [ 29 | 'secret' => env('SPARKPOST_SECRET'), 30 | ], 31 | 32 | 'stripe' => [ 33 | 'model' => App\User::class, 34 | 'key' => env('STRIPE_KEY'), 35 | 'secret' => env('STRIPE_SECRET'), 36 | ], 37 | 38 | ]; 39 | -------------------------------------------------------------------------------- /config/session.php: -------------------------------------------------------------------------------- 1 | env('SESSION_DRIVER', 'file'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Session Lifetime 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may specify the number of minutes that you wish the session 27 | | to be allowed to remain idle before it expires. If you want them 28 | | to immediately expire on the browser closing, set that option. 29 | | 30 | */ 31 | 32 | 'lifetime' => 120, 33 | 34 | 'expire_on_close' => false, 35 | 36 | /* 37 | |-------------------------------------------------------------------------- 38 | | Session Encryption 39 | |-------------------------------------------------------------------------- 40 | | 41 | | This option allows you to easily specify that all of your session data 42 | | should be encrypted before it is stored. All encryption will be run 43 | | automatically by Laravel and you can use the Session like normal. 44 | | 45 | */ 46 | 47 | 'encrypt' => false, 48 | 49 | /* 50 | |-------------------------------------------------------------------------- 51 | | Session File Location 52 | |-------------------------------------------------------------------------- 53 | | 54 | | When using the native session driver, we need a location where session 55 | | files may be stored. A default has been set for you but a different 56 | | location may be specified. This is only needed for file sessions. 57 | | 58 | */ 59 | 60 | 'files' => storage_path('framework/sessions'), 61 | 62 | /* 63 | |-------------------------------------------------------------------------- 64 | | Session Database Connection 65 | |-------------------------------------------------------------------------- 66 | | 67 | | When using the "database" or "redis" session drivers, you may specify a 68 | | connection that should be used to manage these sessions. This should 69 | | correspond to a connection in your database configuration options. 70 | | 71 | */ 72 | 73 | 'connection' => null, 74 | 75 | /* 76 | |-------------------------------------------------------------------------- 77 | | Session Database Table 78 | |-------------------------------------------------------------------------- 79 | | 80 | | When using the "database" session driver, you may specify the table we 81 | | should use to manage the sessions. Of course, a sensible default is 82 | | provided for you; however, you are free to change this as needed. 83 | | 84 | */ 85 | 86 | 'table' => 'sessions', 87 | 88 | /* 89 | |-------------------------------------------------------------------------- 90 | | Session Cache Store 91 | |-------------------------------------------------------------------------- 92 | | 93 | | When using the "apc" or "memcached" session drivers, you may specify a 94 | | cache store that should be used for these sessions. This value must 95 | | correspond with one of the application's configured cache stores. 96 | | 97 | */ 98 | 99 | 'store' => null, 100 | 101 | /* 102 | |-------------------------------------------------------------------------- 103 | | Session Sweeping Lottery 104 | |-------------------------------------------------------------------------- 105 | | 106 | | Some session drivers must manually sweep their storage location to get 107 | | rid of old sessions from storage. Here are the chances that it will 108 | | happen on a given request. By default, the odds are 2 out of 100. 109 | | 110 | */ 111 | 112 | 'lottery' => [2, 100], 113 | 114 | /* 115 | |-------------------------------------------------------------------------- 116 | | Session Cookie Name 117 | |-------------------------------------------------------------------------- 118 | | 119 | | Here you may change the name of the cookie used to identify a session 120 | | instance by ID. The name specified here will get used every time a 121 | | new session cookie is created by the framework for every driver. 122 | | 123 | */ 124 | 125 | 'cookie' => 'laravel_session', 126 | 127 | /* 128 | |-------------------------------------------------------------------------- 129 | | Session Cookie Path 130 | |-------------------------------------------------------------------------- 131 | | 132 | | The session cookie path determines the path for which the cookie will 133 | | be regarded as available. Typically, this will be the root path of 134 | | your application but you are free to change this when necessary. 135 | | 136 | */ 137 | 138 | 'path' => '/', 139 | 140 | /* 141 | |-------------------------------------------------------------------------- 142 | | Session Cookie Domain 143 | |-------------------------------------------------------------------------- 144 | | 145 | | Here you may change the domain of the cookie used to identify a session 146 | | in your application. This will determine which domains the cookie is 147 | | available to in your application. A sensible default has been set. 148 | | 149 | */ 150 | 151 | 'domain' => env('SESSION_DOMAIN', null), 152 | 153 | /* 154 | |-------------------------------------------------------------------------- 155 | | HTTPS Only Cookies 156 | |-------------------------------------------------------------------------- 157 | | 158 | | By setting this option to true, session cookies will only be sent back 159 | | to the server if the browser has a HTTPS connection. This will keep 160 | | the cookie from being sent to you if it can not be done securely. 161 | | 162 | */ 163 | 164 | 'secure' => env('SESSION_SECURE_COOKIE', false), 165 | 166 | /* 167 | |-------------------------------------------------------------------------- 168 | | HTTP Access Only 169 | |-------------------------------------------------------------------------- 170 | | 171 | | Setting this value to true will prevent JavaScript from accessing the 172 | | value of the cookie and the cookie will only be accessible through 173 | | the HTTP protocol. You are free to modify this option if needed. 174 | | 175 | */ 176 | 177 | 'http_only' => true, 178 | 179 | ]; 180 | -------------------------------------------------------------------------------- /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' => realpath(storage_path('framework/views')), 32 | 33 | ]; 34 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite 2 | -------------------------------------------------------------------------------- /database/factories/ModelFactory.php: -------------------------------------------------------------------------------- 1 | define(App\User::class, function (Faker\Generator $faker) { 16 | static $password; 17 | 18 | return [ 19 | 'name' => $faker->name, 20 | 'email' => $faker->unique()->safeEmail, 21 | 'password' => $password ?: $password = bcrypt('secret'), 22 | 'remember_token' => str_random(10), 23 | ]; 24 | }); 25 | 26 | 27 | // quickly create fifty threads using $ php artisan tinker, then: 28 | // factory('App\Thread', 50)->create(); 29 | $factory->define(App\Thread::class, function(Faker\Generator $faker){ 30 | return [ 31 | 'user_id' => function(){ 32 | return factory('App\User')->create()->id; 33 | }, 34 | 'channel_id' => function(){ 35 | return factory('App\Channel')->create()->id; 36 | }, 37 | 'title' => $faker->sentence, 38 | 'body' => $faker->paragraph, 39 | 40 | ]; 41 | }); 42 | 43 | $factory->define(App\Reply::class, function(Faker\Generator $faker){ 44 | return [ 45 | 'thread_id' => function(){ 46 | return factory('App\Thread')->create()->id; 47 | }, 48 | 'user_id' => function(){ 49 | return factory('App\User')->create()->id; 50 | }, 51 | 'body' => $faker->paragraph 52 | ]; 53 | }); 54 | 55 | $factory->define(App\Channel::class, function(Faker\Generator $faker){ 56 | $name = $faker->word; 57 | 58 | return [ 59 | 'name' => $name, 60 | 'slug' => $name 61 | ]; 62 | }); 63 | 64 | 65 | $factory->define(Illuminate\Notifications\DatabaseNotification::class, function(Faker\Generator $faker){ 66 | return [ 67 | 'id' => \Ramsey\Uuid\Uuid::uuid4()->toString(), // generate unique id 68 | 'type' => 'App\Notifications\ThreadWasUpdated', 69 | 'notifiable_id' => function(){ 70 | return auth()->id() ?: factory('App\User')->create()->id; 71 | }, 72 | 'notifiable_type' => 'App\User', 73 | 'data' => ['foo' => 'bar'] 74 | ]; 75 | }); 76 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 19 | $table->string('name'); 20 | $table->string('email')->unique(); 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/2017_04_21_224745_create_threads_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->unsignedInteger('user_id'); 19 | $table->unsignedInteger('channel_id'); 20 | $table->unsignedInteger('replies_count')->default(0); 21 | $table->string('title'); 22 | $table->text('body'); 23 | $table->timestamps(); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('threads'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /database/migrations/2017_04_21_233654_create_replies_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->integer('thread_id'); 19 | $table->integer('user_id'); 20 | $table->text('body'); 21 | $table->timestamps(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | * 28 | * @return void 29 | */ 30 | public function down() 31 | { 32 | Schema::dropIfExists('replies'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /database/migrations/2017_05_29_025659_create_channels_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->string('name', 50); 19 | $table->string('slug', 50); 20 | $table->timestamps(); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | * 27 | * @return void 28 | */ 29 | public function down() 30 | { 31 | Schema::dropIfExists('channels'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /database/migrations/2017_06_30_195457_create_favorites_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->unsignedInteger('user_id'); 19 | $table->unsignedInteger('favorited_id'); 20 | $table->string('favorited_type', 50); 21 | $table->timestamps(); 22 | 23 | // cannot have more than one of that combination 24 | $table->unique(['user_id', 'favorited_id', 'favorited_type']); 25 | }); 26 | } 27 | 28 | /** 29 | * Reverse the migrations. 30 | * 31 | * @return void 32 | */ 33 | public function down() 34 | { 35 | Schema::dropIfExists('favorites'); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /database/migrations/2017_07_05_151909_create_activities_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 19 | $table->unsignedInteger('user_id')->index(); 20 | $table->unsignedInteger('subject_id')->index(); 21 | $table->string('subject_type', 50); 22 | $table->string('type', 50); 23 | $table->timestamps(); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('activities'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /database/migrations/2017_10_24_160355_create_thread_subscriptions_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->unsignedInteger('user_id'); 19 | $table->unsignedInteger('thread_id'); 20 | $table->unique(['user_id', 'thread_id']); 21 | 22 | $table->foreign('thread_id') 23 | ->references('id') 24 | ->on('threads') 25 | ->onDelete('cascade'); 26 | 27 | $table->timestamps(); 28 | }); 29 | } 30 | 31 | /** 32 | * Reverse the migrations. 33 | * 34 | * @return void 35 | */ 36 | public function down() 37 | { 38 | Schema::dropIfExists('thread_subscriptions'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /database/migrations/2017_10_31_171936_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/seeds/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | create(); 16 | factory(App\Reply::class, 5)->create(); 17 | } 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "dev": "npm run development", 5 | "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 6 | "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 7 | "watch-poll": "npm run watch -- --watch-poll", 8 | "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", 9 | "prod": "npm run production", 10 | "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" 11 | }, 12 | "devDependencies": { 13 | "axios": "^0.15.3", 14 | "bootstrap-sass": "^3.3.7", 15 | "cross-env": "^3.2.3", 16 | "jquery": "^3.1.1", 17 | "laravel-mix": "1.2.1", 18 | "lodash": "^4.17.4", 19 | "vue": "^2.4.1" 20 | }, 21 | "dependencies": { 22 | "moment": "^2.18.1" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | ./tests/Feature 14 | 15 | 16 | 17 | ./tests/Unit 18 | 19 | 20 | 21 | 22 | ./app 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Redirect Trailing Slashes If Not A Folder... 9 | RewriteCond %{REQUEST_FILENAME} !-d 10 | RewriteRule ^(.*)/$ /$1 [L,R=301] 11 | 12 | # Handle Front Controller... 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | RewriteCond %{REQUEST_FILENAME} !-f 15 | RewriteRule ^ index.php [L] 16 | 17 | # Handle Authorization Header 18 | RewriteCond %{HTTP:Authorization} . 19 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 20 | 21 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/connor11528/laravel-forum/2537256fdf10a57c87bc6ed0deeb44ac18c1aa41/public/favicon.ico -------------------------------------------------------------------------------- /public/fonts/vendor/bootstrap-sass/bootstrap/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/connor11528/laravel-forum/2537256fdf10a57c87bc6ed0deeb44ac18c1aa41/public/fonts/vendor/bootstrap-sass/bootstrap/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /public/fonts/vendor/bootstrap-sass/bootstrap/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/connor11528/laravel-forum/2537256fdf10a57c87bc6ed0deeb44ac18c1aa41/public/fonts/vendor/bootstrap-sass/bootstrap/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /public/fonts/vendor/bootstrap-sass/bootstrap/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/connor11528/laravel-forum/2537256fdf10a57c87bc6ed0deeb44ac18c1aa41/public/fonts/vendor/bootstrap-sass/bootstrap/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /public/fonts/vendor/bootstrap-sass/bootstrap/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/connor11528/laravel-forum/2537256fdf10a57c87bc6ed0deeb44ac18c1aa41/public/fonts/vendor/bootstrap-sass/bootstrap/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | /* 11 | |-------------------------------------------------------------------------- 12 | | Register The Auto Loader 13 | |-------------------------------------------------------------------------- 14 | | 15 | | Composer provides a convenient, automatically generated class loader for 16 | | our application. We just need to utilize it! We'll simply require it 17 | | into the script here so that we don't have to worry about manual 18 | | loading any of our classes later on. It feels great to relax. 19 | | 20 | */ 21 | 22 | require __DIR__.'/../bootstrap/autoload.php'; 23 | 24 | /* 25 | |-------------------------------------------------------------------------- 26 | | Turn On The Lights 27 | |-------------------------------------------------------------------------- 28 | | 29 | | We need to illuminate PHP development, so let us turn on the lights. 30 | | This bootstraps the framework and gets it ready for use, then it 31 | | will load up this application so that we can run it and send 32 | | the responses back to the browser and delight our users. 33 | | 34 | */ 35 | 36 | $app = require_once __DIR__.'/../bootstrap/app.php'; 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Run The Application 41 | |-------------------------------------------------------------------------- 42 | | 43 | | Once we have the application, we can handle the incoming request 44 | | through the kernel, and send the associated response back to 45 | | the client's browser allowing them to enjoy the creative 46 | | and wonderful application we have prepared for them. 47 | | 48 | */ 49 | 50 | $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); 51 | 52 | $response = $kernel->handle( 53 | $request = Illuminate\Http\Request::capture() 54 | ); 55 | 56 | $response->send(); 57 | 58 | $kernel->terminate($request, $response); 59 | -------------------------------------------------------------------------------- /public/mix-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "/js/app.js": "/js/app.js", 3 | "/css/app.css": "/css/app.css" 4 | } -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /resources/assets/js/app.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * First we will load all of this project's JavaScript dependencies which 4 | * includes Vue and other libraries. It is a great starting point when 5 | * building robust, powerful web applications using Vue and Laravel. 6 | */ 7 | 8 | require('./bootstrap'); 9 | 10 | window.Vue = require('vue'); 11 | 12 | /** 13 | * Next, we will create a fresh Vue application instance and attach it to 14 | * the page. Then, you may begin adding components to this application 15 | * or customize the JavaScript scaffolding to fit your unique needs. 16 | */ 17 | 18 | Vue.component('flash', require('./components/Flash.vue')); 19 | Vue.component('paginator', require('./components/Paginator.vue')); 20 | Vue.component('user-notifications', require('./components/UserNotifications.vue')); 21 | 22 | Vue.component('thread-view', require('./pages/Thread.vue')); 23 | 24 | const app = new Vue({ 25 | el: '#app' 26 | }); 27 | 28 | 29 | -------------------------------------------------------------------------------- /resources/assets/js/bootstrap.js: -------------------------------------------------------------------------------- 1 | 2 | window._ = require('lodash'); 3 | window.Vue = require('vue'); 4 | 5 | // Vue authorization helper method 6 | Vue.prototype.authorize = function(handler){ 7 | // can add additional admin privileges here 8 | let user = window.App.user; 9 | 10 | return user ? handler(user) : false; 11 | }; 12 | 13 | /** 14 | * We'll load jQuery and the Bootstrap jQuery plugin which provides support 15 | * for JavaScript based Bootstrap features such as modals and tabs. This 16 | * code may be modified to fit the specific needs of your application. 17 | */ 18 | 19 | try { 20 | window.$ = window.jQuery = require('jquery'); 21 | 22 | require('bootstrap-sass'); 23 | } catch (e) {} 24 | 25 | /** 26 | * We'll load the axios HTTP library which allows us to easily issue requests 27 | * to our Laravel back-end. This library automatically handles sending the 28 | * CSRF token as a header based on the value of the "XSRF" token cookie. 29 | */ 30 | 31 | window.axios = require('axios'); 32 | 33 | window.axios.defaults.headers.common['X-CSRF-TOKEN'] = window.App.csrfToken; 34 | window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 35 | 36 | // Events bus 37 | window.events = new Vue(); 38 | 39 | window.flash = function(message){ 40 | window.events.$emit('flash', message); 41 | } -------------------------------------------------------------------------------- /resources/assets/js/components/Favorite.vue: -------------------------------------------------------------------------------- 1 | 7 | 8 | -------------------------------------------------------------------------------- /resources/assets/js/components/Flash.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 38 | 39 | 47 | -------------------------------------------------------------------------------- /resources/assets/js/components/NewReply.vue: -------------------------------------------------------------------------------- 1 | 24 | 25 | -------------------------------------------------------------------------------- /resources/assets/js/components/Paginator.vue: -------------------------------------------------------------------------------- 1 | 15 | 16 | -------------------------------------------------------------------------------- /resources/assets/js/components/Replies.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | -------------------------------------------------------------------------------- /resources/assets/js/components/Reply.vue: -------------------------------------------------------------------------------- 1 | 35 | 36 | -------------------------------------------------------------------------------- /resources/assets/js/components/SubscribeButton.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | -------------------------------------------------------------------------------- /resources/assets/js/components/UserNotifications.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | -------------------------------------------------------------------------------- /resources/assets/js/mixins/Collection.js: -------------------------------------------------------------------------------- 1 | export default { 2 | data(){ 3 | return { 4 | items: [] 5 | }; 6 | }, 7 | methods: { 8 | add(item){ 9 | this.items.push(item); 10 | this.$emit('added'); 11 | }, 12 | remove(index){ 13 | this.items.splice(index, 1); 14 | this.$emit('removed'); 15 | } 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /resources/assets/js/pages/Thread.vue: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /resources/assets/sass/_variables.scss: -------------------------------------------------------------------------------- 1 | 2 | // Body 3 | $body-bg: #f5f8fa; 4 | 5 | // Borders 6 | $laravel-border-color: darken($body-bg, 10%); 7 | $list-group-border: $laravel-border-color; 8 | $navbar-default-border: $laravel-border-color; 9 | $panel-default-border: $laravel-border-color; 10 | $panel-inner-border: $laravel-border-color; 11 | 12 | // Brands 13 | $brand-primary: #3097D1; 14 | $brand-info: #8eb4cb; 15 | $brand-success: #2ab27b; 16 | $brand-warning: #cbb956; 17 | $brand-danger: #bf5329; 18 | 19 | // Typography 20 | $icon-font-path: "~bootstrap-sass/assets/fonts/bootstrap/"; 21 | $font-family-sans-serif: "Raleway", sans-serif; 22 | $font-size-base: 14px; 23 | $line-height-base: 1.6; 24 | $text-color: #636b6f; 25 | 26 | // Navbar 27 | $navbar-default-bg: #fff; 28 | 29 | // Buttons 30 | $btn-default-color: $text-color; 31 | 32 | // Inputs 33 | $input-border: lighten($text-color, 40%); 34 | $input-border-focus: lighten($brand-primary, 25%); 35 | $input-color-placeholder: lighten($text-color, 30%); 36 | 37 | // Panels 38 | $panel-default-heading-bg: #fff; 39 | -------------------------------------------------------------------------------- /resources/assets/sass/app.scss: -------------------------------------------------------------------------------- 1 | 2 | // Fonts 3 | @import url(https://fonts.googleapis.com/css?family=Raleway:300,400,600); 4 | 5 | // Variables 6 | @import "variables"; 7 | 8 | // Bootstrap 9 | @import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap"; 10 | -------------------------------------------------------------------------------- /resources/lang/en/auth.php: -------------------------------------------------------------------------------- 1 | 'These credentials do not match our records.', 17 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /resources/lang/en/pagination.php: -------------------------------------------------------------------------------- 1 | '« Previous', 17 | 'next' => 'Next »', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /resources/lang/en/passwords.php: -------------------------------------------------------------------------------- 1 | 'Passwords must be at least six characters and match the confirmation.', 17 | 'reset' => 'Your password has been reset!', 18 | 'sent' => 'We have e-mailed your password reset link!', 19 | 'token' => 'This password reset token is invalid.', 20 | 'user' => "We can't find a user with that e-mail address.", 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /resources/lang/en/validation.php: -------------------------------------------------------------------------------- 1 | 'The :attribute must be accepted.', 17 | 'active_url' => 'The :attribute is not a valid URL.', 18 | 'after' => 'The :attribute must be a date after :date.', 19 | 'after_or_equal' => 'The :attribute must be a date after or equal to :date.', 20 | 'alpha' => 'The :attribute may only contain letters.', 21 | 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', 22 | 'alpha_num' => 'The :attribute may only contain letters and numbers.', 23 | 'array' => 'The :attribute must be an array.', 24 | 'before' => 'The :attribute must be a date before :date.', 25 | 'before_or_equal' => 'The :attribute must be a date before or equal to :date.', 26 | 'between' => [ 27 | 'numeric' => 'The :attribute must be between :min and :max.', 28 | 'file' => 'The :attribute must be between :min and :max kilobytes.', 29 | 'string' => 'The :attribute must be between :min and :max characters.', 30 | 'array' => 'The :attribute must have between :min and :max items.', 31 | ], 32 | 'boolean' => 'The :attribute field must be true or false.', 33 | 'confirmed' => 'The :attribute confirmation does not match.', 34 | 'date' => 'The :attribute is not a valid date.', 35 | 'date_format' => 'The :attribute does not match the format :format.', 36 | 'different' => 'The :attribute and :other must be different.', 37 | 'digits' => 'The :attribute must be :digits digits.', 38 | 'digits_between' => 'The :attribute must be between :min and :max digits.', 39 | 'dimensions' => 'The :attribute has invalid image dimensions.', 40 | 'distinct' => 'The :attribute field has a duplicate value.', 41 | 'email' => 'The :attribute must be a valid email address.', 42 | 'exists' => 'The selected :attribute is invalid.', 43 | 'file' => 'The :attribute must be a file.', 44 | 'filled' => 'The :attribute field must have a value.', 45 | 'image' => 'The :attribute must be an image.', 46 | 'in' => 'The selected :attribute is invalid.', 47 | 'in_array' => 'The :attribute field does not exist in :other.', 48 | 'integer' => 'The :attribute must be an integer.', 49 | 'ip' => 'The :attribute must be a valid IP address.', 50 | 'json' => 'The :attribute must be a valid JSON string.', 51 | 'max' => [ 52 | 'numeric' => 'The :attribute may not be greater than :max.', 53 | 'file' => 'The :attribute may not be greater than :max kilobytes.', 54 | 'string' => 'The :attribute may not be greater than :max characters.', 55 | 'array' => 'The :attribute may not have more than :max items.', 56 | ], 57 | 'mimes' => 'The :attribute must be a file of type: :values.', 58 | 'mimetypes' => 'The :attribute must be a file of type: :values.', 59 | 'min' => [ 60 | 'numeric' => 'The :attribute must be at least :min.', 61 | 'file' => 'The :attribute must be at least :min kilobytes.', 62 | 'string' => 'The :attribute must be at least :min characters.', 63 | 'array' => 'The :attribute must have at least :min items.', 64 | ], 65 | 'not_in' => 'The selected :attribute is invalid.', 66 | 'numeric' => 'The :attribute must be a number.', 67 | 'present' => 'The :attribute field must be present.', 68 | 'regex' => 'The :attribute format is invalid.', 69 | 'required' => 'The :attribute field is required.', 70 | 'required_if' => 'The :attribute field is required when :other is :value.', 71 | 'required_unless' => 'The :attribute field is required unless :other is in :values.', 72 | 'required_with' => 'The :attribute field is required when :values is present.', 73 | 'required_with_all' => 'The :attribute field is required when :values is present.', 74 | 'required_without' => 'The :attribute field is required when :values is not present.', 75 | 'required_without_all' => 'The :attribute field is required when none of :values are present.', 76 | 'same' => 'The :attribute and :other must match.', 77 | 'size' => [ 78 | 'numeric' => 'The :attribute must be :size.', 79 | 'file' => 'The :attribute must be :size kilobytes.', 80 | 'string' => 'The :attribute must be :size characters.', 81 | 'array' => 'The :attribute must contain :size items.', 82 | ], 83 | 'string' => 'The :attribute must be a string.', 84 | 'timezone' => 'The :attribute must be a valid zone.', 85 | 'unique' => 'The :attribute has already been taken.', 86 | 'uploaded' => 'The :attribute failed to upload.', 87 | 'url' => 'The :attribute format is invalid.', 88 | 89 | /* 90 | |-------------------------------------------------------------------------- 91 | | Custom Validation Language Lines 92 | |-------------------------------------------------------------------------- 93 | | 94 | | Here you may specify custom validation messages for attributes using the 95 | | convention "attribute.rule" to name the lines. This makes it quick to 96 | | specify a specific custom language line for a given attribute rule. 97 | | 98 | */ 99 | 100 | 'custom' => [ 101 | 'attribute-name' => [ 102 | 'rule-name' => 'custom-message', 103 | ], 104 | ], 105 | 106 | /* 107 | |-------------------------------------------------------------------------- 108 | | Custom Validation Attributes 109 | |-------------------------------------------------------------------------- 110 | | 111 | | The following language lines are used to swap attribute place-holders 112 | | with something more reader friendly such as E-Mail Address instead 113 | | of "email". This simply helps us make messages a little cleaner. 114 | | 115 | */ 116 | 117 | 'attributes' => [], 118 | 119 | ]; 120 | -------------------------------------------------------------------------------- /resources/views/auth/login.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
Login
9 |
10 |
11 | {{ csrf_field() }} 12 | 13 |
14 | 15 | 16 |
17 | 18 | 19 | @if ($errors->has('email')) 20 | 21 | {{ $errors->first('email') }} 22 | 23 | @endif 24 |
25 |
26 | 27 |
28 | 29 | 30 |
31 | 32 | 33 | @if ($errors->has('password')) 34 | 35 | {{ $errors->first('password') }} 36 | 37 | @endif 38 |
39 |
40 | 41 |
42 |
43 |
44 | 47 |
48 |
49 |
50 | 51 |
52 |
53 | 56 | 57 | 58 | Forgot Your Password? 59 | 60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | @endsection 69 | -------------------------------------------------------------------------------- /resources/views/auth/passwords/email.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
Reset Password
9 |
10 | @if (session('status')) 11 |
12 | {{ session('status') }} 13 |
14 | @endif 15 | 16 |
17 | {{ csrf_field() }} 18 | 19 |
20 | 21 | 22 |
23 | 24 | 25 | @if ($errors->has('email')) 26 | 27 | {{ $errors->first('email') }} 28 | 29 | @endif 30 |
31 |
32 | 33 |
34 |
35 | 38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | @endsection 47 | -------------------------------------------------------------------------------- /resources/views/auth/passwords/reset.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
Reset Password
9 | 10 |
11 | @if (session('status')) 12 |
13 | {{ session('status') }} 14 |
15 | @endif 16 | 17 |
18 | {{ csrf_field() }} 19 | 20 | 21 | 22 |
23 | 24 | 25 |
26 | 27 | 28 | @if ($errors->has('email')) 29 | 30 | {{ $errors->first('email') }} 31 | 32 | @endif 33 |
34 |
35 | 36 |
37 | 38 | 39 |
40 | 41 | 42 | @if ($errors->has('password')) 43 | 44 | {{ $errors->first('password') }} 45 | 46 | @endif 47 |
48 |
49 | 50 |
51 | 52 |
53 | 54 | 55 | @if ($errors->has('password_confirmation')) 56 | 57 | {{ $errors->first('password_confirmation') }} 58 | 59 | @endif 60 |
61 |
62 | 63 |
64 |
65 | 68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | @endsection 77 | -------------------------------------------------------------------------------- /resources/views/auth/register.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
Register
9 |
10 |
11 | {{ csrf_field() }} 12 | 13 |
14 | 15 | 16 |
17 | 18 | 19 | @if ($errors->has('name')) 20 | 21 | {{ $errors->first('name') }} 22 | 23 | @endif 24 |
25 |
26 | 27 |
28 | 29 | 30 |
31 | 32 | 33 | @if ($errors->has('email')) 34 | 35 | {{ $errors->first('email') }} 36 | 37 | @endif 38 |
39 |
40 | 41 |
42 | 43 | 44 |
45 | 46 | 47 | @if ($errors->has('password')) 48 | 49 | {{ $errors->first('password') }} 50 | 51 | @endif 52 |
53 |
54 | 55 |
56 | 57 | 58 |
59 | 60 |
61 |
62 | 63 |
64 |
65 | 68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | @endsection 77 | -------------------------------------------------------------------------------- /resources/views/home.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
Dashboard
9 | 10 |
11 | You are logged in! 12 |
13 |
14 |
15 |
16 |
17 | @endsection 18 | -------------------------------------------------------------------------------- /resources/views/layouts/app.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | {{ config('app.name', 'Laravel Forum') }} 12 | 13 | 14 | @if(getenv('APP_ENV') == 'production') 15 | 16 | @else 17 | 18 | @endif 19 | 20 | 21 | 28 | 29 | 36 | 37 | 38 |
39 | @include('layouts.nav') 40 | 41 | @yield('content') 42 | 43 | 44 | 45 |
46 | 47 | 48 | @if(getenv('APP_ENV') == 'production') 49 | 50 | @else 51 | 52 | @endif 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /resources/views/layouts/nav.blade.php: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/views/profiles/activities/activity.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 | 5 | {{ $heading }} 6 | 7 |
8 |
9 | 10 |
11 | {{ $body }} 12 |
13 |
-------------------------------------------------------------------------------- /resources/views/profiles/activities/created_reply.blade.php: -------------------------------------------------------------------------------- 1 | @component('profiles.activities.activity') 2 | @slot('heading') 3 | {{ $profileUser->name }} replied to 4 | "{{$activity->subject->thread->title }}" 5 | @endslot 6 | 7 | @slot('body') 8 | {{ $activity->subject->body }} 9 | @endslot 10 | @endcomponent -------------------------------------------------------------------------------- /resources/views/profiles/activities/created_thread.blade.php: -------------------------------------------------------------------------------- 1 | @component('profiles.activities.activity') 2 | @slot('heading') 3 | {{ $profileUser->name }} published 4 | {{$activity->subject->title }} 5 | @endslot 6 | 7 | @slot('body') 8 | {{ $activity->subject->body }} 9 | @endslot 10 | @endcomponent -------------------------------------------------------------------------------- /resources/views/profiles/show.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 | 5 |
6 |
7 |
8 | 14 | 15 | @forelse($activities as $date => $activity) 16 | 17 | 18 | @foreach($activity as $record) 19 | @if(view()->exists("profiles.activities.{$record->type}")) 20 | @include("profiles.activities.{$record->type}", ["activity" => $record]) 21 | @endif 22 | @endforeach 23 | @empty 24 |

There is no activity for this user yet.

25 | @endforelse 26 |
27 |
28 |
29 | @endsection -------------------------------------------------------------------------------- /resources/views/threads/create.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
Create a New Thread
9 | 10 |
11 |
12 | {{ csrf_field() }} 13 | 14 |
15 | 16 | 25 |
26 | 27 |
28 | 29 | 30 |
31 | 32 |
33 | 34 | 35 |
36 | 37 |
38 | 39 |
40 | 41 | @if(count($errors)) 42 |
    43 | @foreach($errors->all() as $error) 44 |
  • {{$error}}
  • 45 | @endforeach 46 |
47 | @endif 48 |
49 | 50 |
51 |
52 |
53 |
54 |
55 | @endsection -------------------------------------------------------------------------------- /resources/views/threads/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 | @forelse($threads as $thread) 8 |
9 | 19 | 20 |
21 |
22 | {{ $thread->body }} 23 |
24 |
25 |
26 | @empty 27 |

There are no threads in this category yet. Create one!

28 | @endforelse 29 |
30 |
31 |
32 | @endsection -------------------------------------------------------------------------------- /resources/views/threads/reply.blade.php: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 |
5 |
6 | {{ $reply->owner->name }} said {{ $reply->created_at->diffForHumans() }}... 7 |
8 | 9 | @if(Auth::check()) 10 |
11 | 12 |
13 | @endif 14 |
15 |
16 | 17 |
18 |
19 |
20 | 21 |
22 | 23 | 24 | 25 |
26 |
27 | {{ $reply->body }} 28 |
29 |
30 | 31 | @can('update', $reply) 32 | 36 | @endcan 37 |
38 |
-------------------------------------------------------------------------------- /resources/views/threads/show.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 | 5 |
6 |
7 |
8 |
9 |
10 |
11 | 12 |

{{ $thread->title }}

13 | 14 | 15 | Posted by {{ $thread->creator->name }} 16 |
17 | 18 | @can('update', $thread) 19 |
20 | {{ csrf_field() }} 21 | {{ method_field('DELETE') }} 22 | 23 |
24 | @endcan 25 |
26 |
27 | 28 |
29 | {{ $thread->body }} 30 |
31 |
32 | 33 | 34 | 35 |
36 |
37 |
38 | 39 |
40 | This thread was published {{ $thread->created_at->diffForHumans() }} by {{ $thread->creator->name }} and currently has {{ str_plural('reply', $thread->replies_count) }}. 41 |

42 | 43 |

44 | 45 |
46 | 47 |
48 |
49 |
50 |
51 |
52 | @endsection -------------------------------------------------------------------------------- /resources/views/welcome.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Laravel 9 | 10 | 11 | 12 | 13 | 14 | 66 | 67 | 68 |
69 | @if (Route::has('login')) 70 | 78 | @endif 79 | 80 |
81 |
82 | Laravel 83 |
84 | 85 | 92 |
93 |
94 | 95 | 96 | -------------------------------------------------------------------------------- /routes/api.php: -------------------------------------------------------------------------------- 1 | get('/user', function (Request $request) { 17 | return $request->user(); 18 | }); 19 | -------------------------------------------------------------------------------- /routes/channels.php: -------------------------------------------------------------------------------- 1 | id === (int) $id; 16 | }); 17 | -------------------------------------------------------------------------------- /routes/console.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 18 | })->describe('Display an inspiring quote'); 19 | -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 36 | Route::delete('/threads/{channel}/{thread}/subscriptions', 'ThreadSubscriptionsController@destroy')->middleware('auth'); 37 | 38 | // Replies 39 | Route::delete('/replies/{reply}', 'RepliesController@destroy'); 40 | Route::post('/replies/{reply}/favorites', 'FavoritesController@store'); 41 | Route::delete('/replies/{reply}/favorites', 'FavoritesController@destroy'); 42 | Route::patch('/replies/{reply}', 'RepliesController@update'); 43 | 44 | 45 | // Profile 46 | Route::get('/profiles/{user}', 'ProfilesController@show')->name('profile'); 47 | Route::get("/profiles/{user}/notifications", 'UserNotificationsController@index'); 48 | Route::delete('/profiles/{user}/notifications/{notification}', 'UserNotificationsController@destroy'); 49 | 50 | -------------------------------------------------------------------------------- /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 -------------------------------------------------------------------------------- /storage/framework/.gitignore: -------------------------------------------------------------------------------- 1 | config.php 2 | routes.php 3 | schedule-* 4 | compiled.php 5 | services.json 6 | events.scanned.php 7 | routes.scanned.php 8 | down 9 | -------------------------------------------------------------------------------- /storage/framework/cache/.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 | -------------------------------------------------------------------------------- /tests/CreatesApplication.php: -------------------------------------------------------------------------------- 1 | make(Kernel::class)->bootstrap(); 19 | 20 | return $app; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/Feature/CreateThreadsTest.php: -------------------------------------------------------------------------------- 1 | withExceptionHandling(); 19 | 20 | $this->get('/threads/create') 21 | ->assertRedirect('/login'); 22 | $this->post('/threads') 23 | ->assertRedirect('/login'); 24 | } 25 | 26 | /** @test */ 27 | public function an_authenticated_user_can_create_new_forum_threads() 28 | { 29 | $this->signIn(); 30 | 31 | $thread = make('App\Thread'); 32 | $response = $this->post('/threads', $thread->toArray()); 33 | 34 | // get location of the redirection and check post is there 35 | $this->get($response->headers->get('Location')) 36 | ->assertSee($thread->title) 37 | ->assertSee($thread->body); 38 | } 39 | 40 | /** @test */ 41 | public function a_thread_requires_a_title() 42 | { 43 | $this->publishThread(['title' => null]) 44 | ->assertSessionHasErrors('title'); 45 | } 46 | 47 | /** @test */ 48 | public function a_thread_requires_a_body() 49 | { 50 | $this->publishThread(['body' => null]) 51 | ->assertSessionHasErrors('body'); 52 | } 53 | 54 | /** @test */ 55 | public function a_thread_requires_a_valid_channel() 56 | { 57 | factory('App\Channel', 2)->create(); 58 | 59 | // cannot be null 60 | $this->publishThread(['channel_id' => null]) 61 | ->assertSessionHasErrors('channel_id'); 62 | 63 | // must be existing channel (fails w/ id=2) 64 | $this->publishThread(['channel_id' => 999]) 65 | ->assertSessionHasErrors('channel_id'); 66 | } 67 | 68 | /** @test */ 69 | public function authorized_users_can_delete_threads() 70 | { 71 | $this->signIn(); 72 | 73 | // create thread owned by user with reply 74 | $thread = create('App\Thread', ['user_id' => auth()->id()]); 75 | $reply = create('App\Reply', ['thread_id' => $thread->id]); 76 | 77 | $response = $this->json('DELETE', $thread->path()); 78 | 79 | $response->assertStatus(204); 80 | 81 | $this->assertDatabaseMissing('threads', ['id' => $thread->id]); 82 | $this->assertDatabaseMissing('replies', ['id' => $reply->id]); 83 | 84 | // make sure that threads and replies activities is also empty 85 | $this->assertEquals(0, Activity::count()); 86 | 87 | } 88 | 89 | /** @test */ 90 | public function unauthorized_users_may_not_delete_threads() 91 | { 92 | $this->withExceptionHandling(); 93 | $thread = create('App\Thread'); 94 | 95 | // delete as guest 96 | $this->delete($thread->path()) 97 | ->assertRedirect('/login'); 98 | 99 | $this->signIn(); 100 | 101 | // test authorization 102 | $this->delete($thread->path()) 103 | ->assertStatus(403); 104 | } 105 | 106 | 107 | protected function publishThread($overrides = []) 108 | { 109 | // laravel can catch exception and perform redirect 110 | $this->withExceptionHandling() 111 | ->signIn(); 112 | 113 | $thread = make('App\Thread', $overrides); 114 | return $this->post('/threads', $thread->toArray()); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /tests/Feature/FavoritesTest.php: -------------------------------------------------------------------------------- 1 | withExceptionHandling() 16 | ->post('replies/1/favorites') 17 | ->assertRedirect('/login'); 18 | } 19 | 20 | /** @test */ 21 | public function an_authenticated_user_can_favorite_any_reply() 22 | { 23 | $this->signIn(); 24 | 25 | $reply = create('App\Reply'); 26 | 27 | // If I post to a favorite endpoint 28 | $this->post('replies/' . $reply->id . '/favorites'); 29 | 30 | // It should be recorded in the database 31 | $this->assertCount(1, $reply->favorites); 32 | } 33 | 34 | /** @test */ 35 | public function an_authenticated_user_may_only_favorite_a_reply_once() 36 | { 37 | $this->signIn(); 38 | 39 | $reply = create('App\Reply'); 40 | 41 | try { 42 | $this->post('replies/' . $reply->id . '/favorites'); 43 | $this->post('replies/' . $reply->id . '/favorites'); 44 | } catch (\Exception $e) { 45 | // better fail test error handling 46 | $this->fail('Database did not expect to insert the same record twice.'); 47 | } 48 | 49 | $this->assertCount(1, $reply->favorites); 50 | } 51 | 52 | /** @test */ 53 | public function an_authenticated_user_can_unfavorite_any_reply() 54 | { 55 | $this->signIn(); 56 | $reply = create('App\Reply'); 57 | 58 | // favorite 59 | $reply->favorite(); 60 | 61 | // unfavorite 62 | $this->delete('replies/' . $reply->id . '/favorites'); 63 | $this->assertCount(0, $reply->favorites); 64 | } 65 | } -------------------------------------------------------------------------------- /tests/Feature/NotificationsTest.php: -------------------------------------------------------------------------------- 1 | signIn(); 19 | } 20 | 21 | /** @test **/ 22 | public function a_notification_is_prepared_when_a_subscribed_thread_receives_a_reply_from_not_current_user() 23 | { 24 | // create thread and subscribe to it 25 | $thread = create('App\Thread')->subscribe(); 26 | 27 | // check notifications is empty 28 | $this->assertCount(0, auth()->user()->notifications); 29 | 30 | // signed in user leaves reply on thread 31 | $thread->addReply([ 32 | 'user_id' => auth()->id(), 33 | 'body' => 'reply to a thread here' 34 | ]); 35 | 36 | // get fresh instance of user's notifications and check that there is none 37 | $this->assertCount(0, auth()->user()->fresh()->notifications); 38 | 39 | // new user leaves reply on thread 40 | $thread->addReply([ 41 | 'user_id' => create('App\User')->id, 42 | 'body' => 'reply to a thread here' 43 | ]); 44 | 45 | // notify the logged in user with one notification 46 | $this->assertCount(1, auth()->user()->fresh()->notifications); 47 | } 48 | 49 | /** @test **/ 50 | public function a_user_can_mark_a_notification_as_read() 51 | { 52 | 53 | create(DatabaseNotification::class); 54 | 55 | $user = auth()->user(); 56 | 57 | $this->assertCount(1, $user->unreadNotifications); 58 | 59 | $notificationId = $user->unreadNotifications->first()->id; 60 | 61 | // send delete request for user's notification 62 | $this->delete("/profiles/{$user->name}/notifications/{$notificationId}"); 63 | 64 | $this->assertCount(0, $user->fresh()->unreadNotifications); 65 | 66 | } 67 | 68 | /** @test **/ 69 | public function a_user_can_fetch_unread_notifications() 70 | { 71 | // invoke model factory to create notification 72 | create(DatabaseNotification::class); 73 | 74 | // make sure there is one 75 | $this->assertCount( 76 | 1, 77 | $this->getJson("/profiles/" . auth()->user()->name . "/notifications")->json() 78 | ); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /tests/Feature/ParticipateInForumTest.php: -------------------------------------------------------------------------------- 1 | withExceptionHandling() 16 | ->post('/threads/some-channel/1/replies', []) 17 | ->assertRedirect('/login'); 18 | } 19 | 20 | /** @test */ 21 | function an_authenticated_user_may_participate_in_forum_threads() 22 | { 23 | $this->signIn(); // sets authenticated user 24 | 25 | $thread = create('App\Thread'); 26 | $reply = make('App\Reply'); 27 | 28 | $this->post($thread->path().'/replies', $reply->toArray()); 29 | 30 | // make sure reply is added to database 31 | $this->assertDatabaseHas('replies', ['body' => $reply->body]); 32 | 33 | // make sure the thread reply_count is incremented 34 | $this->assertEquals(1, $thread->fresh()->replies_count); 35 | } 36 | 37 | /** @test */ 38 | function a_reply_requires_a_body() 39 | { 40 | $this->withExceptionHandling()->signIn(); 41 | $thread = create('App\Thread'); 42 | $reply = make('App\Reply', ['body' => null]); 43 | 44 | $this->post($thread->path() . '/replies', $reply->toArray()) 45 | ->assertSessionHasErrors('body'); 46 | } 47 | 48 | /** @test */ 49 | function unauthorized_users_cannot_delete_replies(){ 50 | $this->withExceptionHandling(); 51 | 52 | $reply = create('App\Reply'); 53 | 54 | $this->delete("/replies/{$reply->id}") 55 | ->assertRedirect('login'); 56 | 57 | $this->signIn() 58 | ->delete("/replies/{$reply->id}") 59 | ->assertStatus(403); 60 | } 61 | 62 | /** @test */ 63 | public function authorized_users_can_delete_replies() 64 | { 65 | $this->signIn(); 66 | $reply = create('App\Reply', ['user_id' => auth()->id()]); 67 | 68 | $this->delete("/replies/{$reply->id}")->assertStatus(302); 69 | 70 | $this->assertDatabaseMissing('replies', ['id' => $reply->id]); 71 | $this->assertEquals(0, $reply->thread->fresh()->replies_count); 72 | } 73 | 74 | /** @test */ 75 | function unauthorized_users_cannot_update_replies() 76 | { 77 | $this->withExceptionHandling(); 78 | 79 | $reply = create('App\Reply'); 80 | 81 | $this->patch("/replies/{$reply->id}") 82 | ->assertRedirect('login'); 83 | 84 | $this->signIn() 85 | ->patch("/replies/{$reply->id}") 86 | ->assertStatus(403); 87 | } 88 | 89 | /** @test */ 90 | function authorized_users_can_update_replies() 91 | { 92 | $this->signIn(); 93 | $reply = create('App\Reply', ['user_id' => auth()->id()]); 94 | $updatedBody = 'updated text body for reply'; 95 | 96 | // update reply 97 | $this->patch("/replies/{$reply->id}", [ 'body' => $updatedBody ]); 98 | 99 | // make sure it is updated 100 | $this->assertDatabaseHas('replies', [ 'id' => $reply->id, 'body' => $updatedBody ]); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /tests/Feature/ProfilesTest.php: -------------------------------------------------------------------------------- 1 | get("/profiles/{$user->name}") 17 | ->assertSee($user->name); 18 | } 19 | 20 | /** @test */ 21 | function profiles_display_all_threads_created_by_the_associated_user() 22 | { 23 | $this->signIn(); 24 | 25 | $thread = create('App\Thread', ['user_id' => auth()->id()]); 26 | 27 | $this->get("/profiles/". auth()->user()->name) 28 | ->assertSee($thread->title) 29 | ->assertSee($thread->body); 30 | } 31 | } -------------------------------------------------------------------------------- /tests/Feature/ReadThreadsTest.php: -------------------------------------------------------------------------------- 1 | thread = create('App\Thread'); 16 | } 17 | 18 | /** @test */ 19 | function a_user_can_view_all_threads() 20 | { 21 | $response = $this->get('/threads') 22 | ->assertSee($this->thread->title); 23 | } 24 | 25 | /** @test */ 26 | function a_user_can_read_a_single_thread() 27 | { 28 | $response = $this->get($this->thread->path()) 29 | ->assertSee($this->thread->title); 30 | } 31 | 32 | /** @test */ 33 | function a_user_can_filter_threads_according_to_a_channel() 34 | { 35 | $channel = create('App\Channel'); 36 | $threadInChannel = create('App\Thread', ['channel_id' => $channel->id]); 37 | $threadNotInChannel = create('App\Thread'); 38 | $this->get('/threads/' . $channel->slug) 39 | ->assertSee($threadInChannel->title) 40 | ->assertDontSee($threadNotInChannel->title); 41 | } 42 | 43 | /** @test */ 44 | function a_user_can_filter_threads_by_username() 45 | { 46 | $this->signIn(create('App\User', ['name' => 'JohnDoe'])); 47 | 48 | $threadByJohn = create('App\Thread', ['user_id' => auth()->id()]); 49 | $threadNotByJohn = create('App\Thread'); 50 | 51 | $this->get('threads?by=JohnDoe') 52 | ->assertSee($threadByJohn->title) 53 | ->assertDontSee($threadNotByJohn->title); 54 | } 55 | 56 | /** @test */ 57 | function a_user_can_filter_threads_by_popularity() 58 | { 59 | // create threads and replies 60 | $threadWithNoReplies = $this->thread; 61 | 62 | $threadWithTwoReplies = create('App\Thread'); 63 | create('App\Reply', ['thread_id' => $threadWithTwoReplies->id], 2); 64 | 65 | $threadWithThreeReplies = create('App\Thread'); 66 | create('App\Reply', ['thread_id' => $threadWithThreeReplies->id], 3); 67 | 68 | 69 | // filter threads by popularity 70 | $response = $this->getJson('threads?popular=1')->json(); 71 | 72 | // get replies count 73 | $this->assertEquals([3, 2, 0], array_column($response, 'replies_count')); 74 | } 75 | 76 | /** @test */ 77 | function a_user_can_filter_threads_by_those_that_are_unanswered() 78 | { 79 | $thread = create('App\Thread'); 80 | create('App\Reply', ['thread_id' => $thread->id]); 81 | 82 | $response = $this->getJson('threads?unanswered=1')->json(); 83 | $this->assertCount(1, $response); 84 | } 85 | 86 | /** @test */ 87 | function a_user_can_request_all_replies_for_a_given_thread() 88 | { 89 | $thread = create('App\Thread'); 90 | create('App\Reply', ['thread_id' => $thread->id], 2); 91 | 92 | $response = $this->getJson($thread->path() . '/replies')->json(); 93 | 94 | $this->assertCount(2, $response['data']); 95 | $this->assertEquals(2, $response['total']); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /tests/Feature/SubscribeToThreadsTest.php: -------------------------------------------------------------------------------- 1 | signIn(); 16 | $thread = create('App\Thread'); 17 | 18 | // user subscribes to thread 19 | $this->post($thread->path() . '/subscriptions'); 20 | 21 | $this->assertCount(1, $thread->fresh()->subscriptions); 22 | 23 | } 24 | 25 | /** @test **/ 26 | public function a_user_can_unsubscribe_from_threads() 27 | { 28 | $this->signIn(); 29 | $thread = create('App\Thread'); 30 | $thread->subscribe(); 31 | 32 | $this->delete($thread->path() . '/subscriptions'); 33 | 34 | $this->assertCount(0, $thread->subscriptions); 35 | } 36 | } 37 | 38 | 39 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | disableExceptionHandling(); 20 | } 21 | 22 | protected function disableExceptionHandling() 23 | { 24 | $this->oldExceptionHandler = $this->app->make(ExceptionHandler::class); 25 | $this->app->instance(ExceptionHandler::class, new TestHandler); 26 | } 27 | 28 | protected function withExceptionHandling() 29 | { 30 | $this->app->instance(ExceptionHandler::class, $this->oldExceptionHandler); 31 | return $this; 32 | } 33 | 34 | protected function signIn($user = null) 35 | { 36 | // use passed in user or create one 37 | $user = $user ?: create('App\User'); 38 | $this->actingAs($user); 39 | return $this; 40 | } 41 | } 42 | 43 | 44 | class TestHandler extends Handler 45 | { 46 | public function __construct() 47 | { 48 | } 49 | public function report(\Exception $e) 50 | { 51 | } 52 | public function render($request, \Exception $e) 53 | { 54 | throw $e; 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /tests/Unit/ActivityTest.php: -------------------------------------------------------------------------------- 1 | signIn(); 18 | $thread = create('App\Thread'); 19 | 20 | $this->assertDatabaseHas('activities', [ 21 | 'type' => 'created_thread', 22 | 'user_id' => auth()->id(), 23 | 'subject_id' => $thread->id, 24 | 'subject_type' => 'App\Thread' 25 | ]); 26 | 27 | $activity = Activity::first(); 28 | 29 | $this->assertEquals($activity->subject->id, $thread->id); 30 | } 31 | 32 | /** @test */ 33 | public function it_records_activity_when_a_reply_is_created() 34 | { 35 | $this->signIn(); 36 | 37 | $reply = create('App\Reply'); 38 | 39 | $this->assertEquals(2, Activity::count()); 40 | } 41 | 42 | /** @test */ 43 | function it_fetches_a_feed_for_any_user() 44 | { 45 | // Given we have a thread 46 | $this->signIn(); 47 | 48 | create('App\Thread', ['user_id' => auth()->id() ], 2); 49 | 50 | // and another thread from a week ago 51 | auth()->user()->activity()->first()->update(['created_at' => Carbon::now()->subWeek()]); 52 | 53 | // fetch the user's activity feed 54 | $feed = Activity::feed(auth()->user(), 50); 55 | 56 | // then it should be returned in the proper format 57 | $this->assertTrue($feed->keys()->contains( 58 | Carbon::now()->format('Y-m-d') 59 | )); 60 | 61 | $this->assertTrue($feed->keys()->contains( 62 | Carbon::now()->subWeek()->format('Y-m-d') 63 | )); 64 | } 65 | } -------------------------------------------------------------------------------- /tests/Unit/ChannelTest.php: -------------------------------------------------------------------------------- 1 | $channel->id]); 17 | 18 | $this->assertTrue($channel->threads->contains($thread)); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tests/Unit/ReplyTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('App\User', $reply->owner); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/Unit/ThreadTest.php: -------------------------------------------------------------------------------- 1 | thread = create('App\Thread'); 19 | } 20 | 21 | /** @test */ 22 | function a_thread_can_make_a_string_path() 23 | { 24 | $thread = create('App\Thread'); 25 | $this->assertEquals("/threads/{$thread->channel->slug}/{$thread->id}", $thread->path()); 26 | } 27 | 28 | /** @test */ 29 | function a_thread_has_a_creator() 30 | { 31 | $this->assertInstanceOf('App\User', $this->thread->creator); 32 | } 33 | 34 | /** @test */ 35 | function a_thread_has_replies() 36 | { 37 | $this->assertInstanceOf('Illuminate\Database\Eloquent\Collection', $this->thread->replies); 38 | } 39 | 40 | /** @test */ 41 | function a_thread_can_add_a_reply() 42 | { 43 | $this->thread->addReply([ 44 | 'body' => 'Foobar', 45 | 'user_id' => 1 46 | ]); 47 | 48 | $this->assertCount(1, $this->thread->replies); 49 | } 50 | 51 | /** @test */ 52 | function a_thread_belongs_to_a_channel() 53 | { 54 | $thread = create('App\Thread'); 55 | $this->assertInstanceOf('App\Channel', $thread->channel); 56 | } 57 | 58 | /** @test */ 59 | function a_thread_can_be_subscribed_to() 60 | { 61 | $thread = create('App\Thread'); 62 | $thread->subscribe($userId = 1); 63 | 64 | $numOfSubscriptions = $thread->subscriptions()->where('user_id', $userId)->count(); 65 | 66 | $this->assertEquals(1, $numOfSubscriptions); 67 | 68 | } 69 | 70 | /** @test */ 71 | function a_thread_can_be_unsubscribed_from() 72 | { 73 | $thread = create('App\Thread'); 74 | 75 | $thread->subscribe($userId = 1); 76 | $thread->unsubscribe($userId); 77 | $this->assertCount(0, $thread->subscriptions); 78 | } 79 | 80 | /** @test */ 81 | function it_knows_if_the_authenticated_user_is_subscribed_to_it() 82 | { 83 | $thread = create('App\Thread'); 84 | $this->signIn(); 85 | 86 | $this->assertFalse($thread->isSubscribedTo); 87 | 88 | $thread->subscribe(); 89 | 90 | $this->assertTrue($thread->isSubscribedTo); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /tests/utilities/functions.php: -------------------------------------------------------------------------------- 1 | create($attributes); 6 | } 7 | 8 | function make($class, $attributes = [], $times = null) 9 | { 10 | return factory($class, $times)->make($attributes); 11 | } -------------------------------------------------------------------------------- /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 application. By default, we are compiling the Sass 10 | | file for the application as well as bundling up all the JS files. 11 | | 12 | */ 13 | 14 | mix.js('resources/assets/js/app.js', 'public/js') 15 | .sass('resources/assets/sass/app.scss', 'public/css'); 16 | --------------------------------------------------------------------------------