├── .editorconfig ├── .env.example ├── .gitattributes ├── .gitignore ├── .prittierrc.json ├── .vscode └── settings.json ├── app ├── Author.php ├── BlogPost.php ├── Comment.php ├── Console │ └── Kernel.php ├── Contracts │ └── CounterContract.php ├── Events │ ├── BlogPostPosted.php │ └── CommentPosted.php ├── Exceptions │ └── Handler.php ├── Facades │ └── CounterFacade.php ├── Http │ ├── Controllers │ │ ├── Api │ │ │ └── V1 │ │ │ │ └── PostCommentController.php │ │ ├── Auth │ │ │ ├── ForgotPasswordController.php │ │ │ ├── LoginController.php │ │ │ ├── RegisterController.php │ │ │ ├── ResetPasswordController.php │ │ │ └── VerificationController.php │ │ ├── Controller.php │ │ ├── HomeController.php │ │ ├── PostCommentController.php │ │ ├── PostController.php │ │ ├── PostTagController.php │ │ ├── UserCommentController.php │ │ └── UserController.php │ ├── Kernel.php │ ├── Middleware │ │ ├── Authenticate.php │ │ ├── CheckForMaintenanceMode.php │ │ ├── EncryptCookies.php │ │ ├── LocaleMiddleware.php │ │ ├── RedirectIfAuthenticated.php │ │ ├── TrimStrings.php │ │ ├── TrustProxies.php │ │ └── VerifyCsrfToken.php │ ├── Requests │ │ ├── StoreComment.php │ │ ├── StorePost.php │ │ └── UpdateUser.php │ ├── Resources │ │ ├── Comment.php │ │ └── CommentUser.php │ └── ViewComposers │ │ └── ActivityComposer.php ├── Image.php ├── Jobs │ ├── NotifyUsersPostWasCommented.php │ └── ThrottledMail.php ├── Listeners │ ├── CacheSubscriber.php │ ├── NotifyAdminWhenBlogPostCreated.php │ └── NotifyUsersAboutComment.php ├── Mail │ ├── BlogPostAdded.php │ ├── CommentPosted.php │ ├── CommentPostedMarkdown.php │ └── CommentPostedOnPostWatched.php ├── Observers │ ├── BlogPostObserver.php │ └── CommentObserver.php ├── Policies │ ├── BlogPostPolicy.php │ ├── CommentPolicy.php │ └── UserPolicy.php ├── Profile.php ├── Providers │ ├── AppServiceProvider.php │ ├── AuthServiceProvider.php │ ├── BroadcastServiceProvider.php │ ├── EventServiceProvider.php │ └── RouteServiceProvider.php ├── Scopes │ ├── DeletedAdminScope.php │ └── LatestScope.php ├── Services │ ├── Counter.php │ └── DummyCounter.php ├── Tag.php ├── Traits │ └── Taggable.php └── User.php ├── artisan ├── bootstrap ├── app.php └── cache │ └── .gitignore ├── composer.json ├── composer.lock ├── config ├── app.php ├── auth.php ├── broadcasting.php ├── cache.php ├── database.php ├── filesystems.php ├── hashing.php ├── logging.php ├── mail.php ├── queue.php ├── services.php ├── session.php └── view.php ├── database ├── .gitignore ├── factories │ ├── AuthorFactory.php │ ├── BlogPostFactory.php │ ├── CommentFactory.php │ ├── ProfileFactory.php │ └── UserFactory.php ├── migrations │ ├── 2014_10_12_000000_create_users_table.php │ ├── 2014_10_12_100000_create_password_resets_table.php │ ├── 2019_01_20_161408_create_blogposts_table.php │ ├── 2019_01_20_162238_add_title_content_to_blogposts_table.php │ ├── 2019_01_22_173935_change_blogposts_table_name.php │ ├── 2019_02_25_124726_create_authors_table.php │ ├── 2019_02_25_124736_create_profiles_table.php │ ├── 2019_02_27_160516_create_comments_table.php │ ├── 2019_03_20_181629_add_user_to_blog_posts_table.php │ ├── 2019_04_02_162450_add_cascade_delete_to_comments_table.php │ ├── 2019_04_02_163816_add_soft_deletes_to_blog_posts_table.php │ ├── 2019_04_04_162648_add_soft_deletes_to_comments_table.php │ ├── 2019_04_06_145253_add_is_admin_to_users_table.php │ ├── 2019_04_20_154128_create_tags_table.php │ ├── 2019_04_20_154241_create_blog_post_tag_table.php │ ├── 2019_04_22_111215_add_user_to_comments_table.php │ ├── 2019_04_28_104117_create_images_table.php │ ├── 2019_05_01_114040_add_polymorph_to_images_table.php │ ├── 2019_05_02_180253_add_polymorph_to_comments_table.php │ ├── 2019_05_05_123450_rename_blog_post_tag_table_to_taggables.php │ ├── 2019_05_09_155933_create_jobs_table.php │ ├── 2019_05_09_170210_create_failed_jobs_table.php │ ├── 2019_05_14_141217_add_locale_to_users_table.php │ └── 2019_07_28_093515_add_api_token_to_users_table.php └── seeds │ ├── BlogPostTagTableSeeder.php │ ├── BlogPostsTableSeeder.php │ ├── CommentsTableSeeder.php │ ├── DatabaseSeeder.php │ ├── TagsTableSeeder.php │ └── UsersTableSeeder.php ├── package-lock.json ├── package.json ├── phpunit.xml ├── public ├── .htaccess ├── favicon.ico ├── index.php ├── mix-manifest.json ├── robots.txt ├── svg │ ├── 403.svg │ ├── 404.svg │ ├── 500.svg │ └── 503.svg └── web.config ├── readme.md ├── resources ├── js │ ├── app.js │ ├── bootstrap.js │ └── components │ │ └── ExampleComponent.vue ├── lang │ ├── de.json │ ├── de │ │ ├── .gitkeep │ │ └── messages.php │ ├── en.json │ ├── en │ │ ├── auth.php │ │ ├── messages.php │ │ ├── pagination.php │ │ ├── passwords.php │ │ └── validation.php │ ├── es.json │ └── es │ │ ├── .gitkeep │ │ └── messages.php ├── sass │ ├── _variables.scss │ └── app.scss └── views │ ├── auth │ ├── login.blade.php │ └── register.blade.php │ ├── components │ ├── badge.blade.php │ ├── card.blade.php │ ├── comment-form.blade.php │ ├── comment-list.blade.php │ ├── errors.blade.php │ ├── tags.blade.php │ └── updated.blade.php │ ├── contact.blade.php │ ├── emails │ └── posts │ │ ├── blog-post-added.blade.php │ │ ├── comment-posted-on-watched.blade.php │ │ ├── commented-markdown.blade.php │ │ └── commented.blade.php │ ├── home.blade.php │ ├── layout.blade.php │ ├── posts │ ├── _activity.blade.php │ ├── _form.blade.php │ ├── create.blade.php │ ├── edit.blade.php │ ├── index.blade.php │ └── show.blade.php │ ├── secret.blade.php │ ├── users │ ├── edit.blade.php │ └── show.blade.php │ └── vendor │ └── mail │ ├── html │ ├── button.blade.php │ ├── footer.blade.php │ ├── header.blade.php │ ├── layout.blade.php │ ├── message.blade.php │ ├── panel.blade.php │ ├── promotion.blade.php │ ├── promotion │ │ └── button.blade.php │ ├── subcopy.blade.php │ ├── table.blade.php │ └── themes │ │ └── default.css │ └── markdown │ ├── button.blade.php │ ├── footer.blade.php │ ├── header.blade.php │ ├── layout.blade.php │ ├── message.blade.php │ ├── panel.blade.php │ ├── promotion.blade.php │ ├── promotion │ └── button.blade.php │ ├── subcopy.blade.php │ └── table.blade.php ├── routes ├── api.php ├── channels.php ├── console.php └── web.php ├── server.php ├── storage ├── app │ ├── .gitignore │ └── public │ │ └── .gitignore ├── debugbar │ └── .gitignore ├── framework │ ├── .gitignore │ ├── cache │ │ ├── .gitignore │ │ └── data │ │ │ └── .gitignore │ ├── sessions │ │ └── .gitignore │ ├── testing │ │ └── .gitignore │ └── views │ │ └── .gitignore └── logs │ └── .gitignore ├── tests ├── CreatesApplication.php ├── Feature │ ├── ApiPostCommentsTest.php │ ├── ExampleTest.php │ ├── HomeTest.php │ └── PostTest.php ├── TestCase.php └── Unit │ └── ExampleTest.php ├── webpack.mix.js └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | insert_final_newline = true 7 | indent_style = space 8 | indent_size = 4 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | 14 | [*.yml] 15 | indent_size = 2 16 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | APP_DEBUG=true 5 | APP_URL=http://localhost 6 | 7 | LOG_CHANNEL=stack 8 | 9 | DB_CONNECTION=mysql 10 | DB_HOST=127.0.0.1 11 | DB_PORT=3306 12 | DB_DATABASE=homestead 13 | DB_USERNAME=homestead 14 | DB_PASSWORD=secret 15 | 16 | BROADCAST_DRIVER=log 17 | CACHE_DRIVER=file 18 | QUEUE_CONNECTION=sync 19 | SESSION_DRIVER=file 20 | SESSION_LIFETIME=120 21 | 22 | REDIS_HOST=127.0.0.1 23 | REDIS_PASSWORD=null 24 | REDIS_PORT=6379 25 | 26 | MAIL_DRIVER=smtp 27 | MAIL_HOST=smtp.mailtrap.io 28 | MAIL_PORT=2525 29 | MAIL_USERNAME=null 30 | MAIL_PASSWORD=null 31 | MAIL_ENCRYPTION=null 32 | 33 | PUSHER_APP_ID= 34 | PUSHER_APP_KEY= 35 | PUSHER_APP_SECRET= 36 | PUSHER_APP_CLUSTER=mt1 37 | 38 | MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" 39 | MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" 40 | -------------------------------------------------------------------------------- /.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 | /public/js 5 | /public/css 6 | /public/fonts 7 | /storage/*.key 8 | /vendor 9 | .env 10 | .phpunit.result.cache 11 | Homestead.json 12 | Homestead.yaml 13 | npm-debug.log 14 | yarn-error.log 15 | .idea/ -------------------------------------------------------------------------------- /.prittierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "tabWidth": 4, 3 | "semi": true, 4 | "singleQuote": false 5 | } 6 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.fontFamily": "FiraCode-Retina, Monaco, 'Courier New', monospace", 3 | "editor.fontLigatures": true 4 | } -------------------------------------------------------------------------------- /app/Author.php: -------------------------------------------------------------------------------- 1 | hasOne('App\Profile'); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/BlogPost.php: -------------------------------------------------------------------------------- 1 | morphMany('App\Comment', 'commentable')->latest(); 23 | } 24 | 25 | public function user() 26 | { 27 | return $this->belongsTo('App\User'); 28 | } 29 | 30 | public function image() 31 | { 32 | return $this->morphOne('App\Image', 'imageable'); 33 | } 34 | 35 | public function scopeLatest(Builder $query) 36 | { 37 | return $query->orderBy(static::CREATED_AT, 'desc'); 38 | } 39 | 40 | public function scopeMostCommented(Builder $query) 41 | { 42 | // comments_count 43 | return $query->withCount('comments')->orderBy('comments_count', 'desc'); 44 | } 45 | 46 | public function scopeLatestWithRelations(Builder $query) 47 | { 48 | return $query->latest() 49 | ->withCount('comments') 50 | ->with('user') 51 | ->with('tags'); 52 | } 53 | 54 | public static function boot() 55 | { 56 | static::addGlobalScope(new DeletedAdminScope); 57 | parent::boot(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /app/Comment.php: -------------------------------------------------------------------------------- 1 | morphTo(); 21 | } 22 | 23 | public function user() 24 | { 25 | return $this->belongsTo('App\User'); 26 | } 27 | 28 | public function scopeLatest(Builder $query) 29 | { 30 | return $query->orderBy(static::CREATED_AT, 'desc'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Console/Kernel.php: -------------------------------------------------------------------------------- 1 | command('inspire') 28 | // ->hourly(); 29 | } 30 | 31 | /** 32 | * Register the commands for the application. 33 | * 34 | * @return void 35 | */ 36 | protected function commands() 37 | { 38 | $this->load(__DIR__.'/Commands'); 39 | 40 | require base_path('routes/console.php'); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/Contracts/CounterContract.php: -------------------------------------------------------------------------------- 1 | blogPost = $blogPost; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/Events/CommentPosted.php: -------------------------------------------------------------------------------- 1 | comment = $comment; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/Exceptions/Handler.php: -------------------------------------------------------------------------------- 1 | expectsJson() && $exception instanceof ModelNotFoundException) { 53 | return Route::respondWithRoute('api.fallback'); 54 | } 55 | 56 | if ($request->expectsJson() && $exception instanceof AuthorizationException) { 57 | return response()->json(['message' => $exception->getMessage()], 403); 58 | } 59 | 60 | return parent::render($request, $exception); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/Facades/CounterFacade.php: -------------------------------------------------------------------------------- 1 | middleware('auth:api')->only(['store', 'update', 'destroy']); 18 | } 19 | 20 | /** 21 | * Display a listing of the resource. 22 | * 23 | * @return \Illuminate\Http\Response 24 | */ 25 | public function index(BlogPost $post, Request $request) 26 | { 27 | $perPage = $request->input('per_page') ?? 15; 28 | return CommentResource::collection( 29 | $post->comments()->with('user')->paginate($perPage)->appends( 30 | [ 31 | 'per_page' => $perPage 32 | ] 33 | ) 34 | ); 35 | } 36 | 37 | /** 38 | * Store a newly created resource in storage. 39 | * 40 | * @param \Illuminate\Http\Request $request 41 | * @return \Illuminate\Http\Response 42 | */ 43 | public function store(BlogPost $post, StoreComment $request) 44 | { 45 | $comment = $post->comments()->create([ 46 | 'content' => $request->input('content'), 47 | 'user_id' => $request->user()->id 48 | ]); 49 | event(new CommentPosted($comment)); 50 | 51 | return new CommentResource($comment); 52 | } 53 | 54 | /** 55 | * Display the specified resource. 56 | * 57 | * @param int $id 58 | * @return \Illuminate\Http\Response 59 | */ 60 | public function show(BlogPost $post, Comment $comment) 61 | { 62 | return new CommentResource($comment); 63 | } 64 | 65 | /** 66 | * Update the specified resource in storage. 67 | * 68 | * @param \Illuminate\Http\Request $request 69 | * @param int $id 70 | * @return \Illuminate\Http\Response 71 | */ 72 | public function update(BlogPost $post, Comment $comment, StoreComment $request) 73 | { 74 | $this->authorize($comment); 75 | $comment->content = $request->input('content'); 76 | $comment->save(); 77 | 78 | return new CommentResource($comment); 79 | } 80 | 81 | /** 82 | * Remove the specified resource from storage. 83 | * 84 | * @param int $id 85 | * @return \Illuminate\Http\Response 86 | */ 87 | public function destroy(BlogPost $post, Comment $comment) 88 | { 89 | $this->authorize($comment); 90 | $comment->delete(); 91 | 92 | return response()->noContent(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /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 | // public function username() 41 | // { 42 | // return 'username'; 43 | // } 44 | } 45 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/RegisterController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 41 | } 42 | 43 | /** 44 | * Get a validator for an incoming registration request. 45 | * 46 | * @param array $data 47 | * @return \Illuminate\Contracts\Validation\Validator 48 | */ 49 | protected function validator(array $data) 50 | { 51 | return Validator::make($data, [ 52 | 'name' => ['required', 'string', 'max:255'], 53 | 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], 54 | 'password' => ['required', 'string', 'min:6', 'confirmed'], 55 | ]); 56 | } 57 | 58 | /** 59 | * Create a new user instance after a valid registration. 60 | * 61 | * @param array $data 62 | * @return \App\User 63 | */ 64 | protected function create(array $data) 65 | { 66 | return User::create([ 67 | 'name' => $data['name'], 68 | 'email' => $data['email'], 69 | 'password' => Hash::make($data['password']), 70 | ]); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ResetPasswordController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/VerificationController.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 38 | $this->middleware('signed')->only('verify'); 39 | $this->middleware('throttle:6,1')->only('verify', 'resend'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | middleware('auth')->only(['store']); 15 | } 16 | 17 | public function index(BlogPost $post) 18 | { 19 | // dump(is_array($post->comments)); 20 | // dump(get_class($post->comments)); 21 | // die; 22 | return CommentResource::collection($post->comments()->with('user')->get()); 23 | // return $post->comments()->with('user')->get(); 24 | } 25 | 26 | public function store(BlogPost $post, StoreComment $request) 27 | { 28 | $comment = $post->comments()->create([ 29 | 'content' => $request->input('content'), 30 | 'user_id' => $request->user()->id 31 | ]); 32 | event(new CommentPosted($comment)); 33 | 34 | return redirect()->back() 35 | ->withStatus('Comment was created!'); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/Http/Controllers/PostTagController.php: -------------------------------------------------------------------------------- 1 | $tag->blogPosts() 16 | ->latestWithRelations() 17 | ->get(), 18 | ]); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/Http/Controllers/UserCommentController.php: -------------------------------------------------------------------------------- 1 | middleware('auth')->only(['store']); 13 | } 14 | 15 | public function store(User $user, StoreComment $request) 16 | { 17 | $user->commentsOn()->create([ 18 | 'content' => $request->input('content'), 19 | 'user_id' => $request->user()->id 20 | ]); 21 | 22 | return redirect()->back() 23 | ->withStatus('Comment was created!'); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/Http/Controllers/UserController.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 16 | $this->authorizeResource(User::class, 'user'); 17 | } 18 | 19 | /** 20 | * Display a listing of the resource. 21 | * 22 | * @return \Illuminate\Http\Response 23 | */ 24 | public function index() 25 | { 26 | // 27 | } 28 | 29 | /** 30 | * Show the form for creating a new resource. 31 | * 32 | * @return \Illuminate\Http\Response 33 | */ 34 | public function create() 35 | { 36 | // 37 | } 38 | 39 | /** 40 | * Store a newly created resource in storage. 41 | * 42 | * @param \Illuminate\Http\Request $request 43 | * @return \Illuminate\Http\Response 44 | */ 45 | public function store(Request $request) 46 | { 47 | // 48 | } 49 | 50 | /** 51 | * Display the specified resource. 52 | * 53 | * @param \App\User $user 54 | * @return \Illuminate\Http\Response 55 | */ 56 | public function show(User $user) 57 | { 58 | return view('users.show', [ 59 | 'user' => $user, 60 | 'counter' => CounterFacade::increment("user-{$user->id}") 61 | ]); 62 | } 63 | 64 | /** 65 | * Show the form for editing the specified resource. 66 | * 67 | * @param \App\User $user 68 | * @return \Illuminate\Http\Response 69 | */ 70 | public function edit(User $user) 71 | { 72 | return view('users.edit', ['user' => $user]); 73 | } 74 | 75 | /** 76 | * Update the specified resource in storage. 77 | * 78 | * @param \Illuminate\Http\Request $request 79 | * @param \App\User $user 80 | * @return \Illuminate\Http\Response 81 | */ 82 | public function update(UpdateUser $request, User $user) 83 | { 84 | if ($request->hasFile('avatar')) { 85 | $path = $request->file('avatar')->store('avatars'); 86 | 87 | if ($user->image) { 88 | $user->image->path = $path; 89 | $user->image->save(); 90 | } else { 91 | $user->image()->save( 92 | Image::make(['path' => $path]) 93 | ); 94 | } 95 | } 96 | 97 | $user->locale = $request->get('locale'); 98 | $user->save(); 99 | 100 | return redirect() 101 | ->back() 102 | ->withStatus('Profile was updated!'); 103 | } 104 | 105 | /** 106 | * Remove the specified resource from storage. 107 | * 108 | * @param \App\User $user 109 | * @return \Illuminate\Http\Response 110 | */ 111 | public function destroy(User $user) 112 | { 113 | // 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /app/Http/Kernel.php: -------------------------------------------------------------------------------- 1 | [ 31 | \App\Http\Middleware\EncryptCookies::class, 32 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 33 | \Illuminate\Session\Middleware\StartSession::class, 34 | // \Illuminate\Session\Middleware\AuthenticateSession::class, 35 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, 36 | \App\Http\Middleware\VerifyCsrfToken::class, 37 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 38 | \App\Http\Middleware\LocaleMiddleware::class 39 | ], 40 | 41 | 'api' => [ 42 | 'throttle:60,1', 43 | 'bindings', 44 | ], 45 | ]; 46 | 47 | /** 48 | * The application's route middleware. 49 | * 50 | * These middleware may be assigned to groups or used individually. 51 | * 52 | * @var array 53 | */ 54 | protected $routeMiddleware = [ 55 | 'auth' => \App\Http\Middleware\Authenticate::class, 56 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 57 | 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 58 | 'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class, 59 | 'can' => \Illuminate\Auth\Middleware\Authorize::class, 60 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 61 | 'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class, 62 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 63 | 'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class, 64 | 'locale' => \App\Http\Middleware\LocaleMiddleware::class 65 | ]; 66 | 67 | /** 68 | * The priority-sorted list of middleware. 69 | * 70 | * This forces non-global middleware to always be in the given order. 71 | * 72 | * @var array 73 | */ 74 | protected $middlewarePriority = [ 75 | \Illuminate\Session\Middleware\StartSession::class, 76 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, 77 | \App\Http\Middleware\Authenticate::class, 78 | \Illuminate\Session\Middleware\AuthenticateSession::class, 79 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 80 | \Illuminate\Auth\Middleware\Authorize::class, 81 | ]; 82 | } 83 | -------------------------------------------------------------------------------- /app/Http/Middleware/Authenticate.php: -------------------------------------------------------------------------------- 1 | expectsJson()) { 18 | return route('login'); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/Http/Middleware/CheckForMaintenanceMode.php: -------------------------------------------------------------------------------- 1 | user()->locale; 25 | Session::put('locale', $locale); 26 | } 27 | 28 | if ($request->has('locale')) { 29 | $locale = $request->get('locale'); 30 | Session::put('locale', $locale); 31 | } 32 | 33 | $locale = Session::get('locale'); 34 | 35 | if (null === $locale) { 36 | $locale = config('app.fallback_locale'); 37 | } 38 | 39 | App::setLocale($locale); 40 | 41 | return $next($request); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/Http/Middleware/RedirectIfAuthenticated.php: -------------------------------------------------------------------------------- 1 | check()) { 21 | return redirect('/'); 22 | } 23 | 24 | return $next($request); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrimStrings.php: -------------------------------------------------------------------------------- 1 | 'required|min:5' 28 | ]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Http/Requests/StorePost.php: -------------------------------------------------------------------------------- 1 | 'bail|min:5|required|max:100', 28 | 'content' => 'required|min:10', 29 | 'thumbnail' => 'image|mimes:jpg,jpeg,png,gif,svg|max:1024|dimensions:min_height=500' 30 | ]; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Http/Requests/UpdateUser.php: -------------------------------------------------------------------------------- 1 | 'image|mimes:jpg,jpeg,png,gif,svg|max:1024|dimensions:width=128,height=128', 30 | 'locale' => [ 31 | 'required', 32 | Rule::in(array_keys(User::LOCALES)) 33 | ] 34 | ]; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/Http/Resources/Comment.php: -------------------------------------------------------------------------------- 1 | $this->id, 20 | 'content' => $this->content, 21 | 'created_at' => (string)$this->created_at, 22 | 'updated_at' => (string)$this->updated_at, 23 | 'user' => new CommentUserResource($this->whenLoaded('user')) 24 | ]; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/Http/Resources/CommentUser.php: -------------------------------------------------------------------------------- 1 | $this->id, 20 | 'name' => $this->name, 21 | 'email' => $this->when(false, $this->email) 22 | ]; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/Http/ViewComposers/ActivityComposer.php: -------------------------------------------------------------------------------- 1 | remember('mostCommented', 60, function() { 15 | return BlogPost::mostCommented()->take(5)->get(); 16 | }); 17 | 18 | $mostActive = Cache::remember('mostActive', 60, function() { 19 | return User::withMostBlogPosts()->take(5)->get(); 20 | }); 21 | 22 | $mostActiveLastMonth = Cache::remember('mostActiveLastMonth', 60, function() { 23 | return User::withMostBlogPostsLastMonth()->take(5)->get(); 24 | }); 25 | 26 | $view->with('mostCommented', $mostCommented); 27 | $view->with('mostActive', $mostActive); 28 | $view->with('mostActiveLastMonth', $mostActiveLastMonth); 29 | } 30 | } -------------------------------------------------------------------------------- /app/Image.php: -------------------------------------------------------------------------------- 1 | morphTo(); 15 | } 16 | 17 | public function url() 18 | { 19 | return Storage::url($this->path); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/Jobs/NotifyUsersPostWasCommented.php: -------------------------------------------------------------------------------- 1 | comment = $comment; 28 | } 29 | 30 | /** 31 | * Execute the job. 32 | * 33 | * @return void 34 | */ 35 | public function handle() 36 | { 37 | User::thatHasCommentedOnPost($this->comment->commentable) 38 | ->get() 39 | ->filter(function (User $user) { 40 | return $user->id !== $this->comment->user_id; 41 | })->map(function (User $user) { 42 | ThrottledMail::dispatch( 43 | new CommentPostedOnPostWatched($this->comment, $user), 44 | $user 45 | ); 46 | }); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/Jobs/ThrottledMail.php: -------------------------------------------------------------------------------- 1 | mail = $mail; 33 | $this->user = $user; 34 | } 35 | 36 | /** 37 | * Execute the job. 38 | * 39 | * @return void 40 | */ 41 | public function handle() 42 | { 43 | Redis::throttle('mailtrap')->allow(2)->every(12)->then(function () { 44 | Mail::to($this->user)->send($this->mail); 45 | }, function () { 46 | return $this->release(5); 47 | }); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/Listeners/CacheSubscriber.php: -------------------------------------------------------------------------------- 1 | key} cache hit"); 14 | } 15 | 16 | public function handleCacheMissed(CacheMissed $event) 17 | { 18 | Log::info("{$event->key} cache miss"); 19 | } 20 | 21 | public function subscribe($events) 22 | { 23 | $events->listen( 24 | CacheHit::class, 25 | 'App\Listeners\CacheSubscriber@handleCacheHit' 26 | ); 27 | 28 | $events->listen( 29 | CacheMissed::class, 30 | 'App\Listeners\CacheSubscriber@handleCacheMissed' 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/Listeners/NotifyAdminWhenBlogPostCreated.php: -------------------------------------------------------------------------------- 1 | get() 23 | ->map(function (User $user) { 24 | ThrottledMail::dispatch( 25 | new BlogPostAdded(), 26 | $user 27 | ); 28 | }); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Listeners/NotifyUsersAboutComment.php: -------------------------------------------------------------------------------- 1 | comment), 25 | $event->comment->commentable->user 26 | )->onQueue('low'); 27 | NotifyUsersPostWasCommented::dispatch($event->comment) 28 | ->onQueue('high'); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Mail/BlogPostAdded.php: -------------------------------------------------------------------------------- 1 | markdown('emails.posts.blog-post-added'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/Mail/CommentPosted.php: -------------------------------------------------------------------------------- 1 | comment = $comment; 26 | } 27 | 28 | /** 29 | * Build the message. 30 | * 31 | * @return $this 32 | */ 33 | public function build() 34 | { 35 | $subject = "Commented was posted on your {$this->comment->commentable->title} blog post"; 36 | return $this 37 | // First example with full path 38 | // ->attach( 39 | // storage_path('app/public') . '/' . $this->comment->user->image->path, 40 | // [ 41 | // 'as' => 'profile_picture.jpeg', 42 | // 'mime' => 'image/jpeg' 43 | // ] 44 | // ) 45 | // ->attachFromStorage($this->comment->user->image->path, 'profile_picture.jpeg') 46 | // ->attachFromStorageDisk('public', $this->comment->user->image->path) 47 | // ->attachData(Storage::get($this->comment->user->image->path), 'profile_picture_from_data.jpeg', [ 48 | // 'mime' => 'image/jpeg' 49 | // ]) 50 | ->subject($subject) 51 | ->view('emails.posts.commented'); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/Mail/CommentPostedMarkdown.php: -------------------------------------------------------------------------------- 1 | comment = $comment; 25 | } 26 | 27 | /** 28 | * Build the message. 29 | * 30 | * @return $this 31 | */ 32 | public function build() 33 | { 34 | $subject = "Commented was posted on your {$this->comment->commentable->title} blog post"; 35 | return $this->subject($subject) 36 | ->markdown('emails.posts.commented-markdown'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/Mail/CommentPostedOnPostWatched.php: -------------------------------------------------------------------------------- 1 | comment = $comment; 27 | $this->user = $user; 28 | } 29 | 30 | /** 31 | * Build the message. 32 | * 33 | * @return $this 34 | */ 35 | public function build() 36 | { 37 | return $this->markdown('emails.posts.comment-posted-on-watched'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/Observers/BlogPostObserver.php: -------------------------------------------------------------------------------- 1 | forget("blog-post-{$blogPost->id}"); 13 | } 14 | 15 | public function deleting(BlogPost $blogPost) 16 | { 17 | // dd("I'm deleted"); 18 | $blogPost->comments()->delete(); 19 | Cache::tags(['blog-post'])->forget("blog-post-{$blogPost->id}"); 20 | } 21 | 22 | public function restoring(BlogPost $blogPost) 23 | { 24 | $blogPost->comments()->restore(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/Observers/CommentObserver.php: -------------------------------------------------------------------------------- 1 | commentable_type === BlogPost::class) { 20 | // dd("I'm created"); 21 | Cache::tags(['blog-post'])->forget("blog-post-{$comment->commentable_id}"); 22 | Cache::tags(['blog-post'])->forget('mostCommented'); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/Policies/BlogPostPolicy.php: -------------------------------------------------------------------------------- 1 | id == $blogPost->user_id; 46 | } 47 | 48 | /** 49 | * Determine whether the user can delete the blog post. 50 | * 51 | * @param \App\User $user 52 | * @param \App\BlogPost $blogPost 53 | * @return mixed 54 | */ 55 | public function delete(User $user, BlogPost $blogPost) 56 | { 57 | return $user->id == $blogPost->user_id; 58 | } 59 | 60 | /** 61 | * Determine whether the user can restore the blog post. 62 | * 63 | * @param \App\User $user 64 | * @param \App\BlogPost $blogPost 65 | * @return mixed 66 | */ 67 | public function restore(User $user, BlogPost $blogPost) 68 | { 69 | // 70 | } 71 | 72 | /** 73 | * Determine whether the user can permanently delete the blog post. 74 | * 75 | * @param \App\User $user 76 | * @param \App\BlogPost $blogPost 77 | * @return mixed 78 | */ 79 | public function forceDelete(User $user, BlogPost $blogPost) 80 | { 81 | // 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/Policies/CommentPolicy.php: -------------------------------------------------------------------------------- 1 | user_id === $user->id; 46 | } 47 | 48 | /** 49 | * Determine whether the user can delete the comment. 50 | * 51 | * @param \App\User $user 52 | * @param \App\Comment $comment 53 | * @return mixed 54 | */ 55 | public function delete(User $user, Comment $comment) 56 | { 57 | return $comment->user_id === $user->id; 58 | } 59 | 60 | /** 61 | * Determine whether the user can restore the comment. 62 | * 63 | * @param \App\User $user 64 | * @param \App\Comment $comment 65 | * @return mixed 66 | */ 67 | public function restore(User $user, Comment $comment) 68 | { 69 | return false; 70 | } 71 | 72 | /** 73 | * Determine whether the user can permanently delete the comment. 74 | * 75 | * @param \App\User $user 76 | * @param \App\Comment $comment 77 | * @return mixed 78 | */ 79 | public function forceDelete(User $user, Comment $comment) 80 | { 81 | return false; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/Policies/UserPolicy.php: -------------------------------------------------------------------------------- 1 | id == $model->id; 45 | } 46 | 47 | /** 48 | * Determine whether the user can delete the model. 49 | * 50 | * @param \App\User $user 51 | * @param \App\User $model 52 | * @return mixed 53 | */ 54 | public function delete(User $user, User $model) 55 | { 56 | return false; 57 | } 58 | 59 | /** 60 | * Determine whether the user can restore the model. 61 | * 62 | * @param \App\User $user 63 | * @param \App\User $model 64 | * @return mixed 65 | */ 66 | public function restore(User $user, User $model) 67 | { 68 | return false; 69 | } 70 | 71 | /** 72 | * Determine whether the user can permanently delete the model. 73 | * 74 | * @param \App\User $user 75 | * @param \App\User $model 76 | * @return mixed 77 | */ 78 | public function forceDelete(User $user, User $model) 79 | { 80 | return false; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/Profile.php: -------------------------------------------------------------------------------- 1 | belongsTo('App\Author'); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | composer('*', ActivityComposer::class); 37 | view()->composer(['posts.index', 'posts.show'], ActivityComposer::class); 38 | 39 | BlogPost::observe(BlogPostObserver::class); 40 | Comment::observe(CommentObserver::class); 41 | 42 | $this->app->singleton(Counter::class, function ($app) { 43 | return new Counter( 44 | $app->make('Illuminate\Contracts\Cache\Factory'), 45 | $app->make('Illuminate\Contracts\Session\Session'), 46 | env('COUNTER_TIMEOUT') 47 | ); 48 | }); 49 | 50 | $this->app->bind( 51 | 'App\Contracts\CounterContract', 52 | Counter::class 53 | ); 54 | 55 | // CommentResource::withoutWrapping(); 56 | Resource::withoutWrapping(); 57 | 58 | // $this->app->bind( 59 | // 'App\Contracts\CounterContract', 60 | // DummyCounter::class 61 | // ); 62 | 63 | // $this->app->when(Counter::class) 64 | // ->needs('$timeout') 65 | // ->give(env('COUNTER_TIMEOUT')); 66 | } 67 | 68 | /** 69 | * Register any application services. 70 | * 71 | * @return void 72 | */ 73 | public function register() 74 | { 75 | // 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /app/Providers/AuthServiceProvider.php: -------------------------------------------------------------------------------- 1 | 'App\Policies\ModelPolicy', 17 | 'App\BlogPost' => 'App\Policies\BlogPostPolicy', 18 | 'App\User' => 'App\Policies\UserPolicy', 19 | 'App\Comment' => 'App\Policies\CommentPolicy' 20 | ]; 21 | 22 | /** 23 | * Register any authentication / authorization services. 24 | * 25 | * @return void 26 | */ 27 | public function boot() 28 | { 29 | $this->registerPolicies(); 30 | 31 | Gate::define('home.secret', function ($user) { 32 | return $user->is_admin; 33 | }); 34 | 35 | // Gate::define('update-post', function ($user, $post) { 36 | // return $user->id == $post->user_id; 37 | // }); 38 | // Gate::allows('update-post', $post); 39 | // $this->authorize('update-post',) 40 | 41 | // Gate::define('delete-post', function ($user, $post) { 42 | // return $user->id == $post->user_id; 43 | // }); 44 | 45 | // Gate::define('posts.update', 'App\Policies\BlogPostPolicy@update'); 46 | // Gate::define('posts.delete', 'App\Policies\BlogPostPolicy@delete'); 47 | 48 | // Gate::resource('posts', 'App\Policies\BlogPostPolicy'); 49 | // posts.create, posts.view, posts.update, posts.delete 50 | // comments.create, comments.update etc. 51 | 52 | Gate::before(function ($user, $ability) { 53 | if ($user->is_admin && in_array($ability, ['update', 'delete'])) { 54 | return true; 55 | } 56 | }); 57 | 58 | // Gate::after(function ($user, $ability, $result) { 59 | // if ($user->is_admin) { 60 | // return true; 61 | // } 62 | // }); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /app/Providers/BroadcastServiceProvider.php: -------------------------------------------------------------------------------- 1 | [ 24 | SendEmailVerificationNotification::class, 25 | ], 26 | CommentPosted::class => [ 27 | NotifyUsersAboutComment::class 28 | ], 29 | BlogPostPosted::class => [ 30 | NotifyAdminWhenBlogPostCreated::class 31 | ] 32 | ]; 33 | 34 | protected $subscribe = [ 35 | CacheSubscriber::class 36 | ]; 37 | 38 | /** 39 | * Register any events for your application. 40 | * 41 | * @return void 42 | */ 43 | public function boot() 44 | { 45 | parent::boot(); 46 | 47 | // 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /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/Scopes/DeletedAdminScope.php: -------------------------------------------------------------------------------- 1 | is_admin) { 15 | $builder->withTrashed(); 16 | // $builder->withoutGlobalScope('Illuminate\Database\Eloquent\SoftDeletingScope'); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/Scopes/LatestScope.php: -------------------------------------------------------------------------------- 1 | orderBy($model::CREATED_AT, 'desc'); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/Services/Counter.php: -------------------------------------------------------------------------------- 1 | cache = $cache; 19 | $this->timeout = $timeout; 20 | $this->session = $session; 21 | $this->supportsTags = method_exists($cache, 'tags'); 22 | } 23 | 24 | public function increment(string $key, array $tags = null): int 25 | { 26 | $sessionId = $this->session->getId(); 27 | $counterKey = "{$key}-counter"; 28 | $usersKey = "{$key}-users"; 29 | 30 | $cache = $this->supportsTags && null !== $tags 31 | ? $this->cache->tags($tags) : $this->cache; 32 | 33 | $users = $cache->get($usersKey, []); 34 | $usersUpdate = []; 35 | $diffrence = 0; 36 | $now = now(); 37 | 38 | foreach ($users as $session => $lastVisit) { 39 | if ($now->diffInMinutes($lastVisit) >= $this->timeout) { 40 | $diffrence--; 41 | } else { 42 | $usersUpdate[$session] = $lastVisit; 43 | } 44 | } 45 | 46 | if( 47 | !array_key_exists($sessionId, $users) 48 | || $now->diffInMinutes($users[$sessionId]) >= $this->timeout 49 | ) { 50 | $diffrence++; 51 | } 52 | 53 | $usersUpdate[$sessionId] = $now; 54 | $cache->forever($usersKey, $usersUpdate); 55 | 56 | if (!$cache->has($counterKey)) { 57 | $cache->forever($counterKey, 1); 58 | } else { 59 | $cache->increment($counterKey, $diffrence); 60 | } 61 | 62 | $counter = $cache->get($counterKey); 63 | 64 | return $counter; 65 | } 66 | } -------------------------------------------------------------------------------- /app/Services/DummyCounter.php: -------------------------------------------------------------------------------- 1 | morphedByMany('App\BlogPost', 'taggable')->withTimestamps()->as('tagged'); 12 | } 13 | 14 | public function comments() 15 | { 16 | return $this->morphedByMany('App\Comment', 'taggable')->withTimestamps()->as('tagged'); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/Traits/Taggable.php: -------------------------------------------------------------------------------- 1 | tags()->sync(static::findTagsInContent($model->content)); 12 | }); 13 | 14 | static::created(function ($model) { 15 | $model->tags()->sync(static::findTagsInContent($model->content)); 16 | }); 17 | } 18 | 19 | public function tags() 20 | { 21 | return $this->morphToMany('App\Tag', 'taggable')->withTimestamps(); 22 | } 23 | 24 | private static function findTagsInContent($content) 25 | { 26 | preg_match_all('/@([^@]+)@/m', $content, $tags); 27 | 28 | return Tag::whereIn('name', $tags[1] ?? [])->get(); 29 | } 30 | } -------------------------------------------------------------------------------- /app/User.php: -------------------------------------------------------------------------------- 1 | 'English', 15 | 'es' => 'Español', 16 | 'de' => 'Deutsch' 17 | ]; 18 | 19 | /** 20 | * The attributes that are mass assignable. 21 | * 22 | * @var array 23 | */ 24 | protected $fillable = [ 25 | 'name', 'email', 'password', 26 | ]; 27 | 28 | /** 29 | * The attributes that should be hidden for arrays. 30 | * 31 | * @var array 32 | */ 33 | protected $hidden = [ 34 | 'password', 'remember_token', 'email', 'email_verified_at', 'created_at', 'updated_at', 'is_admin', 35 | 'locale' 36 | ]; 37 | 38 | public function blogPosts() 39 | { 40 | return $this->hasMany('App\BlogPost'); 41 | } 42 | 43 | public function comments() 44 | { 45 | return $this->hasMany('App\Comment'); 46 | } 47 | 48 | public function commentsOn() 49 | { 50 | return $this->morphMany('App\Comment', 'commentable')->latest(); 51 | } 52 | 53 | public function image() 54 | { 55 | return $this->morphOne('App\Image', 'imageable'); 56 | } 57 | 58 | public function scopeWithMostBlogPosts(Builder $query) 59 | { 60 | return $query->withCount('blogPosts')->orderBy('blog_posts_count', 'desc'); 61 | } 62 | 63 | public function scopeWithMostBlogPostsLastMonth(Builder $query) 64 | { 65 | return $query->withCount(['blogPosts' => function (Builder $query) { 66 | $query->whereBetween(static::CREATED_AT, [now()->subMonths(1), now()]); 67 | }])->has('blogPosts', '>=', 2) 68 | ->orderBy('blog_posts_count', 'desc'); 69 | } 70 | 71 | public function scopeThatHasCommentedOnPost(Builder $query, BlogPost $post) 72 | { 73 | return $query->whereHas('comments', function ($query) use ($post) { 74 | return $query->where('commentable_id', '=', $post->id) 75 | ->where('commentable_type', '=', BlogPost::class); 76 | }); 77 | } 78 | 79 | public function scopeThatIsAnAdmin(Builder $query) 80 | { 81 | return $query->where('is_admin', true); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /artisan: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | make(Illuminate\Contracts\Console\Kernel::class); 34 | 35 | $status = $kernel->handle( 36 | $input = new Symfony\Component\Console\Input\ArgvInput, 37 | new Symfony\Component\Console\Output\ConsoleOutput 38 | ); 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Shutdown The Application 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Once Artisan has finished running, we will fire off the shutdown events 46 | | so that any final work may be done by the application before we shut 47 | | down the process. This is the last thing to happen to the request. 48 | | 49 | */ 50 | 51 | $kernel->terminate($input, $status); 52 | 53 | exit($status); 54 | -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | singleton( 30 | Illuminate\Contracts\Http\Kernel::class, 31 | App\Http\Kernel::class 32 | ); 33 | 34 | $app->singleton( 35 | Illuminate\Contracts\Console\Kernel::class, 36 | App\Console\Kernel::class 37 | ); 38 | 39 | $app->singleton( 40 | Illuminate\Contracts\Debug\ExceptionHandler::class, 41 | App\Exceptions\Handler::class 42 | ); 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Return The Application 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This script returns the application instance. The instance is given to 50 | | the calling script so we can separate the building of the instances 51 | | from the actual running of the application and sending responses. 52 | | 53 | */ 54 | 55 | return $app; 56 | -------------------------------------------------------------------------------- /bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel/laravel", 3 | "type": "project", 4 | "description": "The Laravel Framework.", 5 | "keywords": [ 6 | "framework", 7 | "laravel" 8 | ], 9 | "license": "MIT", 10 | "require": { 11 | "php": "^7.1.3", 12 | "fideloper/proxy": "^4.0", 13 | "laravel/framework": "5.7.*", 14 | "laravel/tinker": "^1.0", 15 | "predis/predis": "^1.1" 16 | }, 17 | "require-dev": { 18 | "barryvdh/laravel-debugbar": "^3.2", 19 | "beyondcode/laravel-dump-server": "^1.0", 20 | "filp/whoops": "^2.0", 21 | "fzaninotto/faker": "^1.4", 22 | "mockery/mockery": "^1.0", 23 | "nunomaduro/collision": "^2.0", 24 | "phpunit/phpunit": "^7.0" 25 | }, 26 | "config": { 27 | "optimize-autoloader": true, 28 | "preferred-install": "dist", 29 | "sort-packages": true 30 | }, 31 | "extra": { 32 | "laravel": { 33 | "dont-discover": [] 34 | } 35 | }, 36 | "autoload": { 37 | "psr-4": { 38 | "App\\": "app/" 39 | }, 40 | "classmap": [ 41 | "database/seeds", 42 | "database/factories" 43 | ] 44 | }, 45 | "autoload-dev": { 46 | "psr-4": { 47 | "Tests\\": "tests/" 48 | } 49 | }, 50 | "minimum-stability": "dev", 51 | "prefer-stable": true, 52 | "scripts": { 53 | "post-autoload-dump": [ 54 | "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump", 55 | "@php artisan package:discover --ansi" 56 | ], 57 | "post-root-package-install": [ 58 | "@php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 59 | ], 60 | "post-create-project-cmd": [ 61 | "@php artisan key:generate --ansi" 62 | ] 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /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 | // 'input_key' => 'api_token', 48 | // 'storage_key' => 'api_token' 49 | ], 50 | ], 51 | 52 | /* 53 | |-------------------------------------------------------------------------- 54 | | User Providers 55 | |-------------------------------------------------------------------------- 56 | | 57 | | All authentication drivers have a user provider. This defines how the 58 | | users are actually retrieved out of your database or other storage 59 | | mechanisms used by this application to persist your user's data. 60 | | 61 | | If you have multiple user tables or models you may configure multiple 62 | | sources which represent each model / table. These sources may then 63 | | be assigned to any extra authentication guards you have defined. 64 | | 65 | | Supported: "database", "eloquent" 66 | | 67 | */ 68 | 69 | 'providers' => [ 70 | 'users' => [ 71 | 'driver' => 'eloquent', 72 | 'model' => App\User::class, 73 | ], 74 | 75 | // 'users' => [ 76 | // 'driver' => 'database', 77 | // 'table' => 'users', 78 | // ], 79 | ], 80 | 81 | /* 82 | |-------------------------------------------------------------------------- 83 | | Resetting Passwords 84 | |-------------------------------------------------------------------------- 85 | | 86 | | You may specify multiple password reset configurations if you have more 87 | | than one user table or model in the application and you want to have 88 | | separate password reset settings based on the specific user types. 89 | | 90 | | The expire time is the number of minutes that the reset token should be 91 | | considered valid. This security feature keeps tokens short-lived so 92 | | they have less time to be guessed. You may change this as needed. 93 | | 94 | */ 95 | 96 | 'passwords' => [ 97 | 'users' => [ 98 | 'provider' => 'users', 99 | 'table' => 'password_resets', 100 | 'expire' => 60, 101 | ], 102 | ], 103 | 104 | ]; 105 | -------------------------------------------------------------------------------- /config/broadcasting.php: -------------------------------------------------------------------------------- 1 | env('BROADCAST_DRIVER', 'null'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Broadcast Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the broadcast connections that will be used 26 | | to broadcast events to other systems or over websockets. Samples of 27 | | each available type of connection are provided inside this array. 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'pusher' => [ 34 | 'driver' => 'pusher', 35 | 'key' => env('PUSHER_APP_KEY'), 36 | 'secret' => env('PUSHER_APP_SECRET'), 37 | 'app_id' => env('PUSHER_APP_ID'), 38 | 'options' => [ 39 | 'cluster' => env('PUSHER_APP_CLUSTER'), 40 | 'encrypted' => true, 41 | ], 42 | ], 43 | 44 | 'redis' => [ 45 | 'driver' => 'redis', 46 | 'connection' => 'default', 47 | ], 48 | 49 | 'log' => [ 50 | 'driver' => 'log', 51 | ], 52 | 53 | 'null' => [ 54 | 'driver' => 'null', 55 | ], 56 | 57 | ], 58 | 59 | ]; 60 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_DRIVER', 'file'), 21 | 22 | /* 23 | |-------------------------------------------------------------------------- 24 | | Cache Stores 25 | |-------------------------------------------------------------------------- 26 | | 27 | | Here you may define all of the cache "stores" for your application as 28 | | well as their drivers. You may even define multiple stores for the 29 | | same cache driver to group types of items stored in your caches. 30 | | 31 | */ 32 | 33 | 'stores' => [ 34 | 35 | 'apc' => [ 36 | 'driver' => 'apc', 37 | ], 38 | 39 | 'array' => [ 40 | 'driver' => 'array', 41 | ], 42 | 43 | 'database' => [ 44 | 'driver' => 'database', 45 | 'table' => 'cache', 46 | 'connection' => null, 47 | ], 48 | 49 | 'file' => [ 50 | 'driver' => 'file', 51 | 'path' => storage_path('framework/cache/data'), 52 | ], 53 | 54 | 'memcached' => [ 55 | 'driver' => 'memcached', 56 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 57 | 'sasl' => [ 58 | env('MEMCACHED_USERNAME'), 59 | env('MEMCACHED_PASSWORD'), 60 | ], 61 | 'options' => [ 62 | // Memcached::OPT_CONNECT_TIMEOUT => 2000, 63 | ], 64 | 'servers' => [ 65 | [ 66 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 67 | 'port' => env('MEMCACHED_PORT', 11211), 68 | 'weight' => 100, 69 | ], 70 | ], 71 | ], 72 | 73 | 'redis' => [ 74 | 'driver' => 'redis', 75 | 'connection' => 'cache', 76 | ], 77 | 78 | ], 79 | 80 | /* 81 | |-------------------------------------------------------------------------- 82 | | Cache Key Prefix 83 | |-------------------------------------------------------------------------- 84 | | 85 | | When utilizing a RAM based store such as APC or Memcached, there might 86 | | be other applications utilizing the same cache. So, we'll specify a 87 | | value to get prefixed to all our keys so we can avoid collisions. 88 | | 89 | */ 90 | 91 | 'prefix' => env('CACHE_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_cache'), 92 | 93 | ]; 94 | -------------------------------------------------------------------------------- /config/filesystems.php: -------------------------------------------------------------------------------- 1 | env('FILESYSTEM_DRIVER', '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' => env('FILESYSTEM_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", "sftp", "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_ACCESS_KEY_ID'), 61 | 'secret' => env('AWS_SECRET_ACCESS_KEY'), 62 | 'region' => env('AWS_DEFAULT_REGION'), 63 | 'bucket' => env('AWS_BUCKET'), 64 | 'url' => env('AWS_URL'), 65 | ], 66 | 67 | ], 68 | 69 | ]; 70 | -------------------------------------------------------------------------------- /config/hashing.php: -------------------------------------------------------------------------------- 1 | 'bcrypt', 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Bcrypt Options 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may specify the configuration options that should be used when 26 | | passwords are hashed using the Bcrypt algorithm. This will allow you 27 | | to control the amount of time it takes to hash the given password. 28 | | 29 | */ 30 | 31 | 'bcrypt' => [ 32 | 'rounds' => env('BCRYPT_ROUNDS', 10), 33 | ], 34 | 35 | /* 36 | |-------------------------------------------------------------------------- 37 | | Argon Options 38 | |-------------------------------------------------------------------------- 39 | | 40 | | Here you may specify the configuration options that should be used when 41 | | passwords are hashed using the Argon algorithm. These will allow you 42 | | to control the amount of time it takes to hash the given password. 43 | | 44 | */ 45 | 46 | 'argon' => [ 47 | 'memory' => 1024, 48 | 'threads' => 2, 49 | 'time' => 2, 50 | ], 51 | 52 | ]; 53 | -------------------------------------------------------------------------------- /config/logging.php: -------------------------------------------------------------------------------- 1 | env('LOG_CHANNEL', 'stack'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Log Channels 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may configure the log channels for your application. Out of 27 | | the box, Laravel uses the Monolog PHP logging library. This gives 28 | | you a variety of powerful log handlers / formatters to utilize. 29 | | 30 | | Available Drivers: "single", "daily", "slack", "syslog", 31 | | "errorlog", "monolog", 32 | | "custom", "stack" 33 | | 34 | */ 35 | 36 | 'channels' => [ 37 | 'stack' => [ 38 | 'driver' => 'stack', 39 | 'channels' => ['daily'], 40 | ], 41 | 42 | 'single' => [ 43 | 'driver' => 'single', 44 | 'path' => storage_path('logs/laravel.log'), 45 | 'level' => 'debug', 46 | ], 47 | 48 | 'daily' => [ 49 | 'driver' => 'daily', 50 | 'path' => storage_path('logs/laravel.log'), 51 | 'level' => 'debug', 52 | 'days' => 14, 53 | ], 54 | 55 | 'slack' => [ 56 | 'driver' => 'slack', 57 | 'url' => env('LOG_SLACK_WEBHOOK_URL'), 58 | 'username' => 'Laravel Log', 59 | 'emoji' => ':boom:', 60 | 'level' => 'critical', 61 | ], 62 | 63 | 'papertrail' => [ 64 | 'driver' => 'monolog', 65 | 'level' => 'debug', 66 | 'handler' => SyslogUdpHandler::class, 67 | 'handler_with' => [ 68 | 'host' => env('PAPERTRAIL_URL'), 69 | 'port' => env('PAPERTRAIL_PORT'), 70 | ], 71 | ], 72 | 73 | 'stderr' => [ 74 | 'driver' => 'monolog', 75 | 'handler' => StreamHandler::class, 76 | 'formatter' => env('LOG_STDERR_FORMATTER'), 77 | 'with' => [ 78 | 'stream' => 'php://stderr', 79 | ], 80 | ], 81 | 82 | 'syslog' => [ 83 | 'driver' => 'syslog', 84 | 'level' => 'debug', 85 | ], 86 | 87 | 'errorlog' => [ 88 | 'driver' => 'errorlog', 89 | 'level' => 'debug', 90 | ], 91 | ], 92 | 93 | ]; 94 | -------------------------------------------------------------------------------- /config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_CONNECTION', 'sync'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Queue Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here you may configure the connection information for each server that 24 | | is used by your application. A default configuration has been added 25 | | for each back-end shipped with Laravel. You are free to add more. 26 | | 27 | | Drivers: "sync", "database", "beanstalkd", "sqs", "redis", "null" 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'sync' => [ 34 | 'driver' => 'sync', 35 | ], 36 | 37 | 'database' => [ 38 | 'driver' => 'database', 39 | 'table' => 'jobs', 40 | 'queue' => 'default', 41 | 'retry_after' => 90, 42 | ], 43 | 44 | 'beanstalkd' => [ 45 | 'driver' => 'beanstalkd', 46 | 'host' => 'localhost', 47 | 'queue' => 'default', 48 | 'retry_after' => 90, 49 | ], 50 | 51 | 'sqs' => [ 52 | 'driver' => 'sqs', 53 | 'key' => env('SQS_KEY', 'your-public-key'), 54 | 'secret' => env('SQS_SECRET', 'your-secret-key'), 55 | 'prefix' => env('SQS_PREFIX', 'https://sqs.us-east-1.amazonaws.com/your-account-id'), 56 | 'queue' => env('SQS_QUEUE', 'your-queue-name'), 57 | 'region' => env('SQS_REGION', 'us-east-1'), 58 | ], 59 | 60 | 'redis' => [ 61 | 'driver' => 'redis', 62 | 'connection' => 'default', 63 | 'queue' => env('REDIS_QUEUE', 'default'), 64 | 'retry_after' => 90, 65 | 'block_for' => null, 66 | ], 67 | 68 | ], 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Failed Queue Jobs 73 | |-------------------------------------------------------------------------- 74 | | 75 | | These options configure the behavior of failed queue job logging so you 76 | | can control which database and table are used to store the jobs that 77 | | have failed. You may change them to any database / table you wish. 78 | | 79 | */ 80 | 81 | 'failed' => [ 82 | 'database' => env('DB_CONNECTION', 'mysql'), 83 | 'table' => 'failed_jobs', 84 | ], 85 | 86 | ]; 87 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'domain' => env('MAILGUN_DOMAIN'), 19 | 'secret' => env('MAILGUN_SECRET'), 20 | 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), 21 | ], 22 | 23 | 'ses' => [ 24 | 'key' => env('SES_KEY'), 25 | 'secret' => env('SES_SECRET'), 26 | 'region' => env('SES_REGION', 'us-east-1'), 27 | ], 28 | 29 | 'sparkpost' => [ 30 | 'secret' => env('SPARKPOST_SECRET'), 31 | ], 32 | 33 | 'stripe' => [ 34 | 'model' => App\User::class, 35 | 'key' => env('STRIPE_KEY'), 36 | 'secret' => env('STRIPE_SECRET'), 37 | 'webhook' => [ 38 | 'secret' => env('STRIPE_WEBHOOK_SECRET'), 39 | 'tolerance' => env('STRIPE_WEBHOOK_TOLERANCE', 300), 40 | ], 41 | ], 42 | 43 | ]; 44 | -------------------------------------------------------------------------------- /config/view.php: -------------------------------------------------------------------------------- 1 | [ 17 | resource_path('views'), 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled View Path 23 | |-------------------------------------------------------------------------- 24 | | 25 | | This option determines where all the compiled Blade templates will be 26 | | stored for your application. Typically, this is within the storage 27 | | directory. However, as usual, you are free to change this value. 28 | | 29 | */ 30 | 31 | 'compiled' => env( 32 | 'VIEW_COMPILED_PATH', 33 | realpath(storage_path('framework/views')) 34 | ), 35 | 36 | ]; 37 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite 2 | -------------------------------------------------------------------------------- /database/factories/AuthorFactory.php: -------------------------------------------------------------------------------- 1 | define(App\Author::class, function (Faker $faker) { 6 | return [ 7 | // 8 | ]; 9 | }); 10 | 11 | $factory->afterCreating(App\Author::class, function ($author, $faker) { 12 | $author->profile()->save(factory(App\Profile::class)->make()); 13 | }); 14 | 15 | // $factory->afterMaking(App\Author::class, function ($author, $faker) { 16 | // $author->profile()->save(factory(App\Profile::class)->make()); 17 | // }); 18 | -------------------------------------------------------------------------------- /database/factories/BlogPostFactory.php: -------------------------------------------------------------------------------- 1 | define(App\BlogPost::class, function (Faker $faker) { 6 | return [ 7 | 'title' => $faker->sentence(10), 8 | 'content' => $faker->paragraphs(5, true), 9 | 'created_at' => $faker->dateTimeBetween('-3 months'), 10 | ]; 11 | }); 12 | 13 | $factory->state(App\BlogPost::class, 'new-title', function (Faker $faker) { 14 | return [ 15 | 'title' => 'New title', 16 | ]; 17 | }); 18 | -------------------------------------------------------------------------------- /database/factories/CommentFactory.php: -------------------------------------------------------------------------------- 1 | define(App\Comment::class, function (Faker $faker) { 6 | return [ 7 | 'content' => $faker->text, 8 | 'created_at' => $faker->dateTimeBetween('-3 months'), 9 | ]; 10 | }); 11 | -------------------------------------------------------------------------------- /database/factories/ProfileFactory.php: -------------------------------------------------------------------------------- 1 | define(App\Profile::class, function (Faker $faker) { 6 | return [ 7 | // 8 | ]; 9 | }); 10 | -------------------------------------------------------------------------------- /database/factories/UserFactory.php: -------------------------------------------------------------------------------- 1 | define(App\User::class, function (Faker $faker) { 18 | return [ 19 | 'name' => $faker->name, 20 | 'email' => $faker->unique()->safeEmail, 21 | 'email_verified_at' => now(), 22 | 'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret 23 | 'api_token' => Str::random(80), 24 | 'remember_token' => str_random(10), 25 | 'is_admin' => false 26 | ]; 27 | }); 28 | 29 | $factory->state(App\User::class, 'john-doe', function (Faker $faker) { 30 | return [ 31 | 'name' => 'John Doe', 32 | 'email' => 'john@laravel.test', 33 | 'is_admin' => true 34 | ]; 35 | }); 36 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 16 | $table->string('name'); 17 | $table->string('email', 191)->unique(); 18 | $table->timestamp('email_verified_at')->nullable(); 19 | $table->string('password'); 20 | $table->rememberToken(); 21 | $table->timestamps(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | */ 28 | public function down() 29 | { 30 | Schema::dropIfExists('users'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_100000_create_password_resets_table.php: -------------------------------------------------------------------------------- 1 | string('email', 191)->index(); 16 | $table->string('token'); 17 | $table->timestamp('created_at')->nullable(); 18 | }); 19 | } 20 | 21 | /** 22 | * Reverse the migrations. 23 | */ 24 | public function down() 25 | { 26 | Schema::dropIfExists('password_resets'); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /database/migrations/2019_01_20_161408_create_blogposts_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->timestamps(); 19 | }); 20 | } 21 | 22 | /** 23 | * Reverse the migrations. 24 | * 25 | * @return void 26 | */ 27 | public function down() 28 | { 29 | Schema::dropIfExists('blogposts'); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /database/migrations/2019_01_20_162238_add_title_content_to_blogposts_table.php: -------------------------------------------------------------------------------- 1 | string('title')->default(''); 16 | 17 | if (env('DB_CONNECTION') === 'sqlite_testing') { 18 | $table->text('content')->default(''); 19 | } else { 20 | $table->text('content'); 21 | } 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | */ 28 | public function down() 29 | { 30 | Schema::table('blogposts', function (Blueprint $table) { 31 | $table->dropColumn(['title', 'content']); 32 | }); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /database/migrations/2019_01_22_173935_change_blogposts_table_name.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->timestamps(); 19 | }); 20 | } 21 | 22 | /** 23 | * Reverse the migrations. 24 | * 25 | * @return void 26 | */ 27 | public function down() 28 | { 29 | Schema::dropIfExists('authors'); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /database/migrations/2019_02_25_124736_create_profiles_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->timestamps(); 19 | 20 | $table->unsignedInteger('author_id')->unique(); 21 | $table->foreign('author_id')->references('id')->on('authors'); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | * 28 | * @return void 29 | */ 30 | public function down() 31 | { 32 | Schema::dropIfExists('profiles'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /database/migrations/2019_02_27_160516_create_comments_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->timestamps(); 19 | 20 | 21 | if (env('DB_CONNECTION') === 'sqlite_testing') { 22 | $table->text('content')->default(''); 23 | } else { 24 | $table->text('content'); 25 | } 26 | 27 | $table->unsignedInteger('blog_post_id')->index(); 28 | $table->foreign('blog_post_id')->references('id')->on('blog_posts'); 29 | }); 30 | } 31 | 32 | /** 33 | * Reverse the migrations. 34 | * 35 | * @return void 36 | */ 37 | public function down() 38 | { 39 | Schema::dropIfExists('comments'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /database/migrations/2019_03_20_181629_add_user_to_blog_posts_table.php: -------------------------------------------------------------------------------- 1 | unsignedInteger('user_id')->nullable(); 18 | 19 | if (env('DB_CONNECTION') === 'sqlite_testing') { 20 | $table->unsignedInteger('user_id')->default(0); 21 | } else { 22 | $table->unsignedInteger('user_id'); 23 | } 24 | 25 | $table->foreign('user_id') 26 | ->references('id')->on('users'); 27 | }); 28 | } 29 | 30 | /** 31 | * Reverse the migrations. 32 | * 33 | * @return void 34 | */ 35 | public function down() 36 | { 37 | Schema::table('blog_posts', function (Blueprint $table) { 38 | $table->dropForeign(['user_id']); 39 | $table->dropColumn('user_id'); 40 | }); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /database/migrations/2019_04_02_162450_add_cascade_delete_to_comments_table.php: -------------------------------------------------------------------------------- 1 | dropForeign(['blog_post_id']); 19 | } 20 | 21 | $table->foreign('blog_post_id') 22 | ->references('id') 23 | ->on('blog_posts') 24 | ->onDelete('cascade'); 25 | }); 26 | } 27 | 28 | /** 29 | * Reverse the migrations. 30 | * 31 | * @return void 32 | */ 33 | public function down() 34 | { 35 | Schema::table('comments', function (Blueprint $table) { 36 | $table->dropForeign(['blog_post_id']); 37 | $table->foreign('blog_post_id') 38 | ->references('id') 39 | ->on('blog_posts'); 40 | }); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /database/migrations/2019_04_02_163816_add_soft_deletes_to_blog_posts_table.php: -------------------------------------------------------------------------------- 1 | softDeletes(); 18 | }); 19 | } 20 | 21 | /** 22 | * Reverse the migrations. 23 | * 24 | * @return void 25 | */ 26 | public function down() 27 | { 28 | Schema::table('blog_posts', function (Blueprint $table) { 29 | $table->dropSoftDeletes(); 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/migrations/2019_04_04_162648_add_soft_deletes_to_comments_table.php: -------------------------------------------------------------------------------- 1 | softDeletes(); 18 | }); 19 | } 20 | 21 | /** 22 | * Reverse the migrations. 23 | * 24 | * @return void 25 | */ 26 | public function down() 27 | { 28 | Schema::table('comments', function (Blueprint $table) { 29 | $table->dropSoftDeletes(); 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/migrations/2019_04_06_145253_add_is_admin_to_users_table.php: -------------------------------------------------------------------------------- 1 | boolean('is_admin')->default(false); 18 | }); 19 | } 20 | 21 | /** 22 | * Reverse the migrations. 23 | * 24 | * @return void 25 | */ 26 | public function down() 27 | { 28 | Schema::table('users', function (Blueprint $table) { 29 | $table->dropColumn('is_admin'); 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/migrations/2019_04_20_154128_create_tags_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->string('name', 40); 19 | $table->timestamps(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | * 26 | * @return void 27 | */ 28 | public function down() 29 | { 30 | Schema::dropIfExists('tags'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/migrations/2019_04_20_154241_create_blog_post_tag_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | 19 | $table->unsignedInteger('blog_post_id')->index(); 20 | $table->foreign('blog_post_id')->references('id') 21 | ->on('blog_posts') 22 | ->onDelete('cascade'); 23 | 24 | $table->unsignedInteger('tag_id')->index(); 25 | $table->foreign('tag_id')->references('id') 26 | ->on('tags') 27 | ->onDelete('cascade'); 28 | 29 | $table->timestamps(); 30 | }); 31 | } 32 | 33 | /** 34 | * Reverse the migrations. 35 | * 36 | * @return void 37 | */ 38 | public function down() 39 | { 40 | Schema::dropIfExists('blog_post_tag'); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /database/migrations/2019_04_22_111215_add_user_to_comments_table.php: -------------------------------------------------------------------------------- 1 | unsignedInteger('user_id')->default(0); 19 | } else { 20 | $table->unsignedInteger('user_id'); 21 | } 22 | 23 | $table->foreign('user_id') 24 | ->references('id')->on('users'); 25 | }); 26 | } 27 | 28 | /** 29 | * Reverse the migrations. 30 | * 31 | * @return void 32 | */ 33 | public function down() 34 | { 35 | Schema::table('comments', function (Blueprint $table) { 36 | $table->dropForeign(['user_id']); 37 | $table->dropColumn('user_id'); 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /database/migrations/2019_04_28_104117_create_images_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->string('path'); 19 | $table->unsignedInteger('blog_post_id')->nullable(); 20 | $table->timestamps(); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | * 27 | * @return void 28 | */ 29 | public function down() 30 | { 31 | Schema::dropIfExists('images'); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /database/migrations/2019_05_01_114040_add_polymorph_to_images_table.php: -------------------------------------------------------------------------------- 1 | dropColumn('blog_post_id'); 18 | 19 | $table->morphs('imageable'); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | * 26 | * @return void 27 | */ 28 | public function down() 29 | { 30 | Schema::table('images', function (Blueprint $table) { 31 | $table->unsignedInteger('blog_post_id')->nullable(); 32 | $table->dropMorphs('imageable'); 33 | }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /database/migrations/2019_05_02_180253_add_polymorph_to_comments_table.php: -------------------------------------------------------------------------------- 1 | dropForeign(['blog_post_id']); 18 | $table->dropColumn('blog_post_id'); 19 | 20 | $table->morphs('commentable'); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | * 27 | * @return void 28 | */ 29 | public function down() 30 | { 31 | Schema::table('comments', function (Blueprint $table) { 32 | $table->dropMorphs('commentable'); 33 | 34 | $table->unsignedInteger('blog_post_id')->index()->nullable(); 35 | $table->foreign('blog_post_id')->references('id')->on('blog_posts'); 36 | }); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /database/migrations/2019_05_05_123450_rename_blog_post_tag_table_to_taggables.php: -------------------------------------------------------------------------------- 1 | dropForeign(['blog_post_id']); 18 | $table->dropColumn('blog_post_id'); 19 | }); 20 | 21 | Schema::rename('blog_post_tag', 'taggables'); 22 | 23 | Schema::table('taggables', function (Blueprint $table) { 24 | $table->morphs('taggable'); 25 | }); 26 | } 27 | 28 | /** 29 | * Reverse the migrations. 30 | * 31 | * @return void 32 | */ 33 | public function down() 34 | { 35 | Schema::table('taggables', function (Blueprint $table) { 36 | $table->dropMorphs('taggable'); 37 | }); 38 | 39 | Schema::rename('taggables', 'blog_post_tag'); 40 | 41 | Schema::disableForeignKeyConstraints(); 42 | 43 | Schema::table('blog_post_tag', function (Blueprint $table) { 44 | $table->unsignedInteger('blog_post_id')->index(); 45 | $table->foreign('blog_post_id')->references('id')->on('blog_posts') 46 | ->onDelete('cascade'); 47 | }); 48 | 49 | Schema::enableForeignKeyConstraints(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /database/migrations/2019_05_09_155933_create_jobs_table.php: -------------------------------------------------------------------------------- 1 | bigIncrements('id'); 18 | $table->string('queue')->index(); 19 | $table->longText('payload'); 20 | $table->unsignedTinyInteger('attempts'); 21 | $table->unsignedInteger('reserved_at')->nullable(); 22 | $table->unsignedInteger('available_at'); 23 | $table->unsignedInteger('created_at'); 24 | }); 25 | } 26 | 27 | /** 28 | * Reverse the migrations. 29 | * 30 | * @return void 31 | */ 32 | public function down() 33 | { 34 | Schema::dropIfExists('jobs'); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /database/migrations/2019_05_09_170210_create_failed_jobs_table.php: -------------------------------------------------------------------------------- 1 | bigIncrements('id'); 18 | $table->text('connection'); 19 | $table->text('queue'); 20 | $table->longText('payload'); 21 | $table->longText('exception'); 22 | $table->timestamp('failed_at')->useCurrent(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | Schema::dropIfExists('failed_jobs'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /database/migrations/2019_05_14_141217_add_locale_to_users_table.php: -------------------------------------------------------------------------------- 1 | string('locale', 3)->default('en'); 18 | }); 19 | } 20 | 21 | /** 22 | * Reverse the migrations. 23 | * 24 | * @return void 25 | */ 26 | public function down() 27 | { 28 | Schema::table('users', function (Blueprint $table) { 29 | $table->dropColumn('locale'); 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/migrations/2019_07_28_093515_add_api_token_to_users_table.php: -------------------------------------------------------------------------------- 1 | string('api_token', 80)->after('password') 18 | ->unique() 19 | ->nullable() 20 | ->default(null); 21 | }); 22 | } 23 | 24 | /** 25 | * Reverse the migrations. 26 | * 27 | * @return void 28 | */ 29 | public function down() 30 | { 31 | Schema::table('users', function (Blueprint $table) { 32 | $table->dropColumn('api_token'); 33 | }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /database/seeds/BlogPostTagTableSeeder.php: -------------------------------------------------------------------------------- 1 | count(); 17 | 18 | if (0 === $tagCount) { 19 | $this->command->info('No tags found, skipping assigning tags to blog posts'); 20 | return; 21 | } 22 | 23 | $howManyMin = (int)$this->command->ask('Minimum tags on blog post?', 0); 24 | $howManyMax = min((int)$this->command->ask('Maximum tags on blog post?', $tagCount), $tagCount); 25 | 26 | BlogPost::all()->each(function (BlogPost $post) use($howManyMin, $howManyMax) { 27 | $take = random_int($howManyMin, $howManyMax); 28 | $tags = Tag::inRandomOrder()->take($take)->get()->pluck('id'); 29 | $post->tags()->sync($tags); 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/seeds/BlogPostsTableSeeder.php: -------------------------------------------------------------------------------- 1 | command->ask('How many blog posts would you like?', 50); 15 | $users = App\User::all(); 16 | 17 | factory(App\BlogPost::class, $blogCount)->make()->each(function($post) use ($users) { 18 | $post->user_id = $users->random()->id; 19 | $post->save(); 20 | }); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /database/seeds/CommentsTableSeeder.php: -------------------------------------------------------------------------------- 1 | count() === 0 || $users->count() === 0) { 18 | $this->command->info('There are no blog posts or users, so no comments will be added'); 19 | return; 20 | } 21 | 22 | $commentsCount = (int)$this->command->ask('How many comments would you like?', 150); 23 | 24 | factory(App\Comment::class, $commentsCount)->make()->each(function ($comment) use ($posts, $users) { 25 | $comment->commentable_id = $posts->random()->id; 26 | $comment->commentable_type = 'App\BlogPost'; 27 | $comment->user_id = $users->random()->id; 28 | $comment->save(); 29 | }); 30 | 31 | factory(App\Comment::class, $commentsCount)->make()->each(function ($comment) use ($users) { 32 | $comment->commentable_id = $users->random()->id; 33 | $comment->commentable_type = 'App\User'; 34 | $comment->user_id = $users->random()->id; 35 | $comment->save(); 36 | }); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /database/seeds/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | command->confirm('Do you want to refresh the database?')) { 16 | $this->command->call('migrate:refresh'); 17 | $this->command->info('Database was refreshed'); 18 | } 19 | 20 | Cache::tags(['blog-post'])->flush(); 21 | 22 | $this->call([ 23 | UsersTableSeeder::class, 24 | BlogPostsTableSeeder::class, 25 | CommentsTableSeeder::class, 26 | TagsTableSeeder::class, 27 | BlogPostTagTableSeeder::class 28 | ]); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /database/seeds/TagsTableSeeder.php: -------------------------------------------------------------------------------- 1 | each(function ($tagName) { 18 | $tag = new Tag(); 19 | $tag->name = $tagName; 20 | $tag->save(); 21 | }); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /database/seeds/UsersTableSeeder.php: -------------------------------------------------------------------------------- 1 | command->ask('How many users would you like?', 20), 1); 15 | factory(App\User::class)->states('john-doe')->create(); 16 | factory(App\User::class, $usersCount)->create(); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /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": "npm run development -- --watch", 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 --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" 11 | }, 12 | "devDependencies": { 13 | "axios": "^0.18", 14 | "bootstrap": "^4.0.0", 15 | "cross-env": "^5.1", 16 | "jquery": "^3.2", 17 | "laravel-mix": "^4.0.7", 18 | "lodash": "^4.17.5", 19 | "popper.js": "^1.12", 20 | "resolve-url-loader": "^2.3.1", 21 | "sass": "^1.15.2", 22 | "sass-loader": "^7.1.0", 23 | "vue": "^2.5.17", 24 | "vue-template-compiler": "^2.6.4" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | ./tests/Unit 14 | 15 | 16 | 17 | ./tests/Feature 18 | 19 | 20 | 21 | 22 | ./app 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews -Indexes 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Handle Authorization Header 9 | RewriteCond %{HTTP:Authorization} . 10 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 11 | 12 | # Redirect Trailing Slashes If Not A Folder... 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | RewriteCond %{REQUEST_URI} (.+)/$ 15 | RewriteRule ^ %1 [L,R=301] 16 | 17 | # /de/posts -> /posts?locale=de 18 | # /de -> /?locale=de 19 | # /es/posts/14 -> /posts/14?locale=es 20 | # /de/users/1 -> /users/1?locale=de 21 | RedirectMatch "^/(en|de|es)/?(.*)?" "/$2?locale=$1" 22 | 23 | # Handle Front Controller... 24 | RewriteCond %{REQUEST_FILENAME} !-d 25 | RewriteCond %{REQUEST_FILENAME} !-f 26 | RewriteRule ^ index.php [L] 27 | 28 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/piotr-jura-udemy/laravel-course/b7def47345bd5d02166e8d006de1f5d209809e8c/public/favicon.ico -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | define('LARAVEL_START', microtime(true)); 11 | 12 | /* 13 | |-------------------------------------------------------------------------- 14 | | Register The Auto Loader 15 | |-------------------------------------------------------------------------- 16 | | 17 | | Composer provides a convenient, automatically generated class loader for 18 | | our application. We just need to utilize it! We'll simply require it 19 | | into the script here so that we don't have to worry about manual 20 | | loading any of our classes later on. It feels great to relax. 21 | | 22 | */ 23 | 24 | require __DIR__.'/../vendor/autoload.php'; 25 | 26 | /* 27 | |-------------------------------------------------------------------------- 28 | | Turn On The Lights 29 | |-------------------------------------------------------------------------- 30 | | 31 | | We need to illuminate PHP development, so let us turn on the lights. 32 | | This bootstraps the framework and gets it ready for use, then it 33 | | will load up this application so that we can run it and send 34 | | the responses back to the browser and delight our users. 35 | | 36 | */ 37 | 38 | $app = require_once __DIR__.'/../bootstrap/app.php'; 39 | 40 | /* 41 | |-------------------------------------------------------------------------- 42 | | Run The Application 43 | |-------------------------------------------------------------------------- 44 | | 45 | | Once we have the application, we can handle the incoming request 46 | | through the kernel, and send the associated response back to 47 | | the client's browser allowing them to enjoy the creative 48 | | and wonderful application we have prepared for them. 49 | | 50 | */ 51 | 52 | $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); 53 | 54 | $response = $kernel->handle( 55 | $request = Illuminate\Http\Request::capture() 56 | ); 57 | 58 | $response->send(); 59 | 60 | $kernel->terminate($request, $response); 61 | -------------------------------------------------------------------------------- /public/mix-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "/js/app.js": "/js/app.js", 3 | "/css/app.css": "/css/app.css" 4 | } 5 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /public/svg/404.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | 2 |

