diff --git a/app/Comment.php b/app/Comment.php new file mode 100644 index 0000000..f17422d --- /dev/null +++ b/app/Comment.php @@ -0,0 +1,20 @@ +morphTo(); + } +} diff --git a/app/Events/PostUpdated.php b/app/Events/PostUpdated.php new file mode 100644 index 0000000..d01693f --- /dev/null +++ b/app/Events/PostUpdated.php @@ -0,0 +1,20 @@ +post = $post; + } +} diff --git a/app/History.php b/app/History.php new file mode 100644 index 0000000..c85d6e3 --- /dev/null +++ b/app/History.php @@ -0,0 +1,15 @@ +latest()->get(); return view('/admin.posts', compact('posts')); } + + public function news() { + $news = News::latest()->get(); + return view('/admin.news', compact('news')); + } } diff --git a/app/Http/Controllers/CommentsController.php b/app/Http/Controllers/CommentsController.php new file mode 100644 index 0000000..809630c --- /dev/null +++ b/app/Http/Controllers/CommentsController.php @@ -0,0 +1,46 @@ +validate([ + 'text' => 'required' + ]); + + $new->comments()->create($values); + + flash('Comment create successfully'); + + return back(); + } + + public function postsCommentStore(Request $request, Post $post) + { + $values = $request->validate([ + 'text' => 'required' + ]); + + $post->comments()->create($values); + + flash('Comment create successfully'); + + return back(); + } + + public function destroy(Comment $comment) + { + $comment->delete(); + + flash('Comment delete successfully'); + + return back(); + } +} diff --git a/app/Http/Controllers/NewsController.php b/app/Http/Controllers/NewsController.php new file mode 100644 index 0000000..e87ced5 --- /dev/null +++ b/app/Http/Controllers/NewsController.php @@ -0,0 +1,93 @@ +middleware('auth'); + $this->middleware('role:admin')->except(['index', 'show']); + } + + public function validateRequest($request, $new) + { + return $request->validate([ + 'name' => ['required', 'max:100', Rule::unique('news')->ignore($new->id)], + 'text' => 'required' + ]); + } + + public function index() + { + $news = News::with(['tags', 'comments'])->latest()->get(); + + return view('news.index', compact('news')); + } + + public function create() + { + return view('news.create'); + } + + public function store(Request $request) + { + $values = $this->validateRequest($request, new News()); + + $new = News::create($values); + + if (!is_null($request['tags'])) { + $requestTags = explode(', ', $request['tags']); + foreach ($requestTags as $tag) { + $tag = Tag::firstOrCreate(['name' => $tag]); + $new->tags()->attach($tag); + } + } + + flash('New created successfully'); + + return back(); + } + + public function show(News $new) + { + return view('news.show', compact('new')); + } + + public function edit(News $new) + { + return view('news.edit', compact('new')); + } + + public function update(Request $request, News $new) + { + $values = $this->validateRequest($request, $new); + + $new->update($values); + + $updater = new TagsCreatorService($new, $request); + $updater->updateTags(); + +// updateTags($new, $request); + + flash( 'New updated successfully'); + + return back(); + } + + public function destroy(News $new) + { + $new->delete(); + + flash( 'New deleted successfully'); + + return redirect('/admin/news'); + } +} diff --git a/app/Http/Controllers/PostsController.php b/app/Http/Controllers/PostsController.php index 2d183d2..dce5829 100644 --- a/app/Http/Controllers/PostsController.php +++ b/app/Http/Controllers/PostsController.php @@ -7,6 +7,7 @@ use App\Notifications\PostEdited; use App\Post; use App\PostTag; +use App\Services\TagsCreatorService; use App\Tag; use Illuminate\Http\Request; use Illuminate\Validation\Rule; @@ -30,13 +31,7 @@ public function validateRequest($request, $post) public function index() { - $posts = Post::with('tags')->where('published', 1)->latest()->get(); - return view('/index', compact('posts')); - } - - public function userPosts() - { - $posts = auth()->user()->posts()->with('tags')->latest()->get(); + $posts = auth()->user()->posts()->with(['tags', 'comments'])->latest()->get(); return view('/posts.index', compact('posts')); } @@ -96,31 +91,10 @@ public function update(Request $request, Post $post) $post->update($values); - $postTags = $post->tags->keyBy('name'); - - if (!is_null($request['tags'])) { - $requestTags = collect(explode(', ', $request['tags']))->keyBy(function ($item) { return $item; }); - } else { - $requestTags = collect([]); - } - - $deleteTags = $postTags->diffKeys($requestTags); - $addTags = $requestTags->diffKeys($postTags); + $updater = new TagsCreatorService($post, $request); + $updater->updateTags(); - if ($addTags->isNotEmpty()) { - foreach ($addTags as $tag) { - $tag = Tag::firstOrCreate(['name' => $tag]); - $post->tags()->attach($tag); - }; - } - - if ($deleteTags->isNotEmpty()) { - foreach ($deleteTags as $tag) { - $post->tags()->detach($tag); - $isLastTag = PostTag::where('tag_id', $tag->id)->first(); - if (!$isLastTag) $tag->delete(); - }; - } +// updateTags($post, $request); sendMailNotifyToAdmin(new PostEdited($post)); flash( 'Post edited successfully'); @@ -139,6 +113,10 @@ public function destroy(Post $post) flash( 'Post deleted successfully'); pushNotification('Post deleted successfully', 'New Notification'); - return back(); + if (auth()->user()->hasRole('admin')) { + return redirect('/admin/posts'); + } else { + return back(); + } } } diff --git a/app/Http/Controllers/StaticPagesController.php b/app/Http/Controllers/StaticPagesController.php index fe0af1e..50ff25e 100644 --- a/app/Http/Controllers/StaticPagesController.php +++ b/app/Http/Controllers/StaticPagesController.php @@ -2,10 +2,17 @@ namespace App\Http\Controllers; -use Illuminate\Http\Request; +use App\Services\StatisticService; class StaticPagesController extends Controller { + protected $statisticService; + + public function __construct(StatisticService $statisticService) + { + $this->statisticService = $statisticService; + } + public function contactsIndex() { return view('static.contacts'); } @@ -13,4 +20,43 @@ public function contactsIndex() { public function aboutIndex() { return view('static.about'); } + + public function statisticsIndex() { + //Общее количество статей + $postsCount = $this->statisticService->getPostsCount(); + + //Общее количество новостей + $newsCount = $this->statisticService->getNewsCount(); + + //ФИО автора, у которого больше всего статей на сайте + $userWithMostPosts = $this->statisticService->getUserWithMaxPosts(); + + //Самая длинная статья - название, ссылка на статью и длина статьи в символах + $theLongestPost = $this->statisticService->getTheLongestPost(); + + //Самая короткая статья - название, ссылка на статью и длина статьи в символах + $theShortestPost = $this->statisticService->getTheShortestPost(); + + //Средние количество статей у “активных” пользователей, при этом активным пользователь считается, если у него есть более 1-й статьи + $avgPostsHaveActiveUsers = $this->statisticService->getAveragePosts(); + + //Самая непостоянная - название, ссылка на статью, которую меняли больше всего раз + $mostChangingPost = $this->statisticService->getMostChangingPost(); + + //Самая обсуждаемая статья - название, ссылка на статью, у которой больше всего комментариев. + $mostCommentPost = $this->statisticService->getMostCommentPost(); + + $statistics = [ + 'posts_count' => $postsCount, + 'news_count' => $newsCount, + 'user_with_most_posts' => $userWithMostPosts, + 'the_longest_post' => $theLongestPost, + 'the_shortest_post' => $theShortestPost, + 'avg_posts_have_active_users' => $avgPostsHaveActiveUsers, + 'most_changing_post' => $mostChangingPost, + 'most_comment_post' => $mostCommentPost + ]; + + return view('static.statistics', ['statistics' => $statistics]); + } } diff --git a/app/Http/Controllers/TagsController.php b/app/Http/Controllers/TagsController.php index 76820d0..c9f9cf4 100644 --- a/app/Http/Controllers/TagsController.php +++ b/app/Http/Controllers/TagsController.php @@ -10,6 +10,7 @@ class TagsController extends Controller public function index(Tag $tag) { $posts = $tag->posts()->with('tags')->get(); - return view('index', compact('posts')); + $news = $tag->news()->with('tags')->get(); + return view('layouts.tags.index', compact('posts', 'news')); } } diff --git a/app/Listeners/AddHistoryOnUpdatePost.php b/app/Listeners/AddHistoryOnUpdatePost.php new file mode 100644 index 0000000..17d477a --- /dev/null +++ b/app/Listeners/AddHistoryOnUpdatePost.php @@ -0,0 +1,37 @@ +post->getChanges(); + $freshValues = $event->post->getOriginal(); + unset($dirtyValues['updated_at']); + + if ($dirtyValues['published'] === true && $freshValues['published'] === 1) { + unset($dirtyValues['published']); + } + + foreach ($dirtyValues as $key => $field) { + $result .= 'Изменено поле: "' . $key . '". Было: "' . $freshValues[$key] . '". Стало: "' . $field . '"' . PHP_EOL; + } + + $values = [ + 'user_email' => auth()->user()->email, + 'text' => $result + ]; + + $event->post->history()->create($values); + } +} diff --git a/app/NewTag.php b/app/NewTag.php new file mode 100644 index 0000000..b0cba3d --- /dev/null +++ b/app/NewTag.php @@ -0,0 +1,10 @@ +belongsToMany(Tag::class, 'new_tag', 'new_id', 'tag_id'); + return $this->morphToMany(Tag::class, 'taggable'); + } + + public function comments() + { + return $this->morphMany(Comment::class, 'commentable'); + } +} diff --git a/app/Post.php b/app/Post.php index 90c29ac..2341625 100644 --- a/app/Post.php +++ b/app/Post.php @@ -2,7 +2,7 @@ namespace App; -use App\Events\PostCreated; +use App\Events\PostUpdated; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -14,17 +14,28 @@ class Post extends Model protected $guarded = []; -// protected $dispatchesEvents = [ -// 'created' => PostCreated::class, -// ]; + protected $dispatchesEvents = [ + 'updated' => PostUpdated::class, + ]; public function tags() { - return $this->belongsToMany(Tag::class); +// return $this->belongsToMany(Tag::class); + return $this->morphToMany(Tag::class, 'taggable'); } public function owner() { return $this->belongsTo(User::class); } + + public function comments() + { + return $this->morphMany(Comment::class, 'commentable'); + } + + public function history() + { + return $this->hasMany(History::class); + } } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 3210700..158eefe 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,6 +2,7 @@ namespace App\Providers; +use App\Services\StatisticService; use App\Tag; use Illuminate\Support\ServiceProvider; @@ -15,8 +16,12 @@ class AppServiceProvider extends ServiceProvider public function register() { view()->composer('layouts.aside-tags', function ($view) { - $view->with('tagsCloud', Tag::all()); + $tags = Tag::whereHas('posts')->orWhereHas('news')->get(); + + $view->with('tagsCloud', $tags); }); + + $this->app->make(StatisticService::class); } /** @@ -26,6 +31,6 @@ public function register() */ public function boot() { - // + } } diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index a598943..feec67d 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -3,6 +3,8 @@ namespace App\Providers; use App\Events\PostCreated; +use App\Events\PostUpdated; +use App\Listeners\AddHistoryOnUpdatePost; use App\Listeners\SendPostCreateNotification; use Illuminate\Auth\Events\Registered; use Illuminate\Auth\Listeners\SendEmailVerificationNotification; @@ -20,8 +22,8 @@ class EventServiceProvider extends ServiceProvider Registered::class => [ SendEmailVerificationNotification::class, ], - PostCreated::class => [ - SendPostCreateNotification::class, + PostUpdated::class => [ + AddHistoryOnUpdatePost::class, ], ]; diff --git a/app/Services/StatisticService.php b/app/Services/StatisticService.php new file mode 100644 index 0000000..d682e67 --- /dev/null +++ b/app/Services/StatisticService.php @@ -0,0 +1,134 @@ +withCount('posts')->orderBy('posts_count', 'desc')->first(); + +// $users = DB::table('users') +// ->join('posts', 'users.id', '=', 'owner_id') +// ->select('users.name', DB::raw('Count(*) as posts_count')) +// ->groupBy('users.name') +// ->orderByDesc('posts_count') +// ->first(); + + return $userWithMostPostsCount; + } + + + /** + * @return Post + */ + + public function getTheLongestPost() + { + $theLongestPost = Post::where(DB::raw('Length(text)'), function($query){ + $query->select(DB::raw('MAX(Length(text))')) + ->from(DB::table('posts')); + })->first(); + + return $theLongestPost; + } + + /** + * @return Post + */ + + public function getTheShortestPost() + { + $theShortestPost = Post::where(DB::raw('Length(text)'), function($query){ + $query->select(DB::raw('MIN(Length(text))')) + ->from(DB::table('posts')); + })->first(); + + return $theShortestPost; + } + + /** + * @return int + */ + + public function getAveragePosts() + { + $posts = User::has('posts', '>', 1)->withCount('posts')->get(); + $averagePosts = intval(round($posts->avg('posts_count'))); + +// $averagePosts = DB::select('select AVG(u.posts_count) as avg_posts_count from (select users.*, (select Count(*) from posts where users.id = posts.owner_id) as posts_count from users) as u')[0]; +// $averagePosts = intval(round($averagePosts->avg_posts_count)); + + return $averagePosts; + } + + /** + * @return Post + */ + + public function getMostChangingPost() + { + $maxChangingPost = Post::has('history', '>=', 1)->withCount('history')->orderBy('history_count', 'desc')->first(); + +// $maxHistoryCount = DB::table('posts') +// ->join('histories as h', 'posts.id', '=', 'h.post_id') +// ->select('posts.name', DB::raw('Count(*) as history_count')) +// ->groupBy('posts.name') +// ->orderByDesc('history_count') +// ->first() +// ; + + return $maxChangingPost; + } + + /** + * @return Collection + */ + + public function getMostCommentPost() + { + $mostCommentPost = Post::has('comments', '>=', 1)->withCount('comments')->orderBy('comments_count', 'desc')->first(); + +// $maxComment = DB::table('posts') +// ->join('comments as c', function ($join) { +// $join->on('posts.id', '=', 'c.commentable_id') +// ->where('c.commentable_type', '=', 'App\Post'); +// }) +// ->select('posts.name', DB::raw('Count(*) as comments_count')) +// ->groupBy('posts.name') +// ->orderByDesc('comments_count') +// ->first() +// ; + + return $mostCommentPost; + } +} diff --git a/app/Services/TagsCreatorService.php b/app/Services/TagsCreatorService.php new file mode 100644 index 0000000..e819bba --- /dev/null +++ b/app/Services/TagsCreatorService.php @@ -0,0 +1,47 @@ +model = $model; + $this->request = $request; + } + + public function updateTags() { + $modelTags = $this->model->tags->keyBy('name'); + + if (!is_null($this->request['tags'])) { + $requestTags = collect(explode(', ', $this->request['tags']))->keyBy(function ($item) { return $item; }); + } else { + $requestTags = collect([]); + } + + $deleteTags = $modelTags->diffKeys($requestTags); + $addTags = $requestTags->diffKeys($modelTags); + + if ($addTags->isNotEmpty()) { + foreach ($addTags as $tag) { + $tag = Tag::firstOrCreate(['name' => $tag]); + $this->model->tags()->attach($tag); + }; + } + + if ($deleteTags->isNotEmpty()) { + foreach ($deleteTags as $tag) { + $this->model->tags()->detach($tag); + $isLastTag = Taggable::where('tag_id', $tag->id)->first(); + if (!$isLastTag) $tag->delete(); + }; + } + } +} diff --git a/app/Tag.php b/app/Tag.php index 8df7266..1fa0d0d 100644 --- a/app/Tag.php +++ b/app/Tag.php @@ -15,7 +15,14 @@ class Tag extends Model public function posts() { - return $this->belongsToMany(Post::class); +// return $this->belongsToMany(Post::class); + return $this->morphedByMany(Post::class, 'taggable'); + } + + public function news() + { +// return $this->belongsToMany(News::class, 'new_tag', 'tag_id', 'new_id'); + return $this->morphedByMany(News::class, 'taggable'); } public function getRouteKeyName() diff --git a/app/Taggable.php b/app/Taggable.php new file mode 100644 index 0000000..b23248f --- /dev/null +++ b/app/Taggable.php @@ -0,0 +1,10 @@ +new = $new; + } + + public function render() + { + return view('components.new-form', ['new' => $this->new]); + } +} diff --git a/app/helpers.php b/app/helpers.php index b7f9ca0..bdac04a 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -1,5 +1,7 @@ first(); + $admin = User::where('email', env('ADMIN_EMAIL_FOR_NOTIFICATIONS'))->first(); if ($admin) { $admin->notify($mailView); @@ -43,3 +45,6 @@ function pushNotification($text = null, $title = null) { return app(\App\Services\PushNotificationsService::class)->send($text, $title); } } + + + diff --git a/composer.lock b/composer.lock index 6725f08..e6755b7 100644 --- a/composer.lock +++ b/composer.lock @@ -366,16 +366,16 @@ }, { "name": "egulias/email-validator", - "version": "2.1.20", + "version": "2.1.22", "source": { "type": "git", "url": "https://github.com/egulias/EmailValidator.git", - "reference": "f46887bc48db66c7f38f668eb7d6ae54583617ff" + "reference": "68e418ec08fbfc6f58f6fd2eea70ca8efc8cc7d5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/f46887bc48db66c7f38f668eb7d6ae54583617ff", - "reference": "f46887bc48db66c7f38f668eb7d6ae54583617ff", + "url": "https://api.github.com/repos/egulias/EmailValidator/zipball/68e418ec08fbfc6f58f6fd2eea70ca8efc8cc7d5", + "reference": "68e418ec08fbfc6f58f6fd2eea70ca8efc8cc7d5", "shasum": "" }, "require": { @@ -420,7 +420,7 @@ "validation", "validator" ], - "time": "2020-09-06T13:44:32+00:00" + "time": "2020-09-26T15:48:38+00:00" }, { "name": "fideloper/proxy", @@ -680,23 +680,23 @@ }, { "name": "guzzlehttp/promises", - "version": "v1.3.1", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" + "reference": "60d379c243457e073cff02bc323a2a86cb355631" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "url": "https://api.github.com/repos/guzzle/promises/zipball/60d379c243457e073cff02bc323a2a86cb355631", + "reference": "60d379c243457e073cff02bc323a2a86cb355631", "shasum": "" }, "require": { - "php": ">=5.5.0" + "php": ">=5.5" }, "require-dev": { - "phpunit/phpunit": "^4.0" + "symfony/phpunit-bridge": "^4.4 || ^5.1" }, "type": "library", "extra": { @@ -727,20 +727,20 @@ "keywords": [ "promise" ], - "time": "2016-12-20T10:07:11+00:00" + "time": "2020-09-30T07:37:28+00:00" }, { "name": "guzzlehttp/psr7", - "version": "1.6.1", + "version": "1.7.0", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "239400de7a173fe9901b9ac7c06497751f00727a" + "reference": "53330f47520498c0ae1f61f7e2c90f55690c06a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a", - "reference": "239400de7a173fe9901b9ac7c06497751f00727a", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/53330f47520498c0ae1f61f7e2c90f55690c06a3", + "reference": "53330f47520498c0ae1f61f7e2c90f55690c06a3", "shasum": "" }, "require": { @@ -753,15 +753,15 @@ }, "require-dev": { "ext-zlib": "*", - "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" + "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.10" }, "suggest": { - "zendframework/zend-httphandlerrunner": "Emit PSR-7 responses" + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6-dev" + "dev-master": "1.7-dev" } }, "autoload": { @@ -798,20 +798,20 @@ "uri", "url" ], - "time": "2019-07-01T23:21:34+00:00" + "time": "2020-09-30T07:37:11+00:00" }, { "name": "laravel/framework", - "version": "v8.4.0", + "version": "v8.7.1", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "1c57ab5e375d0a897c22b29e8352453be514131e" + "reference": "3fb29e904a152b3e1fe49581f66ba5e02fe991f2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/1c57ab5e375d0a897c22b29e8352453be514131e", - "reference": "1c57ab5e375d0a897c22b29e8352453be514131e", + "url": "https://api.github.com/repos/laravel/framework/zipball/3fb29e904a152b3e1fe49581f66ba5e02fe991f2", + "reference": "3fb29e904a152b3e1fe49581f66ba5e02fe991f2", "shasum": "" }, "require": { @@ -961,7 +961,7 @@ "framework", "laravel" ], - "time": "2020-09-16T16:13:13+00:00" + "time": "2020-09-29T15:39:07+00:00" }, { "name": "laravel/helpers", @@ -1018,16 +1018,16 @@ }, { "name": "laravel/telescope", - "version": "v4.0.0", + "version": "v4.0.1", "source": { "type": "git", "url": "https://github.com/laravel/telescope.git", - "reference": "ff4594284ad73e895070265a26e1c0538b984191" + "reference": "4bd0a8b01b889c7704cd0a1d04a849c8da993f43" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/telescope/zipball/ff4594284ad73e895070265a26e1c0538b984191", - "reference": "ff4594284ad73e895070265a26e1c0538b984191", + "url": "https://api.github.com/repos/laravel/telescope/zipball/4bd0a8b01b889c7704cd0a1d04a849c8da993f43", + "reference": "4bd0a8b01b889c7704cd0a1d04a849c8da993f43", "shasum": "" }, "require": { @@ -1073,7 +1073,7 @@ "laravel", "monitoring" ], - "time": "2020-09-08T14:55:22+00:00" + "time": "2020-09-22T16:49:01+00:00" }, { "name": "laravel/tinker", @@ -1382,16 +1382,16 @@ }, { "name": "league/mime-type-detection", - "version": "1.4.0", + "version": "1.5.0", "source": { "type": "git", "url": "https://github.com/thephpleague/mime-type-detection.git", - "reference": "fda190b62b962d96a069fcc414d781db66d65b69" + "reference": "ea2fbfc988bade315acd5967e6d02274086d0f28" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/fda190b62b962d96a069fcc414d781db66d65b69", - "reference": "fda190b62b962d96a069fcc414d781db66d65b69", + "url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/ea2fbfc988bade315acd5967e6d02274086d0f28", + "reference": "ea2fbfc988bade315acd5967e6d02274086d0f28", "shasum": "" }, "require": { @@ -1429,7 +1429,7 @@ "type": "tidelift" } ], - "time": "2020-08-09T10:34:01+00:00" + "time": "2020-09-21T18:10:53+00:00" }, { "name": "monolog/monolog", @@ -1524,16 +1524,16 @@ }, { "name": "nesbot/carbon", - "version": "2.40.0", + "version": "2.40.1", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "6c7646154181013ecd55e80c201b9fd873c6ee5d" + "reference": "d9a76d8b7eb0f97cf3a82529393245212f40ba3b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/6c7646154181013ecd55e80c201b9fd873c6ee5d", - "reference": "6c7646154181013ecd55e80c201b9fd873c6ee5d", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/d9a76d8b7eb0f97cf3a82529393245212f40ba3b", + "reference": "d9a76d8b7eb0f97cf3a82529393245212f40ba3b", "shasum": "" }, "require": { @@ -1609,20 +1609,20 @@ "type": "tidelift" } ], - "time": "2020-09-11T19:00:58+00:00" + "time": "2020-09-23T08:17:37+00:00" }, { "name": "nikic/php-parser", - "version": "v4.9.1", + "version": "v4.10.2", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "88e519766fc58bd46b8265561fb79b54e2e00b28" + "reference": "658f1be311a230e0907f5dfe0213742aff0596de" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/88e519766fc58bd46b8265561fb79b54e2e00b28", - "reference": "88e519766fc58bd46b8265561fb79b54e2e00b28", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/658f1be311a230e0907f5dfe0213742aff0596de", + "reference": "658f1be311a230e0907f5dfe0213742aff0596de", "shasum": "" }, "require": { @@ -1661,7 +1661,7 @@ "parser", "php" ], - "time": "2020-08-30T16:15:20+00:00" + "time": "2020-09-26T10:30:38+00:00" }, { "name": "opis/closure", @@ -2406,16 +2406,16 @@ }, { "name": "symfony/console", - "version": "v5.1.5", + "version": "v5.1.6", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "186f395b256065ba9b890c0a4e48a91d598fa2cf" + "reference": "04c3a31fe8ea94b42c9e2d1acc93d19782133b00" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/186f395b256065ba9b890c0a4e48a91d598fa2cf", - "reference": "186f395b256065ba9b890c0a4e48a91d598fa2cf", + "url": "https://api.github.com/repos/symfony/console/zipball/04c3a31fe8ea94b42c9e2d1acc93d19782133b00", + "reference": "04c3a31fe8ea94b42c9e2d1acc93d19782133b00", "shasum": "" }, "require": { @@ -2495,11 +2495,11 @@ "type": "tidelift" } ], - "time": "2020-09-02T07:07:40+00:00" + "time": "2020-09-18T14:27:32+00:00" }, { "name": "symfony/css-selector", - "version": "v5.1.5", + "version": "v5.1.6", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", @@ -2630,16 +2630,16 @@ }, { "name": "symfony/error-handler", - "version": "v5.1.5", + "version": "v5.1.6", "source": { "type": "git", "url": "https://github.com/symfony/error-handler.git", - "reference": "525636d4b84e06c6ca72d96b6856b5b169416e6a" + "reference": "d2f1d4996d5499f1261164d10080e4120001f041" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/error-handler/zipball/525636d4b84e06c6ca72d96b6856b5b169416e6a", - "reference": "525636d4b84e06c6ca72d96b6856b5b169416e6a", + "url": "https://api.github.com/repos/symfony/error-handler/zipball/d2f1d4996d5499f1261164d10080e4120001f041", + "reference": "d2f1d4996d5499f1261164d10080e4120001f041", "shasum": "" }, "require": { @@ -2697,20 +2697,20 @@ "type": "tidelift" } ], - "time": "2020-08-17T10:01:29+00:00" + "time": "2020-09-27T03:44:28+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v5.1.5", + "version": "v5.1.6", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "94871fc0a69c3c5da57764187724cdce0755899c" + "reference": "d5de97d6af175a9e8131c546db054ca32842dd0f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/94871fc0a69c3c5da57764187724cdce0755899c", - "reference": "94871fc0a69c3c5da57764187724cdce0755899c", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/d5de97d6af175a9e8131c546db054ca32842dd0f", + "reference": "d5de97d6af175a9e8131c546db054ca32842dd0f", "shasum": "" }, "require": { @@ -2730,6 +2730,7 @@ "psr/log": "~1.0", "symfony/config": "^4.4|^5.0", "symfony/dependency-injection": "^4.4|^5.0", + "symfony/error-handler": "^4.4|^5.0", "symfony/expression-language": "^4.4|^5.0", "symfony/http-foundation": "^4.4|^5.0", "symfony/service-contracts": "^1.1|^2", @@ -2783,7 +2784,7 @@ "type": "tidelift" } ], - "time": "2020-08-13T14:19:42+00:00" + "time": "2020-09-18T14:27:32+00:00" }, { "name": "symfony/event-dispatcher-contracts", @@ -2863,16 +2864,16 @@ }, { "name": "symfony/finder", - "version": "v5.1.5", + "version": "v5.1.6", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "2b765f0cf6612b3636e738c0689b29aa63088d5d" + "reference": "2c3ba7ad6884e6c4451ce2340e2dc23f6fa3e0d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/2b765f0cf6612b3636e738c0689b29aa63088d5d", - "reference": "2b765f0cf6612b3636e738c0689b29aa63088d5d", + "url": "https://api.github.com/repos/symfony/finder/zipball/2c3ba7ad6884e6c4451ce2340e2dc23f6fa3e0d8", + "reference": "2c3ba7ad6884e6c4451ce2340e2dc23f6fa3e0d8", "shasum": "" }, "require": { @@ -2922,20 +2923,95 @@ "type": "tidelift" } ], - "time": "2020-08-17T10:01:29+00:00" + "time": "2020-09-02T16:23:27+00:00" + }, + { + "name": "symfony/http-client-contracts", + "version": "v2.2.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/http-client-contracts.git", + "reference": "3a5d0fe7908daaa23e3dbf4cee3ba4bfbb19fdd3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/3a5d0fe7908daaa23e3dbf4cee3ba4bfbb19fdd3", + "reference": "3a5d0fe7908daaa23e3dbf4cee3ba4bfbb19fdd3", + "shasum": "" + }, + "require": { + "php": ">=7.2.5" + }, + "suggest": { + "symfony/http-client-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.2-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\HttpClient\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to HTTP clients", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-09-07T11:33:47+00:00" }, { "name": "symfony/http-foundation", - "version": "v5.1.5", + "version": "v5.1.6", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "41a4647f12870e9d41d9a7d72ff0614a27208558" + "reference": "6cca6b2e4b69fc5bace160d14cf1ee5f71483db4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/41a4647f12870e9d41d9a7d72ff0614a27208558", - "reference": "41a4647f12870e9d41d9a7d72ff0614a27208558", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/6cca6b2e4b69fc5bace160d14cf1ee5f71483db4", + "reference": "6cca6b2e4b69fc5bace160d14cf1ee5f71483db4", "shasum": "" }, "require": { @@ -2997,20 +3073,20 @@ "type": "tidelift" } ], - "time": "2020-08-17T07:48:54+00:00" + "time": "2020-09-13T05:01:27+00:00" }, { "name": "symfony/http-kernel", - "version": "v5.1.5", + "version": "v5.1.6", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "3e32676e6cb5d2081c91a56783471ff8a7f7110b" + "reference": "17227644c3c66dcf32bdfeceff4364d090cd6756" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/3e32676e6cb5d2081c91a56783471ff8a7f7110b", - "reference": "3e32676e6cb5d2081c91a56783471ff8a7f7110b", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/17227644c3c66dcf32bdfeceff4364d090cd6756", + "reference": "17227644c3c66dcf32bdfeceff4364d090cd6756", "shasum": "" }, "require": { @@ -3019,6 +3095,7 @@ "symfony/deprecation-contracts": "^2.1", "symfony/error-handler": "^4.4|^5.0", "symfony/event-dispatcher": "^5.0", + "symfony/http-client-contracts": "^1.1|^2", "symfony/http-foundation": "^4.4|^5.0", "symfony/polyfill-ctype": "^1.8", "symfony/polyfill-php73": "^1.9", @@ -3110,20 +3187,20 @@ "type": "tidelift" } ], - "time": "2020-09-02T08:15:18+00:00" + "time": "2020-09-27T04:33:19+00:00" }, { "name": "symfony/mime", - "version": "v5.1.5", + "version": "v5.1.6", "source": { "type": "git", "url": "https://github.com/symfony/mime.git", - "reference": "89a2c9b4cb7b5aa516cf55f5194c384f444c81dc" + "reference": "4404d6545125863561721514ad9388db2661eec5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/mime/zipball/89a2c9b4cb7b5aa516cf55f5194c384f444c81dc", - "reference": "89a2c9b4cb7b5aa516cf55f5194c384f444c81dc", + "url": "https://api.github.com/repos/symfony/mime/zipball/4404d6545125863561721514ad9388db2661eec5", + "reference": "4404d6545125863561721514ad9388db2661eec5", "shasum": "" }, "require": { @@ -3187,7 +3264,7 @@ "type": "tidelift" } ], - "time": "2020-08-17T10:01:29+00:00" + "time": "2020-09-02T16:23:27+00:00" }, { "name": "symfony/polyfill-ctype", @@ -3971,16 +4048,16 @@ }, { "name": "symfony/process", - "version": "v5.1.5", + "version": "v5.1.6", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "1864216226af21eb76d9477f691e7cbf198e0402" + "reference": "d3a2e64866169586502f0cd9cab69135ad12cee9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/1864216226af21eb76d9477f691e7cbf198e0402", - "reference": "1864216226af21eb76d9477f691e7cbf198e0402", + "url": "https://api.github.com/repos/symfony/process/zipball/d3a2e64866169586502f0cd9cab69135ad12cee9", + "reference": "d3a2e64866169586502f0cd9cab69135ad12cee9", "shasum": "" }, "require": { @@ -4031,20 +4108,20 @@ "type": "tidelift" } ], - "time": "2020-07-23T08:36:24+00:00" + "time": "2020-09-02T16:23:27+00:00" }, { "name": "symfony/routing", - "version": "v5.1.5", + "version": "v5.1.6", "source": { "type": "git", "url": "https://github.com/symfony/routing.git", - "reference": "47b0218344cb6af25c93ca8ee1137fafbee5005d" + "reference": "d36e06eb02a55522a8eed070c1cbc3dc3c389876" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/routing/zipball/47b0218344cb6af25c93ca8ee1137fafbee5005d", - "reference": "47b0218344cb6af25c93ca8ee1137fafbee5005d", + "url": "https://api.github.com/repos/symfony/routing/zipball/d36e06eb02a55522a8eed070c1cbc3dc3c389876", + "reference": "d36e06eb02a55522a8eed070c1cbc3dc3c389876", "shasum": "" }, "require": { @@ -4123,7 +4200,7 @@ "type": "tidelift" } ], - "time": "2020-08-10T08:03:57+00:00" + "time": "2020-09-02T16:23:27+00:00" }, { "name": "symfony/service-contracts", @@ -4203,16 +4280,16 @@ }, { "name": "symfony/string", - "version": "v5.1.5", + "version": "v5.1.6", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "0de4cc1e18bb596226c06a82e2e7e9bc6001a63a" + "reference": "4a9afe9d07bac506f75bcee8ed3ce76da5a9343e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/0de4cc1e18bb596226c06a82e2e7e9bc6001a63a", - "reference": "0de4cc1e18bb596226c06a82e2e7e9bc6001a63a", + "url": "https://api.github.com/repos/symfony/string/zipball/4a9afe9d07bac506f75bcee8ed3ce76da5a9343e", + "reference": "4a9afe9d07bac506f75bcee8ed3ce76da5a9343e", "shasum": "" }, "require": { @@ -4284,20 +4361,20 @@ "type": "tidelift" } ], - "time": "2020-08-17T07:48:54+00:00" + "time": "2020-09-15T12:23:47+00:00" }, { "name": "symfony/translation", - "version": "v5.1.5", + "version": "v5.1.6", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "917b02cdc5f33e0309b8e9d33ee1480b20687413" + "reference": "e3cdd5119b1b5bf0698c351b8ee20fb5a4ea248b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/917b02cdc5f33e0309b8e9d33ee1480b20687413", - "reference": "917b02cdc5f33e0309b8e9d33ee1480b20687413", + "url": "https://api.github.com/repos/symfony/translation/zipball/e3cdd5119b1b5bf0698c351b8ee20fb5a4ea248b", + "reference": "e3cdd5119b1b5bf0698c351b8ee20fb5a4ea248b", "shasum": "" }, "require": { @@ -4376,7 +4453,7 @@ "type": "tidelift" } ], - "time": "2020-08-17T10:01:29+00:00" + "time": "2020-09-27T03:44:28+00:00" }, { "name": "symfony/translation-contracts", @@ -4455,16 +4532,16 @@ }, { "name": "symfony/var-dumper", - "version": "v5.1.5", + "version": "v5.1.6", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "b43a3905262bcf97b2510f0621f859ca4f5287be" + "reference": "c976c115a0d788808f7e71834c8eb0844f678d02" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/b43a3905262bcf97b2510f0621f859ca4f5287be", - "reference": "b43a3905262bcf97b2510f0621f859ca4f5287be", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/c976c115a0d788808f7e71834c8eb0844f678d02", + "reference": "c976c115a0d788808f7e71834c8eb0844f678d02", "shasum": "" }, "require": { @@ -4541,7 +4618,7 @@ "type": "tidelift" } ], - "time": "2020-08-17T07:42:30+00:00" + "time": "2020-09-18T14:27:32+00:00" }, { "name": "tijsverkoyen/css-to-inline-styles", @@ -5606,28 +5683,28 @@ }, { "name": "phpspec/prophecy", - "version": "1.11.1", + "version": "1.12.1", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "b20034be5efcdab4fb60ca3a29cba2949aead160" + "reference": "8ce87516be71aae9b956f81906aaf0338e0d8a2d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/b20034be5efcdab4fb60ca3a29cba2949aead160", - "reference": "b20034be5efcdab4fb60ca3a29cba2949aead160", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/8ce87516be71aae9b956f81906aaf0338e0d8a2d", + "reference": "8ce87516be71aae9b956f81906aaf0338e0d8a2d", "shasum": "" }, "require": { "doctrine/instantiator": "^1.2", - "php": "^7.2", - "phpdocumentor/reflection-docblock": "^5.0", + "php": "^7.2 || ~8.0, <8.1", + "phpdocumentor/reflection-docblock": "^5.2", "sebastian/comparator": "^3.0 || ^4.0", "sebastian/recursion-context": "^3.0 || ^4.0" }, "require-dev": { "phpspec/phpspec": "^6.0", - "phpunit/phpunit": "^8.0" + "phpunit/phpunit": "^8.0 || ^9.0 <9.3" }, "type": "library", "extra": { @@ -5665,7 +5742,7 @@ "spy", "stub" ], - "time": "2020-07-08T12:44:21+00:00" + "time": "2020-09-29T09:10:42+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/database/factories/CommentFactory.php b/database/factories/CommentFactory.php new file mode 100644 index 0000000..44736e5 --- /dev/null +++ b/database/factories/CommentFactory.php @@ -0,0 +1,18 @@ + $this->faker->text(250), + ]; + } +} diff --git a/database/factories/HistoryFactory.php b/database/factories/HistoryFactory.php new file mode 100644 index 0000000..4e15bba --- /dev/null +++ b/database/factories/HistoryFactory.php @@ -0,0 +1,33 @@ +random()->email; + + return [ + 'post_id' => 1, + 'text' => $this->faker->sentence(), + 'user_email' => $randomUserEmail, + ]; + } +} diff --git a/database/factories/NewsFactory.php b/database/factories/NewsFactory.php new file mode 100644 index 0000000..fe94af1 --- /dev/null +++ b/database/factories/NewsFactory.php @@ -0,0 +1,19 @@ + $this->faker->words(2, true), + 'text' => $this->faker->realText($maxNbChars = 1000, $indexSize = 2), + ]; + } +} diff --git a/database/factories/PostFactory.php b/database/factories/PostFactory.php index 07b639f..3c0d340 100644 --- a/database/factories/PostFactory.php +++ b/database/factories/PostFactory.php @@ -5,7 +5,6 @@ use App\Post; use App\User; use Illuminate\Database\Eloquent\Factories\Factory; -use Illuminate\Support\Str; class PostFactory extends Factory { diff --git a/database/migrations/2020_09_07_185537_create_post_tag_table.php b/database/migrations/2020_09_07_185537_create_post_tag_table.php index ca1f0ea..fb99b4f 100644 --- a/database/migrations/2020_09_07_185537_create_post_tag_table.php +++ b/database/migrations/2020_09_07_185537_create_post_tag_table.php @@ -13,13 +13,13 @@ class CreatePostTagTable extends Migration */ public function up() { - Schema::create('post_tag', function (Blueprint $table) { - $table->unsignedBigInteger('post_id'); - $table->unsignedBigInteger('tag_id'); - $table->primary(['post_id', 'tag_id']); - $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade'); - $table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade'); - }); +// Schema::create('post_tag', function (Blueprint $table) { +// $table->unsignedBigInteger('post_id'); +// $table->unsignedBigInteger('tag_id'); +// $table->primary(['post_id', 'tag_id']); +// $table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade'); +// $table->foreign('tag_id')->references('id')->on('tags')->onDelete('cascade'); +// }); } /** @@ -29,6 +29,6 @@ public function up() */ public function down() { - Schema::dropIfExists('post_tag'); +// Schema::dropIfExists('post_tag'); } } diff --git a/database/migrations/2020_10_01_153124_create_news_table.php b/database/migrations/2020_10_01_153124_create_news_table.php new file mode 100644 index 0000000..7c16841 --- /dev/null +++ b/database/migrations/2020_10_01_153124_create_news_table.php @@ -0,0 +1,28 @@ +id(); + $table->string('name', 100); + $table->text('text'); + $table->timestamps(); + }); + } + + public function down() + { + Schema::dropIfExists('news'); + } +} diff --git a/database/migrations/2020_10_06_152240_create_new_tag_table.php b/database/migrations/2020_10_06_152240_create_new_tag_table.php new file mode 100644 index 0000000..af6c2cb --- /dev/null +++ b/database/migrations/2020_10_06_152240_create_new_tag_table.php @@ -0,0 +1,23 @@ +foreignId('new_id')->constrained('news')->onDelete('Cascade'); +// $table->foreignId('tag_id')->constrained('tags')->onDelete('Cascade'); +// +// $table->primary(['new_id', 'tag_id']); +// }); + } + + public function down() + { +// Schema::dropIfExists('new_tag'); + } +} diff --git a/database/migrations/2020_10_08_120022_create_taggables_table.php b/database/migrations/2020_10_08_120022_create_taggables_table.php new file mode 100644 index 0000000..4417a39 --- /dev/null +++ b/database/migrations/2020_10_08_120022_create_taggables_table.php @@ -0,0 +1,32 @@ +foreignId('tag_id')->constrained('tags')->onDelete('Cascade'); + $table->morphs('taggable'); + $table->primary(['tag_id', 'taggable_id', 'taggable_type']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('taggables'); + } +} diff --git a/database/migrations/2020_10_08_143357_create_comments_table.php b/database/migrations/2020_10_08_143357_create_comments_table.php new file mode 100644 index 0000000..458b333 --- /dev/null +++ b/database/migrations/2020_10_08_143357_create_comments_table.php @@ -0,0 +1,33 @@ +id(); + $table->morphs('commentable'); + $table->text('text'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('comments'); + } +} diff --git a/database/migrations/2020_10_09_123904_create_histories_table.php b/database/migrations/2020_10_09_123904_create_histories_table.php new file mode 100644 index 0000000..37eda8a --- /dev/null +++ b/database/migrations/2020_10_09_123904_create_histories_table.php @@ -0,0 +1,35 @@ +id(); + $table->string('user_email'); + $table->text('text'); + $table->timestamps(); + $table->foreignId('post_id')->constrained('posts')->onDelete('cascade'); + $table->foreign('user_email')->references('email')->on('users')->onDelete('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('histories'); + } +} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 0b25e0f..4d60f7d 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -1,10 +1,6 @@ call(\Database\Seeders\NewsTableSeeder::class); $this->call(\Database\Seeders\UsersTableSeeder::class); } } diff --git a/database/seeds/NewsTableSeeder.php b/database/seeds/NewsTableSeeder.php new file mode 100644 index 0000000..815d8df --- /dev/null +++ b/database/seeds/NewsTableSeeder.php @@ -0,0 +1,19 @@ +count(4)->hasTags(2)->hasComments(random_int(1,3))->create(); + } +} diff --git a/database/seeds/UsersTableSeeder.php b/database/seeds/UsersTableSeeder.php index 2f4ab8a..cd271c2 100644 --- a/database/seeds/UsersTableSeeder.php +++ b/database/seeds/UsersTableSeeder.php @@ -2,13 +2,13 @@ namespace Database\Seeders; +use App\News; use App\Permission; use App\Post; use App\Role; use App\Tag; use App\User; use Illuminate\Database\Seeder; -use Illuminate\Support\Facades\Hash; class UsersTableSeeder extends Seeder { @@ -31,9 +31,8 @@ public function run() }); User::factory() - ->has(Post::factory() - ->count(9)) - ->count(2) + ->has(Post::factory()->hasHistory(random_int(0,3))->hasComments(random_int(0,3))->count(9)) + ->count(3) ->create() ->each(function (User $user) use ($registeredRole, $registeredPermissions, $tags) { $user->roles()->attach($registeredRole); @@ -43,5 +42,11 @@ public function run() }); }) ; + + $news = News::all(); + + foreach ($news as $new) { + $new->tags()->attach($tags->random(random_int(0,1))); + } } } diff --git a/resources/views/admin/news.blade.php b/resources/views/admin/news.blade.php new file mode 100644 index 0000000..87624bc --- /dev/null +++ b/resources/views/admin/news.blade.php @@ -0,0 +1,25 @@ +@extends('layouts.app') + +@section('header') + @include('layouts.admin.admin-header') +@endsection + +@section('content') +
+
+
+
+

News

+ + @include('layouts.news.news-items') +
+ + @include('layouts.aside-tags') +
+
+
+@endsection + +@section('footer') + @include('layouts.admin.admin-footer') +@endsection diff --git a/resources/views/admin/posts.blade.php b/resources/views/admin/posts.blade.php index 0b1ca96..8c9ba64 100644 --- a/resources/views/admin/posts.blade.php +++ b/resources/views/admin/posts.blade.php @@ -5,55 +5,19 @@ @endsection @section('content') -
-
-
-

Posts

+
+
+
+
+

Posts

- @if ($posts->count()) -
- @foreach($posts as $post) -
-
-
- Post #{{ $post->id }} + @include('layouts.posts.posts-items') +
-

{{ $post->name }}

- -
{{ $post->created_at->toFormattedDateString() }}
- -

{{ str_limit($post->text, $limit = 100, $end = '...') }}

- - Continue reading -
- -
- - Placeholder - - Thumbnail - -
- -
- Edit - -
- @csrf - @method('DELETE') - -
-
-
-
- @endforeach + @include('layouts.aside-tags') - @else -

No available posts yet

- @endif - - -
+ + @endsection @section('footer') diff --git a/resources/views/components/new-form.blade.php b/resources/views/components/new-form.blade.php new file mode 100644 index 0000000..7312548 --- /dev/null +++ b/resources/views/components/new-form.blade.php @@ -0,0 +1,54 @@ +
+
+ + + +
+ New Name is required. +
+ + @error('name') +
+ {{ $message }} +
+ @enderror +
+ +
+ + + +
+ New Text is required. +
+ + @error('text') +
+ {{ $message }} +
+ @enderror +
+ +
+ + +
+
diff --git a/resources/views/components/post-form.blade.php b/resources/views/components/post-form.blade.php index 88592c0..9e0f978 100644 --- a/resources/views/components/post-form.blade.php +++ b/resources/views/components/post-form.blade.php @@ -73,7 +73,7 @@ class="form-control @error('text') is-invalid @enderror" required="">{{ old('text', $post->text) }}
- Post Description is required. + Post Text is required.
@error('text') diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index 5e72341..ae6065c 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -7,51 +7,25 @@ @section('content')
-
-

Latest posts

+
+
+
+
+

Latest posts

- @if ($posts->count()) -
- @foreach($posts as $post) -
-
-
- Post #{{ $post->id }} + @include('layouts.posts.posts-items') +
-

{{ $post->name }}

+
+

Latest News

-
{{ $post->created_at->toFormattedDateString() }}
- -

{{ str_limit($post->text, $limit = 100, $end = '...') }}

- - @if($post->tags->isNotEmpty()) - - @endif - - Continue reading -
- -
- - Placeholder - - Thumbnail - -
-
-
- @endforeach + @include('layouts.news.news-items') +
+ - @include('layouts.aside-tags') - @else -

No available posts yet

- @endif - + @include('layouts.aside-tags') +
@endsection diff --git a/resources/views/layouts/admin/admin-header.blade.php b/resources/views/layouts/admin/admin-header.blade.php index 2d84ef7..d1dd36f 100644 --- a/resources/views/layouts/admin/admin-header.blade.php +++ b/resources/views/layouts/admin/admin-header.blade.php @@ -21,11 +21,19 @@ + + + + @@ -63,4 +71,6 @@ + + @include('layouts.notifications.flash_messages') diff --git a/resources/views/layouts/aside-tags.blade.php b/resources/views/layouts/aside-tags.blade.php index 1908564..c3a93f8 100644 --- a/resources/views/layouts/aside-tags.blade.php +++ b/resources/views/layouts/aside-tags.blade.php @@ -2,7 +2,7 @@ @if($tagsCloud->isNotEmpty())

Available Tags

- @include('layouts.posts.tags', ['tags' => $tagsCloud]) + @include('layouts.tags.tags', ['tags' => $tagsCloud]) @else

No available tags

@endif diff --git a/resources/views/layouts/base/header.blade.php b/resources/views/layouts/base/header.blade.php index 8dca032..fe458ec 100644 --- a/resources/views/layouts/base/header.blade.php +++ b/resources/views/layouts/base/header.blade.php @@ -17,7 +17,15 @@ @else + + + +