Piotr Jura - Udemy Instructor

3 |

Piotr Jura Udemy Courses

4 |

Fado Code Camp

5 |
6 | 7 |

8 | High-quality, comprehensive courses for web developers. 9 |

10 | 11 |

12 | About the Instructor · 13 | Courses · 14 | Contact & Links · 15 | This Course Resources 16 |

17 |
18 | 19 | ## About the Instructor 20 | 21 | I am Piotr Jura, a seasoned web developer and a passionate Udemy instructor. With years of experience in JavaScript, TypeScript, Node, PHP, MySQL, Vue, React, and more, I bring practical, real-world knowledge to my students. 22 | 23 | ## Courses 24 | 25 | - [Master Nuxt 3 - Full-Stack Complete Guide](https://www.udemy.com/course/master-nuxt-full-stack-complete-guide/?referralCode=4EBA58BFBD39A31A9BE9) 26 | - [Symfony 6 Framework Hands-On 2023](https://www.udemy.com/course/symfony-framework-hands-on/?referralCode=6750F64C057515A5F787) 27 | - [Vue 3 Mastery: Firebase & More - Learn by Doing!](https://www.udemy.com/course/vuejs-course/?referralCode=26DAD96DAB47B4602DA3) 28 | - [Master NestJS - Node.js Framework 2023](https://www.udemy.com/course/master-nestjs-the-javascript-nodejs-framework/?referralCode=C8A3F83982053A5E44C0) 29 | - [Master Laravel with GraphQL, Vue.js, and Tailwind](https://www.udemy.com/course/master-laravel-with-graphql-vuejs-and-tailwind/?referralCode=CE3B5297B3614EFA884A) 30 | - [Master Laravel, Vue 3 & Inertia Full Stack 2023](https://www.udemy.com/course/master-laravel-6-with-vuejs-fullstack-development/?referralCode=4A6CED7AA1583CB709D6) 31 | - [Master Laravel 10 for Beginners & Intermediate 2023](https://www.udemy.com/course/laravel-beginner-fundamentals/?referralCode=E86A873AC47FB438D79C) 32 | - [Symfony API Platform with React Full Stack Masterclass](https://www.udemy.com/course/symfony-api-platform-reactjs-full-stack-masterclass/?referralCode=D2C29D1C641BB0CDBCD4) 33 | 34 | ## Contact and Links 35 | 36 | - **Blog:** [Fado Code Camp](https://fadocodecamp.com/) 37 | - **LinkedIn:** [Follow Me on LinkedIn](https://www.linkedin.com/in/piotr-j-24250b257/) 38 | - **GitHub:** You are here! Give me a follow! 39 | - **Twitter:** [@piotr_jura](https://twitter.com/piotr_jura) 40 | 41 | ## Course Resources 42 | 43 | Coming up! 44 | 45 | --- 46 | 47 |

48 | Explore, Learn, and Grow with My Comprehensive Web Development Courses! 49 |

50 | -------------------------------------------------------------------------------- /resources/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 | 11 | window.Vue = require('vue'); 12 | 13 | /** 14 | * The following block of code may be used to automatically register your 15 | * Vue components. It will recursively scan this directory for the Vue 16 | * components and automatically register them with their "basename". 17 | * 18 | * Eg. ./components/ExampleComponent.vue -> 19 | */ 20 | 21 | // const files = require.context('./', true, /\.vue$/i) 22 | // files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default)) 23 | 24 | Vue.component('example-component', require('./components/ExampleComponent.vue').default); 25 | 26 | /** 27 | * Next, we will create a fresh Vue application instance and attach it to 28 | * the page. Then, you may begin adding components to this application 29 | * or customize the JavaScript scaffolding to fit your unique needs. 30 | */ 31 | 32 | const app = new Vue({ 33 | el: '#app' 34 | }); 35 | -------------------------------------------------------------------------------- /resources/js/bootstrap.js: -------------------------------------------------------------------------------- 1 | 2 | window._ = require('lodash'); 3 | 4 | /** 5 | * We'll load jQuery and the Bootstrap jQuery plugin which provides support 6 | * for JavaScript based Bootstrap features such as modals and tabs. This 7 | * code may be modified to fit the specific needs of your application. 8 | */ 9 | 10 | try { 11 | window.Popper = require('popper.js').default; 12 | window.$ = window.jQuery = require('jquery'); 13 | 14 | require('bootstrap'); 15 | } catch (e) {} 16 | 17 | /** 18 | * We'll load the axios HTTP library which allows us to easily issue requests 19 | * to our Laravel back-end. This library automatically handles sending the 20 | * CSRF token as a header based on the value of the "XSRF" token cookie. 21 | */ 22 | 23 | window.axios = require('axios'); 24 | 25 | window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 26 | 27 | /** 28 | * Next we will register the CSRF Token as a common header with Axios so that 29 | * all outgoing HTTP requests automatically have it attached. This is just 30 | * a simple convenience so we don't have to attach every token manually. 31 | */ 32 | 33 | let token = document.head.querySelector('meta[name="csrf-token"]'); 34 | 35 | if (token) { 36 | window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content; 37 | } else { 38 | console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token'); 39 | } 40 | 41 | /** 42 | * Echo exposes an expressive API for subscribing to channels and listening 43 | * for events that are broadcast by Laravel. Echo and event broadcasting 44 | * allows your team to easily build robust real-time web applications. 45 | */ 46 | 47 | // import Echo from 'laravel-echo' 48 | 49 | // window.Pusher = require('pusher-js'); 50 | 51 | // window.Echo = new Echo({ 52 | // broadcaster: 'pusher', 53 | // key: process.env.MIX_PUSHER_APP_KEY, 54 | // cluster: process.env.MIX_PUSHER_APP_CLUSTER, 55 | // encrypted: true 56 | // }); 57 | -------------------------------------------------------------------------------- /resources/js/components/ExampleComponent.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 24 | -------------------------------------------------------------------------------- /resources/lang/de.json: -------------------------------------------------------------------------------- 1 | { 2 | "Welcome to Laravel!": "Willkommen bei Laravel!", 3 | "Blog Posts": "Blogeinträge", 4 | "Add": "Hinzufügen", 5 | "Home": "Zuhause", 6 | "Contact": "Kontakt", 7 | "Register": "Registrieren", 8 | "Login": "Anmeldung", 9 | "Logout": "Ausloggen", 10 | "Most Commented": "Am meisten kommentiert", 11 | "Most Active": "Am aktivsten", 12 | "Most Active Last Month": "Am aktivsten im letzten Monat", 13 | "What people are currently talking about": "Worüber die Leute gerade sprechen", 14 | "Writers with most posts written": "Autoren mit den meisten geschriebenen Beiträgen", 15 | "Users with most posts written in the month": "Nutzer mit den meisten Beiträgen im Monat", 16 | "Added": "Hinzugefügt", 17 | "Updated": "Aktualisierte", 18 | "by": "durch", 19 | "Comments": "Bemerkungen", 20 | "Sign-in": "Einloggen", 21 | "to post comments!": "Kommentare zu posten!", 22 | "Hello this is contact!": "Hallo das ist Kontakt!", 23 | "E-mail": "Email", 24 | "Password": "Passwort", 25 | "Remember me": "Erinnere dich an mich", 26 | "Login!": "Anmeldung!", 27 | "Title": "Titel", 28 | "Content": "Inhalt", 29 | "Thumbnail": "Miniaturansicht", 30 | "Create!": "Erstellen!", 31 | "Add comment": "Einen Kommentar hinzufügen", 32 | "Name:": "Name:", 33 | "Upload a different photo": "Laden Sie ein anderes Foto hoch", 34 | "Save changes": "Änderungen speichern", 35 | "Profile": "Profil", 36 | "Edit Profile": "Profil bearbeiten", 37 | "Brand new Post!": "Nagelneuer Beitrag!", 38 | "Edit": "Bearbeiten", 39 | "Delete!": "Löschen!", 40 | "No blog posts yet!": "Noch keine Blog-Beiträge!", 41 | "Update!": "Aktualisieren!" 42 | } 43 | -------------------------------------------------------------------------------- /resources/lang/de/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/piotr-jura-udemy/laravel-course/b7def47345bd5d02166e8d006de1f5d209809e8c/resources/lang/de/.gitkeep -------------------------------------------------------------------------------- /resources/lang/de/messages.php: -------------------------------------------------------------------------------- 1 | '{0} Derzeit von niemandem gelesen|{1} Derzeit von :count Person gelesen|[2,*] Derzeit von :count Personen gelesen', 5 | 'comments' => '{0} Noch keine Kommentare|{1} :count Kommentar|[2,*] :count Kommentare' 6 | ]; 7 | -------------------------------------------------------------------------------- /resources/lang/en.json: -------------------------------------------------------------------------------- 1 | { 2 | "Welcome to Laravel!": "Welcome to Laravel!", 3 | "Blog Posts": "Blog Posts", 4 | "Add": "Add", 5 | "Home": "Home", 6 | "Contact": "Contact", 7 | "Register": "Register", 8 | "Login": "Login", 9 | "Logout": "Logout", 10 | "Most Commented": "Most Commented", 11 | "Most Active": "Most Active", 12 | "Most Active Last Month": "Most Active Last Month", 13 | "What people are currently talking about": "What people are currently talking about", 14 | "Writers with most posts written": "Writers with most posts written", 15 | "Users with most posts written in the month": "Users with most posts written in the month", 16 | "Added": "Added", 17 | "Updated": "Updated", 18 | "by": "by", 19 | "Comments": "Comments", 20 | "Sign-in": "Sign-in", 21 | "to post comments!": "to post comments!", 22 | "Hello this is contact!": "Hello this is contact!", 23 | "E-mail": "E-mail", 24 | "Password": "Password", 25 | "Remember me": "Remember me", 26 | "Login!": "Login!", 27 | "Title": "Title", 28 | "Content": "Content", 29 | "Thumbnail": "Thumbnail", 30 | "Create!": "Create!", 31 | "Add comment": "Add comment", 32 | "Name:": "Name:", 33 | "Upload a different photo": "Upload a different photo", 34 | "Save changes": "Save changes", 35 | "Profile": "Profile", 36 | "Edit Profile": "Edit Profile", 37 | "Brand new Post!": "Brand new Post!", 38 | "Edit": "Edit", 39 | "Delete!": "Delete!", 40 | "No blog posts yet!": "No blog posts yet!", 41 | "Update!": "Update!" 42 | } 43 | -------------------------------------------------------------------------------- /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/messages.php: -------------------------------------------------------------------------------- 1 | '{0} Currently read by :count nobody|{1} Currently read by :count person|[2,*] Currently read by :count people', 5 | 'comments' => '{0} No comments yet|{1} :count comment|[2,*] :count comments' 6 | ]; 7 | -------------------------------------------------------------------------------- /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/es.json: -------------------------------------------------------------------------------- 1 | { 2 | "Welcome to Laravel!": "¡Bienvenido a Laravel!", 3 | "Blog Posts": "Publicaciones de blog", 4 | "Add": "Añadir", 5 | "Home": "Casa", 6 | "Contact": "Contacto", 7 | "Register": "Registro", 8 | "Login": "Iniciar sesión", 9 | "Logout": "Cerrar sesión", 10 | "Most Commented": "Más comentado", 11 | "Most Active": "Mas activo", 12 | "Most Active Last Month": "El mes pasado más activo", 13 | "What people are currently talking about": "Lo que la gente está hablando actualmente", 14 | "Writers with most posts written": "Escritores con más publicaciones escritas", 15 | "Users with most posts written in the month": "Usuarios con más publicaciones escritas en el mes", 16 | "Added": "Adicional", 17 | "Updated": "Actualizado", 18 | "by": "por", 19 | "Comments": "Comentarios", 20 | "Sign-in": "Registrarse", 21 | "to post comments!": "para publicar comentarios!", 22 | "Hello this is contact!": "Hola este es el contacto!", 23 | "E-mail": "Email", 24 | "Password": "Contraseña", 25 | "Remember me": "Recuérdame", 26 | "Login!": "¡Iniciar sesión!", 27 | "Title": "Título", 28 | "Content": "Contenido", 29 | "Thumbnail": "Miniatura", 30 | "Create!": "¡Crear!", 31 | "Add comment": "Agregar comentario", 32 | "Name:": "Nombre:", 33 | "Upload a different photo": "Sube una foto diferente", 34 | "Save changes": "Guardar cambios", 35 | "Profile": "Perfil", 36 | "Edit Profile": "Editar perfil", 37 | "Brand new Post!": "Nuevo post!", 38 | "Edit": "Editar", 39 | "Delete!": "Borrar!", 40 | "No blog posts yet!": "Aún no hay publicaciones en el blog!", 41 | "Update!": "Actualizar!" 42 | } 43 | -------------------------------------------------------------------------------- /resources/lang/es/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/piotr-jura-udemy/laravel-course/b7def47345bd5d02166e8d006de1f5d209809e8c/resources/lang/es/.gitkeep -------------------------------------------------------------------------------- /resources/lang/es/messages.php: -------------------------------------------------------------------------------- 1 | '{0} Actualmente leído por nadie|{1} Actualmente leído por :count persona|[2,*] Actualmente leído por :count personas', 5 | 'comments' => '{0} Sin comentarios aún|{1} :count comentario|[2,*] :count comentarios' 6 | ]; 7 | -------------------------------------------------------------------------------- /resources/sass/_variables.scss: -------------------------------------------------------------------------------- 1 | 2 | // Body 3 | $body-bg: #f8fafc; 4 | 5 | // Typography 6 | $font-family-sans-serif: "Nunito", sans-serif; 7 | $font-size-base: 0.9rem; 8 | $line-height-base: 1.6; 9 | 10 | // Colors 11 | $blue: #3490dc; 12 | $indigo: #6574cd; 13 | $purple: #9561e2; 14 | $pink: #f66D9b; 15 | $red: #e3342f; 16 | $orange: #f6993f; 17 | $yellow: #ffed4a; 18 | $green: #38c172; 19 | $teal: #4dc0b5; 20 | $cyan: #6cb2eb; 21 | -------------------------------------------------------------------------------- /resources/sass/app.scss: -------------------------------------------------------------------------------- 1 | 2 | // Fonts 3 | @import url('https://fonts.googleapis.com/css?family=Nunito'); 4 | 5 | // Variables 6 | @import 'variables'; 7 | 8 | // Bootstrap 9 | @import '~bootstrap/scss/bootstrap'; 10 | 11 | .navbar-laravel { 12 | background-color: #fff; 13 | box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04); 14 | } 15 | 16 | .fm-inline { 17 | display: inline; 18 | } 19 | 20 | .badge-lg { 21 | font-size: 1.0rem; 22 | } 23 | 24 | .avatar { 25 | width: 128px; 26 | height: 128px; 27 | } -------------------------------------------------------------------------------- /resources/views/auth/login.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layout') 2 | @section('content') 3 |
4 | @csrf 5 | 6 |
7 | 8 | 10 | 11 | @if ($errors->has('email')) 12 | 13 | {{ $errors->first('email') }} 14 | 15 | @endif 16 |
17 | 18 |
19 | 20 | 22 | 23 | @if ($errors->has('password')) 24 | 25 | {{ $errors->first('password') }} 26 | 27 | @endif 28 |
29 | 30 |
31 |
32 | 34 | 35 | 38 |
39 |
40 | 41 | 42 |
43 | @endsection('content') -------------------------------------------------------------------------------- /resources/views/auth/register.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layout') 2 | @section('content') 3 |
4 | @csrf 5 | 6 |
7 | 8 | 10 | 11 | @if ($errors->has('name')) 12 | 13 | {{ $errors->first('name') }} 14 | 15 | @endif 16 |
17 | 18 |
19 | 20 | 22 | 23 | @if ($errors->has('email')) 24 | 25 | {{ $errors->first('email') }} 26 | 27 | @endif 28 |
29 | 30 |
31 | 32 | 34 | 35 | @if ($errors->has('password')) 36 | 37 | {{ $errors->first('password') }} 38 | 39 | @endif 40 |
41 | 42 |
43 | 44 | 45 |
46 | 47 | 48 |
49 | @endsection('content') -------------------------------------------------------------------------------- /resources/views/components/badge.blade.php: -------------------------------------------------------------------------------- 1 | @if(!isset($show) || $show) 2 | 3 | {{ $slot }} 4 | 5 | @endif -------------------------------------------------------------------------------- /resources/views/components/card.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 |
{{ $title }}
4 |
5 | {{ $subtitle }} 6 |
7 |
8 | 19 |
-------------------------------------------------------------------------------- /resources/views/components/comment-form.blade.php: -------------------------------------------------------------------------------- 1 |
2 | @auth 3 |
4 | @csrf 5 | 6 |
7 | 8 |
9 | 10 | 11 |
12 | @errors @enderrors 13 | @else 14 | {{ __('Sign-in') }} {{ __('to post comments!') }} 15 | @endauth 16 |
17 |
-------------------------------------------------------------------------------- /resources/views/components/comment-list.blade.php: -------------------------------------------------------------------------------- 1 | @forelse($comments as $comment) 2 |

3 | {{ $comment->content }} 4 |

5 | @tags(['tags' => $comment->tags])@endtags 6 | @updated(['date' => $comment->created_at, 'name' => $comment->user->name, 'userId' => $comment->user->id]) 7 | @endupdated 8 | @empty 9 |

{{ __('No comments yet!') }}

10 | @endforelse -------------------------------------------------------------------------------- /resources/views/components/errors.blade.php: -------------------------------------------------------------------------------- 1 | @if($errors->any()) 2 |
3 | @foreach($errors->all() as $error) 4 | 7 | @endforeach 8 |
9 | @endif -------------------------------------------------------------------------------- /resources/views/components/tags.blade.php: -------------------------------------------------------------------------------- 1 |

2 | @foreach ($tags as $tag) 3 | {{ $tag->name }} 5 | @endforeach 6 |

-------------------------------------------------------------------------------- /resources/views/components/updated.blade.php: -------------------------------------------------------------------------------- 1 |

2 | {{ empty(trim($slot)) ? __('Added') : $slot }} {{ $date->diffForHumans() }} 3 | @if(isset($name)) 4 | @if(isset($userId)) 5 | {{ __('by') }} {{ $name }} 6 | @else 7 | {{ __('by') }} {{ $name }} 8 | @endif 9 | @endif 10 |

-------------------------------------------------------------------------------- /resources/views/contact.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layout') 2 | 3 | @section('content') 4 |

{{ __('Contact') }}

5 |

{{ __('Hello this is contact!') }}

6 | 7 | @can('home.secret') 8 |

9 | 10 | Go to special contact details! 11 | 12 |

13 | @endcan 14 | @endsection -------------------------------------------------------------------------------- /resources/views/emails/posts/blog-post-added.blade.php: -------------------------------------------------------------------------------- 1 | @component('mail::message') 2 | # Someone has posted a blog post 3 | 4 | Be sure to proof read it. 5 | 6 | Thanks,
7 | {{ config('app.name') }} 8 | @endcomponent 9 | -------------------------------------------------------------------------------- /resources/views/emails/posts/comment-posted-on-watched.blade.php: -------------------------------------------------------------------------------- 1 | @component('mail::message') 2 | # Comment was posted on post you're watching 3 | 4 | Hi {{ $user->name }} 5 | 6 | @component('mail::button', ['url' => route('posts.show', ['post' => $comment->commentable->id])]) 7 | View The Blog Post 8 | @endcomponent 9 | 10 | @component('mail::button', ['url' => route('users.show', ['user' => $comment->user->id])]) 11 | Visit {{ $comment->user->name }} profile 12 | @endcomponent 13 | 14 | @component('mail::panel') 15 | {{ $comment->content }} 16 | @endcomponent 17 | 18 | Thanks,
19 | {{ config('app.name') }} 20 | @endcomponent 21 | -------------------------------------------------------------------------------- /resources/views/emails/posts/commented-markdown.blade.php: -------------------------------------------------------------------------------- 1 | @component('mail::message') 2 | # Comment was posted on your blog post 3 | 4 | Hi {{ $comment->commentable->user->name }} 5 | 6 | Someone has commented on your blog post 7 | 8 | @component('mail::button', ['url' => route('posts.show', ['post' => $comment->commentable->id])]) 9 | View The Blog Post 10 | @endcomponent 11 | 12 | @component('mail::button', ['url' => route('users.show', ['user' => $comment->user->id])]) 13 | Visit {{ $comment->user->name }} profile 14 | @endcomponent 15 | 16 | @component('mail::panel') 17 | {{ $comment->content }} 18 | @endcomponent 19 | 20 | Thanks,
21 | {{ config('app.name') }} 22 | @endcomponent 23 | -------------------------------------------------------------------------------- /resources/views/emails/posts/commented.blade.php: -------------------------------------------------------------------------------- 1 | 6 | 7 |

Hi {{ $comment->commentable->user->name }}

8 | 9 |

10 | Someone has commented on your blog post 11 | 12 | {{ $comment->commentable->title }} 13 | 14 |

15 | 16 |
17 | 18 |

19 | 20 | 21 | {{ $comment->user->name }} 22 | said: 23 |

24 | 25 |

26 | "{{ $comment->content }}" 27 |

-------------------------------------------------------------------------------- /resources/views/home.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layout') 2 | 3 | @section('content') 4 |

{{ __('messages.welcome') }}

5 |

@lang('messages.welcome')

6 | 7 |

{{ __('messages.example_with_value', ['name' => 'John']) }}

8 | 9 |

{{ trans_choice('messages.plural', 0, ['a' => 1]) }}

10 |

{{ trans_choice('messages.plural', 1, ['a' => 1]) }}

11 |

{{ trans_choice('messages.plural', 2, ['a' => 1]) }}

12 | 13 |

Using JSON: {{ __('Welcome to Laravel!') }}

14 |

Using JSON: {{ __('Hello :name', ['name' => 'Piotr']) }}

15 | 16 |

This is the content of the main page!

17 | @endsection -------------------------------------------------------------------------------- /resources/views/layout.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Document 9 | 10 | 11 |
12 |
Laravel Blog
13 | 44 |
45 | 46 |
47 | @if(session()->has('status')) 48 |

49 | {{ session()->get('status') }} 50 |

51 | @endif 52 | 53 | @yield('content') 54 |
55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /resources/views/posts/_activity.blade.php: -------------------------------------------------------------------------------- 1 |
2 |
3 | @card(['title' => __('Most Commented')]) 4 | @slot('subtitle') 5 | {{ __('What people are currently talking about') }} 6 | @endslot 7 | @slot('items') 8 | @foreach ($mostCommented as $post) 9 |
  • 10 | 11 | {{ $post->title }} 12 | 13 |
  • 14 | @endforeach 15 | @endslot 16 | @endcard 17 |
    18 | 19 |
    20 | @card(['title' => __('Most Active')]) 21 | @slot('subtitle') 22 | {{ __('Writers with most posts written') }} 23 | @endslot 24 | @slot('items', collect($mostActive)->pluck('name')) 25 | @endcard 26 |
    27 | 28 |
    29 | @card(['title' => __('Most Active Last Month')]) 30 | @slot('subtitle') 31 | {{ __('Users with most posts written in the month') }} 32 | @endslot 33 | @slot('items', collect($mostActiveLastMonth)->pluck('name')) 34 | @endcard 35 |
    36 |
    -------------------------------------------------------------------------------- /resources/views/posts/_form.blade.php: -------------------------------------------------------------------------------- 1 |
    2 | 3 | 5 |
    6 | 7 |
    8 | 9 | 11 |
    12 | 13 |
    14 | 15 | 16 |
    17 | 18 | @errors @enderrors -------------------------------------------------------------------------------- /resources/views/posts/create.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layout') 2 | 3 | @section('content') 4 |
    5 | @csrf 6 | 7 | @include('posts._form') 8 | 9 | 10 |
    11 | @endsection -------------------------------------------------------------------------------- /resources/views/posts/edit.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layout') 2 | 3 | @section('content') 4 |
    7 | @csrf 8 | @method('PUT') 9 | 10 | @include('posts._form') 11 | 12 | 13 |
    14 | @endsection -------------------------------------------------------------------------------- /resources/views/posts/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layout') 2 | 3 | @section('content') 4 |
    5 |
    6 | @forelse ($posts as $post) 7 |

    8 |

    9 | @if($post->trashed()) 10 | 11 | @endif 12 | {{ $post->title }} 14 | @if($post->trashed()) 15 | 16 | @endif 17 |

    18 | 19 | @updated(['date' => $post->created_at, 'name' => $post->user->name, 'userId' => $post->user->id]) 20 | @endupdated 21 | 22 | @tags(['tags' => $post->tags])@endtags 23 |

    24 | {{ trans_choice('messages.comments', $post->comments_count) }} 25 |

    26 | 27 | @auth 28 | @can('update', $post) 29 | 31 | {{ __('Edit') }} 32 | 33 | @endcan 34 | @endauth 35 | 36 | {{-- @cannot('delete', $post) 37 |

    You can't delete this post

    38 | @endcannot --}} 39 | 40 | @auth 41 | @if(!$post->trashed()) 42 | @can('delete', $post) 43 |
    45 | @csrf 46 | @method('DELETE') 47 | 48 | 49 |
    50 | @endcan 51 | @endif 52 | @endauth 53 |

    54 | @empty 55 |

    {{ __('No blog posts yet!') }}

    56 | @endforelse 57 |
    58 |
    59 | @include('posts._activity') 60 |
    61 |
    62 | @endsection('content') -------------------------------------------------------------------------------- /resources/views/posts/show.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layout') 2 | 3 | @section('content') 4 |
    5 |
    6 | @if($post->image) 7 |
    8 |

    9 | @else 10 |

    11 | @endif 12 | {{ $post->title }} 13 | @badge(['show' => now()->diffInMinutes($post->created_at) < 30]) 14 | {{ __('Brand new Post!') }} 15 | @endbadge 16 | @if($post->image) 17 |

    18 |
    19 | @else 20 | 21 | @endif 22 | 23 |

    {{ $post->content }}

    24 | 25 | @updated(['date' => $post->created_at, 'name' => $post->user->name]) 26 | @endupdated 27 | @updated(['date' => $post->updated_at]) 28 | {{ __('Updated') }} 29 | @endupdated 30 | 31 | @tags(['tags' => $post->tags])@endtags 32 | 33 |

    {{ trans_choice('messages.people.reading', $counter) }}

    34 | 35 |

    {{ __('Comments') }}

    36 | 37 | @commentForm(['route' => route('posts.comments.store', ['post' => $post->id])]) 38 | @endcommentForm 39 | 40 | @commentList(['comments' => $post->comments]) 41 | @endcommentList 42 |
    43 |
    44 | @include('posts._activity') 45 |
    46 | @endsection('content') -------------------------------------------------------------------------------- /resources/views/secret.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layout') 2 | 3 | @section('content') 4 |

    Secret Page!

    5 |

    This is a secret email secre@laravel.test

    6 | @endsection -------------------------------------------------------------------------------- /resources/views/users/edit.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layout') 2 | 3 | @section('content') 4 |
    7 | 8 | @csrf 9 | @method('PUT') 10 | 11 |
    12 |
    13 | 15 | 16 |
    17 |
    18 |
    {{ __('Upload a different photo') }}
    19 | 20 |
    21 |
    22 |
    23 |
    24 |
    25 | 26 | 27 |
    28 | 29 |
    30 | 31 | 38 |
    39 | 40 | @errors @enderrors 41 | 42 |
    43 | 44 |
    45 |
    46 |
    47 | 48 |
    49 | @endsection -------------------------------------------------------------------------------- /resources/views/users/show.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layout') 2 | 3 | @section('content') 4 |
    5 |
    6 | 8 |
    9 |
    10 |

    {{ $user->name }}

    11 | 12 |

    Currently viewed by {{ $counter }} other users

    13 | 14 | @commentForm(['route' => route('users.comments.store', ['user' => $user->id])]) 15 | @endcommentForm 16 | 17 | @commentList(['comments' => $user->commentsOn]) 18 | @endcommentList 19 |
    20 |
    21 | @endsection -------------------------------------------------------------------------------- /resources/views/vendor/mail/html/button.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 18 | 19 |
    4 | 5 | 6 | 15 | 16 |
    7 | 8 | 9 | 12 | 13 |
    10 | {{ $slot }} 11 |
    14 |
    17 |
    20 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/html/footer.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/html/header.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{ $slot }} 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/html/layout.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 25 | 26 | 27 | 28 | 51 | 52 |
    29 | 30 | {{ $header ?? '' }} 31 | 32 | 33 | 34 | 46 | 47 | 48 | {{ $footer ?? '' }} 49 |
    35 | 36 | 37 | 38 | 43 | 44 |
    39 | {{ Illuminate\Mail\Markdown::parse($slot) }} 40 | 41 | {{ $subcopy ?? '' }} 42 |
    45 |
    50 |
    53 | 54 | 55 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/html/message.blade.php: -------------------------------------------------------------------------------- 1 | @component('mail::layout') 2 | {{-- Header --}} 3 | @slot('header') 4 | @component('mail::header', ['url' => config('app.url')]) 5 | {{ config('app.name') }} 6 | @endcomponent 7 | @endslot 8 | 9 | {{-- Body --}} 10 | {{ $slot }} 11 | 12 | {{-- Subcopy --}} 13 | @isset($subcopy) 14 | @slot('subcopy') 15 | @component('mail::subcopy') 16 | {{ $subcopy }} 17 | @endcomponent 18 | @endslot 19 | @endisset 20 | 21 | {{-- Footer --}} 22 | @slot('footer') 23 | @component('mail::footer') 24 | © {{ date('Y') }} {{ config('app.name') }}. @lang('All rights reserved.') 25 | @endcomponent 26 | @endslot 27 | @endcomponent 28 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/html/panel.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 |
    4 | 5 | 6 | 9 | 10 |
    7 | {{ Illuminate\Mail\Markdown::parse($slot) }} 8 |
    11 |
    14 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/html/promotion.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 |
    4 | {{ Illuminate\Mail\Markdown::parse($slot) }} 5 |
    8 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/html/promotion/button.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 12 | 13 |
    4 | 5 | 6 | 9 | 10 |
    7 | {{ $slot }} 8 |
    11 |
    14 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/html/subcopy.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 |
    4 | {{ Illuminate\Mail\Markdown::parse($slot) }} 5 |
    8 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/html/table.blade.php: -------------------------------------------------------------------------------- 1 |
    2 | {{ Illuminate\Mail\Markdown::parse($slot) }} 3 |
    4 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/markdown/button.blade.php: -------------------------------------------------------------------------------- 1 | {{ $slot }}: {{ $url }} -------------------------------------------------------------------------------- /resources/views/vendor/mail/markdown/footer.blade.php: -------------------------------------------------------------------------------- 1 | {{ $slot }} 2 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/markdown/header.blade.php: -------------------------------------------------------------------------------- 1 | [{{ $slot }}]({{ $url }}) 2 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/markdown/layout.blade.php: -------------------------------------------------------------------------------- 1 | {!! strip_tags($header) !!} 2 | 3 | {!! strip_tags($slot) !!} 4 | @isset($subcopy) 5 | 6 | {!! strip_tags($subcopy) !!} 7 | @endisset 8 | 9 | {!! strip_tags($footer) !!} 10 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/markdown/message.blade.php: -------------------------------------------------------------------------------- 1 | @component('mail::layout') 2 | {{-- Header --}} 3 | @slot('header') 4 | @component('mail::header', ['url' => config('app.url')]) 5 | {{ config('app.name') }} 6 | @endcomponent 7 | @endslot 8 | 9 | {{-- Body --}} 10 | {{ $slot }} 11 | 12 | {{-- Subcopy --}} 13 | @isset($subcopy) 14 | @slot('subcopy') 15 | @component('mail::subcopy') 16 | {{ $subcopy }} 17 | @endcomponent 18 | @endslot 19 | @endisset 20 | 21 | {{-- Footer --}} 22 | @slot('footer') 23 | @component('mail::footer') 24 | © {{ date('Y') }} {{ config('app.name') }}. @lang('All rights reserved.') 25 | @endcomponent 26 | @endslot 27 | @endcomponent 28 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/markdown/panel.blade.php: -------------------------------------------------------------------------------- 1 | {{ $slot }} 2 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/markdown/promotion.blade.php: -------------------------------------------------------------------------------- 1 | {{ $slot }} 2 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/markdown/promotion/button.blade.php: -------------------------------------------------------------------------------- 1 | [{{ $slot }}]({{ $url }}) 2 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/markdown/subcopy.blade.php: -------------------------------------------------------------------------------- 1 | {{ $slot }} 2 | -------------------------------------------------------------------------------- /resources/views/vendor/mail/markdown/table.blade.php: -------------------------------------------------------------------------------- 1 | {{ $slot }} 2 | -------------------------------------------------------------------------------- /routes/api.php: -------------------------------------------------------------------------------- 1 | get('/user', function (Request $request) { 17 | return $request->user(); 18 | }); 19 | 20 | Route::prefix('v1')->name('api.v1.')->namespace('Api\V1')->group(function () { 21 | Route::get('/status', function () { 22 | return response()->json(['status' => 'OK']); 23 | })->name('status'); 24 | Route::apiResource('posts.comments', 'PostCommentController'); 25 | }); 26 | 27 | Route::prefix('v2')->name('api.v2.')->group(function () { 28 | Route::get('/status', function () { 29 | return response()->json(['status' => true]); 30 | })->name('status'); 31 | }); 32 | 33 | Route::fallback(function () { 34 | return response()->json([ 35 | 'message' => 'Not found' 36 | ], 404); 37 | })->name('api.fallback'); 38 | -------------------------------------------------------------------------------- /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 | name('home') 16 | // ->middleware('auth') 17 | ; 18 | Route::get('/contact', 'HomeController@contact')->name('contact'); 19 | Route::get('/secret', 'HomeController@secret') 20 | ->name('secret') 21 | ->middleware('can:home.secret'); 22 | Route::resource('posts', 'PostController'); 23 | Route::get('/posts/tag/{tag}', 'PostTagController@index')->name('posts.tags.index'); 24 | 25 | Route::resource('posts.comments', 'PostCommentController')->only(['index', 'store']); 26 | Route::resource('users.comments', 'UserCommentController')->only(['store']); 27 | Route::resource('users', 'UserController')->only(['show', 'edit', 'update']); 28 | 29 | Route::get('mailable', function () { 30 | $comment = App\Comment::find(1); 31 | return new App\Mail\CommentPostedMarkdown($comment); 32 | }); 33 | 34 | Auth::routes(); -------------------------------------------------------------------------------- /server.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | $uri = urldecode( 11 | parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) 12 | ); 13 | 14 | // This file allows us to emulate Apache's "mod_rewrite" functionality from the 15 | // built-in PHP web server. This provides a convenient way to test a Laravel 16 | // application without having installed a "real" web server software here. 17 | if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { 18 | return false; 19 | } 20 | 21 | require_once __DIR__.'/public/index.php'; 22 | -------------------------------------------------------------------------------- /storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !public/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/app/public/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/debugbar/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/.gitignore: -------------------------------------------------------------------------------- 1 | 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 | !data/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/framework/cache/data/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/testing/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /tests/CreatesApplication.php: -------------------------------------------------------------------------------- 1 | make(Kernel::class)->bootstrap(); 19 | 20 | return $app; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/Feature/ApiPostCommentsTest.php: -------------------------------------------------------------------------------- 1 | blogPost(); 18 | 19 | $response = $this->json('GET', 'api/v1/posts/1/comments'); 20 | 21 | $response->assertStatus(200) 22 | ->assertJsonStructure(['data', 'links', 'meta']) 23 | ->assertJsonCount(0, 'data'); 24 | } 25 | 26 | public function testBlogPostHas10Comments() 27 | { 28 | $this->blogPost()->each(function (BlogPost $post) { 29 | $post->comments()->saveMany( 30 | factory(Comment::class, 10)->make([ 31 | 'user_id' => $this->user()->id 32 | ]) 33 | ); 34 | }); 35 | 36 | $response = $this->json('GET', 'api/v1/posts/2/comments'); 37 | 38 | $response->assertStatus(200) 39 | ->assertJsonStructure( 40 | [ 41 | 'data' => [ 42 | '*' => [ 43 | 'id', 44 | 'content', 45 | 'created_at', 46 | 'updated_at', 47 | 'user' => [ 48 | 'id', 49 | 'name' 50 | ] 51 | ] 52 | ], 53 | 'links', 54 | 'meta' 55 | ] 56 | ) 57 | ->assertJsonCount(10, 'data'); 58 | } 59 | 60 | public function testAddingCommentsWhenNotAuthenticated() 61 | { 62 | $this->blogPost(); 63 | 64 | $response = $this->json('POST', 'api/v1/posts/3/comments', [ 65 | 'content' => 'Hello' 66 | ]); 67 | 68 | $response->assertStatus(401); 69 | } 70 | 71 | public function testAddingCommentsWhenAuthenicated() 72 | { 73 | $this->blogPost(); 74 | 75 | $response = $this->actingAs($this->user(), 'api')->json('POST', 'api/v1/posts/4/comments', [ 76 | 'content' => 'Hello' 77 | ]); 78 | 79 | $response->assertStatus(201); 80 | } 81 | 82 | public function testAddingCommentWithInvalidData() 83 | { 84 | $this->blogPost(); 85 | 86 | $response = $this->actingAs($this->user(), 'api')->json('POST', 'api/v1/posts/5/comments', []); 87 | 88 | $response->assertStatus(422) 89 | ->assertJson([ 90 | "message" => "The given data was invalid.", 91 | "errors" => [ 92 | "content" => [ 93 | "The content field is required." 94 | ] 95 | ] 96 | ]); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /tests/Feature/ExampleTest.php: -------------------------------------------------------------------------------- 1 | get('/'); 18 | 19 | $response->assertStatus(200); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tests/Feature/HomeTest.php: -------------------------------------------------------------------------------- 1 | get('/'); 12 | 13 | $response->assertSeeText('Welcome to Laravel!'); 14 | $response->assertSeeText('This is the content of the main page!'); 15 | } 16 | 17 | public function testContactPageIsWorkingCorrectly() 18 | { 19 | $response = $this->get('/contact'); 20 | 21 | $response->assertSeeText('Contact'); 22 | $response->assertSeeText('Hello this is contact!'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/Feature/PostTest.php: -------------------------------------------------------------------------------- 1 | get('/posts'); 17 | $response->assertSeeText('No blog posts yet!'); 18 | } 19 | 20 | public function testSee1BlogPostWhenThereIs1WithNoComments() 21 | { 22 | // Arrange 23 | $post = $this->createDummyBlogPost(); 24 | 25 | // Act 26 | $response = $this->get('/posts'); 27 | 28 | // Assert 29 | $response->assertSeeText('New title'); 30 | $response->assertSeeText('No comments yet'); 31 | 32 | $this->assertDatabaseHas('blog_posts', [ 33 | 'title' => 'New title', 34 | ]); 35 | } 36 | 37 | public function testSee1BlogPostWithComments() 38 | { 39 | // Arrange 40 | $user = $this->user(); 41 | 42 | $post = $this->createDummyBlogPost(); 43 | factory(Comment::class, 4)->create([ 44 | 'commentable_id' => $post->id, 45 | 'commentable_type' => 'App\BlogPost', 46 | 'user_id' => $user->id 47 | ]); 48 | 49 | $response = $this->get('/posts'); 50 | 51 | $response->assertSeeText('4 comments'); 52 | } 53 | 54 | public function testStoreValid() 55 | { 56 | $params = [ 57 | 'title' => 'Valid title', 58 | 'content' => 'At least 10 characters', 59 | ]; 60 | 61 | $this->actingAs($this->user()) 62 | ->post('/posts', $params) 63 | ->assertStatus(302) 64 | ->assertSessionHas('status'); 65 | 66 | $this->assertEquals(session('status'), 'Blog post was created!'); 67 | } 68 | 69 | public function testStoreFail() 70 | { 71 | $params = [ 72 | 'title' => 'x', 73 | 'content' => 'x', 74 | ]; 75 | 76 | $this->actingAs($this->user()) 77 | ->post('/posts', $params) 78 | ->assertStatus(302) 79 | ->assertSessionHas('errors'); 80 | 81 | $messages = session('errors')->getMessages(); 82 | 83 | $this->assertEquals($messages['title'][0], 'The title must be at least 5 characters.'); 84 | $this->assertEquals($messages['content'][0], 'The content must be at least 10 characters.'); 85 | } 86 | 87 | public function testUpdateValid() 88 | { 89 | $user = $this->user(); 90 | $post = $this->createDummyBlogPost($user->id); 91 | 92 | $this->assertDatabaseHas('blog_posts', $post->toArray()); 93 | 94 | $params = [ 95 | 'title' => 'A new named title', 96 | 'content' => 'Content was changed', 97 | ]; 98 | 99 | $this->actingAs($user) 100 | ->put("/posts/{$post->id}", $params) 101 | ->assertStatus(302) 102 | ->assertSessionHas('status'); 103 | 104 | $this->assertEquals(session('status'), 'Blog post was updated!'); 105 | $this->assertDatabaseMissing('blog_posts', $post->toArray()); 106 | $this->assertDatabaseHas('blog_posts', [ 107 | 'title' => 'A new named title', 108 | ]); 109 | } 110 | 111 | public function testDelete() 112 | { 113 | $user = $this->user(); 114 | $post = $this->createDummyBlogPost($user->id); 115 | $this->assertDatabaseHas('blog_posts', $post->toArray()); 116 | 117 | $this->actingAs($user) 118 | ->delete("/posts/{$post->id}") 119 | ->assertStatus(302) 120 | ->assertSessionHas('status'); 121 | 122 | $this->assertEquals(session('status'), 'Blog post was deleted!'); 123 | // $this->assertDatabaseMissing('blog_posts', $post->toArray()); 124 | $this->assertSoftDeleted('blog_posts', $post->toArray()); 125 | } 126 | 127 | private function createDummyBlogPost($userId = null): BlogPost 128 | { 129 | // $post = new BlogPost(); 130 | // $post->title = 'New title'; 131 | // $post->content = 'Content of the blog post'; 132 | // $post->save(); 133 | 134 | return factory(BlogPost::class)->states('new-title')->create( 135 | [ 136 | 'user_id' => $userId ?? $this->user()->id, 137 | ] 138 | ); 139 | 140 | // return $post; 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | create(); 16 | } 17 | 18 | protected function blogPost() 19 | { 20 | return factory(BlogPost::class)->create([ 21 | 'user_id' => $this->user()->id 22 | ]); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /tests/Unit/ExampleTest.php: -------------------------------------------------------------------------------- 1 | assertTrue(2 == 2); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /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/js/app.js', 'public/js') 15 | .sass('resources/sass/app.scss', 'public/css'); 16 | --------------------------------------------------------------------------------