Merge pull request 'make static analyse code for BlogPost, Plan, Recipe and writing tests for BlogPost' (#54) from alex_chevski/eatvio:blogPost into main

Reviewed-on: eatvio/eatvio#54
This commit is contained in:
apoloz
2024-01-11 10:57:51 +00:00
70 changed files with 1006 additions and 392 deletions

View File

@@ -44,7 +44,7 @@ class BlogPostController extends Controller
->cooldown($expiresAt)
->record();
echo view('blog_post/show', $data);
return view('blog_post/show', $data);
}
public function edit(BlogPost $blogPost): View

View File

@@ -5,6 +5,7 @@ namespace App\Livewire\BlogPost\Comment;
use App\Models\BlogPost;
use App\Models\BlogPostComment;
use App\Models\User;
use Illuminate\View\View;
use Livewire\Component;
class Create extends Component
@@ -13,16 +14,16 @@ class Create extends Component
public User $user;
public $body = '';
public string $body = '';
public $grade = 0;
public string|int $grade = 0;
public function render()
public function render(): View
{
return view('livewire.blog-post.comment.create');
}
public function save()
public function save(): void
{
$comment = new BlogPostComment();
$comment->grade = $this->grade;

View File

@@ -3,16 +3,20 @@
namespace App\Livewire\BlogPost\Comment;
use App\Models\BlogPost;
use Illuminate\View\View;
use Livewire\Component;
class Show extends Component
{
public BlogPost $blogPost;
protected $listeners = ['commentAdded' => '$refresh'];
public function render()
public function render(): View
{
return view('livewire.blog-post.comment.show');
}
protected function getListeners(): array
{
return ['commentAdded' => '$refresh'];
}
}

View File

@@ -3,18 +3,19 @@
namespace App\Livewire\BlogPost\Comment;
use App\Models\BlogPostComment;
use Illuminate\View\View;
use Livewire\Component;
class Upvote extends Component
{
public BlogPostComment $comment;
public function mount(BlogPostComment $comment)
public function mount(BlogPostComment $comment): void
{
$this->comment = $comment;
}
public function render()
public function render(): View
{
$upvotes = $this->comment->upvotes()->forBlogPostCommentsUpVote($this->comment)->count();
$downvotes = $this->comment->upvotes()->forBlogPostCommentsDownVote($this->comment)->count();
@@ -30,7 +31,7 @@ class Upvote extends Component
);
}
public function upvote()
public function upvote(): void
{
if ($this->comment->isUpVoted()) {
$this->comment->removeUpVote();
@@ -49,7 +50,7 @@ class Upvote extends Component
]);
}
public function downvote()
public function downvote(): void
{
if ($this->comment->isDownVoted()) {
$this->comment->removeDownVote();

View File

@@ -4,7 +4,10 @@ namespace App\Livewire\BlogPost;
use App\Models\BlogPost;
use App\Models\Tag;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\WithFileUploads;
@@ -12,56 +15,55 @@ class Create extends Component
{
use WithFileUploads;
public $image;
public UploadedFile|null $image = null;
public $state = 'archived';
public string $state = 'archived';
public $title = '';
public string $title = '';
public $description = '';
public string $description = '';
public $tags = [];
public Collection|array $tags = [];
public $videoUrl = '';
public string $videoUrl = '';
protected $listeners = ['parentComponentTagAdded', 'parentComponentTagRemoved'];
public function render()
public function render(): View
{
return view('livewire.blog-post.create');
}
public function parentComponentTagAdded(Tag $tag)
public function parentComponentTagAdded(Tag $tag): void
{
$tagIndex = $tag->id;
$this->tags[$tagIndex] = $tag;
}
public function parentComponentTagRemoved($tag)
public function parentComponentTagRemoved(Tag $tag): void
{
$this->tags = collect($this->tags)
->filter(fn ($curTag) => $curTag['name'] !== $tag)
->all();
}
public function draft()
public function draft(): void
{
$this->state = 'archived';
$this->publish();
}
public function preview()
public function preview(): void
{
$this->state = 'archived';
$this->publish();
}
public function publish()
public function publish(): void
{
$this->validate();
$post = new BlogPost();
$post->image = $this->image->store('blog_posts', 'public');
// $post->image = $this->image->store('blog_posts', 'public');
$post->image = $this->image->store('blog_posts');
$post->state = $this->state;
$post->title = $this->title;
$post->description = $this->description;
@@ -74,10 +76,18 @@ class Create extends Component
$user = Auth::user();
$user->author_of_blog_post()->attach($post->id);
return redirect()->route('blog_post.show', $post->id);
$this->redirectRoute('blog_post.show', $post);
// return redirect()->route('blog_post.show', $post->id);
}
protected function rules()
// protected $listeners = ['parentComponentTagAdded', 'parentComponentTagRemoved'];
protected function getListeners(): array
{
return ['parentComponentTagAdded', 'parentComponentTagRemoved'];
}
protected function rules(): array
{
return [
'image' => 'required|image|max:2048',

View File

@@ -4,7 +4,10 @@ namespace App\Livewire\BlogPost;
use App\Models\BlogPost;
use App\Models\Tag;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\WithFileUploads;
@@ -14,23 +17,21 @@ class Edit extends Component
public BlogPost $blogPost;
public $image;
public string|UploadedFile $image;
public $state = 'archived';
public string $state = 'archived';
public $title = '';
public string $title = '';
public $description = '';
public string $description = '';
public $tags = [];
public Collection|array $tags = [];
public $videoUrl = '';
public string $videoUrl = '';
protected $listeners = ['blogPostTagAdded', 'blogPostTagRemoved'];
public function mount(BlogPost $blogPost)
public function mount(BlogPost $blogPost): void
{
$this->name = $blogPost->name;
// $this->name = $blogPost->name;
$this->image = $blogPost->image;
$this->state = $blogPost->state;
$this->title = $blogPost->title;
@@ -39,13 +40,13 @@ class Edit extends Component
$this->videoUrl = $blogPost->youtube_url;
}
public function parentComponentTagAdded(Tag $tag)
public function parentComponentTagAdded(Tag $tag): void
{
$tagIndex = $tag->id;
$this->tags[$tagIndex] = $tag;
}
public function parentComponentTagRemoved($tag)
public function parentComponentTagRemoved(Tag $tag): void
{
$tagToDetach = Tag::where('name', $tag)->first();
$this->tags = collect($this->tags)
@@ -55,24 +56,24 @@ class Edit extends Component
$this->blogPost->tags()->detach($tagToDetach->id);
}
public function draft()
public function draft(): void
{
$this->state = 'archived';
$this->publish();
}
public function preview()
public function preview(): void
{
$this->state = 'archived';
$this->publish();
}
public function publish()
public function publish(): void
{
$this->validate();
$post = $this->blogPost;
/* $post->image = $this->image->store('blog_posts', 'public'); */
$post->image = ! is_string($this->image) ? $this->image->store('blog_posts') : $this->image;
$post->state = $this->state;
$post->title = $this->title;
$post->description = $this->description;
@@ -88,15 +89,20 @@ class Edit extends Component
$user = Auth::user();
$user->author_of_blog_post()->attach($post->id);
return redirect()->route('blog_post.show', $post->id);
$this->redirectRoute('blog_post.show', $post);
}
public function render()
public function render(): View
{
return view('livewire.blog-post.edit');
}
protected function rules()
protected function getListeners(): array
{
return ['blogPostTagAdded', 'blogPostTagRemoved'];
}
protected function rules(): array
{
return [
/* 'image' => 'required|image|max:2048', */

View File

@@ -3,20 +3,21 @@
namespace App\Livewire\BlogPost;
use App\Models\BlogPost;
use Illuminate\View\View;
use Livewire\Component;
class Like extends Component
{
public BlogPost $blogPost;
public $isIconOnly = false;
public bool $isIconOnly = false;
public function mount(BlogPost $blogPost)
public function mount(BlogPost $blogPost): void
{
$this->blogPost = $blogPost;
}
public function render()
public function render(): View
{
return view('livewire.blog-post.like');
}

View File

@@ -3,24 +3,28 @@
namespace App\Livewire\BlogPost;
use App\Models\BlogPost;
use Illuminate\View\View;
use Livewire\Component;
class LikeCount extends Component
{
public BlogPost $blogPost;
protected $listeners = ['liked' => '$refresh'];
public function mount(BlogPost $blogPost)
public function mount(BlogPost $blogPost): void
{
$this->blogPost = $blogPost;
}
public function render()
public function render(): View
{
return view(
'livewire.blog-post.like-count',
['count' => $this->blogPost->likes_count]
);
}
protected function getListeners(): array
{
return ['liked' => '$refresh'];
}
}

View File

@@ -6,6 +6,7 @@ use App\Models\BlogPost;
use App\Models\Tag;
use App\Models\User;
use Illuminate\Support\Str;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\WithPagination;
@@ -13,22 +14,22 @@ class ListView extends Component
{
use WithPagination;
public $search = '';
public string $search = '';
public $typeFilter = 'all';
public string $typeFilter = 'all';
public $tag = '';
public string $tag = '';
public $author;
public User|null $author = null;
protected $queryString = [
protected array $queryString = [
'search' => ['except' => ''],
'typeFilter' => ['except' => 'all'],
'tag' => ['except' => ''],
'author' => ['except' => ''],
];
public function render()
public function render(): View
{
if ($this->author) {
$author = $this->author;

View File

@@ -3,20 +3,19 @@
namespace App\Livewire\Diet;
use App\Models\Diet;
use Illuminate\View\View;
use Livewire\Component;
class LikeCount extends Component
{
public Diet $diet;
protected $listeners = ['liked' => '$refresh'];
public function mount(Diet $diet)
public function mount(Diet $diet): void
{
$this->diet = $diet;
}
public function render()
public function render(): View
{
return view(
'livewire.diet.like-count',
@@ -25,4 +24,9 @@ class LikeCount extends Component
]
);
}
protected function getListeners(): array
{
return ['liked' => '$refresh'];
}
}

View File

@@ -3,19 +3,20 @@
namespace App\Livewire\Plan;
use App\Models\Plan;
use Illuminate\View\View;
use Livewire\Component;
class Accordion extends Component
{
public Plan $plan;
public $accordionState = ['options1' => true, 'options2' => false, 'options3' => false];
public array $accordionState = ['options1' => true, 'options2' => false, 'options3' => false];
public $options1;
public array $options1;
public $options2;
public array $options2;
public $options3;
public array $options3;
public function mount(Plan $plan): void
{
@@ -38,12 +39,12 @@ class Accordion extends Component
$this->options3['description'] = $plan->packet3_options['description'] ?? '';
}
public function render()
public function render(): View
{
return view('livewire.plan.accordion');
}
public function toggleAccordionState($optionName)
public function toggleAccordionState(string $optionName): void
{
$this->accordionState[$optionName] = ! $this->accordionState[$optionName];

View File

@@ -5,6 +5,7 @@ namespace App\Livewire\Plan\Comment;
use App\Models\Plan;
use App\Models\PlanComment;
use App\Models\User;
use Illuminate\View\View;
use Livewire\Component;
class Create extends Component
@@ -13,23 +14,23 @@ class Create extends Component
public User $user;
public $body = '';
public string $body = '';
public $grade;
public string|int $grade = 0;
public $isChecked = false;
public bool|string $isChecked = false;
public function render()
public function render(): View
{
return view('livewire.plan.comment.create');
}
public function toggle()
public function toggle(): void
{
$this->isChecked = ! $this->isChecked;
}
public function save()
public function save(): void
{
$this->validate([
'body' => 'required|min:3',

View File

@@ -3,6 +3,7 @@
namespace App\Livewire\Plan\Comment;
use App\Models\Plan;
use Illuminate\View\View;
use Livewire\Component;
class Show extends Component
@@ -11,15 +12,26 @@ class Show extends Component
public array $tabpanelState = ['positive' => 'positive', 'negative' => false];
protected $listeners = ['commentAdded' => '$refresh'];
public function render()
public function render(): View
{
return view('livewire.plan.comment.show');
}
public function toggleTabpanelState($tabpanelName)
public function toggleTabpanelState(string $tabpanelName): void
{
array_map(fn ($key) => $key === $tabpanelName ? $this->tabpanelState[$tabpanelName] = $tabpanelName : $this->tabpanelState[$key] = false, array_keys($this->tabpanelState));
collect($this->tabpanelState)->keys()->each(
function ($key) use ($tabpanelName) {
if ($key === $tabpanelName) {
$this->tabpanelState[$tabpanelName] = $tabpanelName;
} else {
$this->tabpanelState[$key] = false;
}
}
);
}
protected function getListeners(): array
{
return ['commentAdded' => '$refresh'];
}
}

View File

@@ -3,18 +3,19 @@
namespace App\Livewire\Plan\Comment;
use App\Models\PlanComment;
use Illuminate\View\View;
use Livewire\Component;
class Upvote extends Component
{
public PlanComment $comment;
public function mount(PlanComment $comment)
public function mount(PlanComment $comment): void
{
$this->comment = $comment;
}
public function render()
public function render(): View
{
$upvotes = $this->comment->upvotes()->forPlanCommentsUpVote($this->comment)->count();
$downvotes = $this->comment->upvotes()->forPlanCommentsDownVote($this->comment)->count();
@@ -30,7 +31,7 @@ class Upvote extends Component
);
}
public function upvote()
public function upvote(): void
{
if ($this->comment->isUpVoted()) {
$this->comment->removeUpVote();
@@ -49,7 +50,7 @@ class Upvote extends Component
]);
}
public function downvote()
public function downvote(): void
{
if ($this->comment->isDownVoted()) {
$this->comment->removeDownVote();

View File

@@ -3,79 +3,81 @@
namespace App\Livewire\Plan;
use App\Models\Plan;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
/* use Tonysm\RichTextLaravel\Livewire\WithRichTexts; */
use Illuminate\View\View;
use Livewire\Component;
use Livewire\WithFileUploads;
class Create extends Component
{
use WithFileUploads;
public $name = '';
public string $name = '';
public $image;
public UploadedFile|null $image = null;
public $duration = '7';
public int|string $duration = 7;
public $state = 'draft';
public string $state = 'draft';
public $type = ['fit' => false, 'slim' => false, 'behavior' => false, 'wellness' => false];
public array $type = ['fit' => false, 'slim' => false, 'behavior' => false, 'wellness' => false];
public $details = '';
public string $details = '';
public $packets_count = 1;
public int $packets_count = 1;
public $packet1_options = [];
public array $packet1_options = [];
public $packet2_options = [];
public array $packet2_options = [];
public $packet3_options = [];
public array $packet3_options = [];
public $packet1_options_input = [];
public array $packet1_options_input = [];
public $packet2_options_input = [];
public array $packet2_options_input = [];
public $packet3_options_input = [];
public array $packet3_options_input = [];
public $input_items_1 = '';
public string $input_items_1 = '';
public $input_items_2 = '';
public string $input_items_2 = '';
public $input_items_3 = '';
public string $input_items_3 = '';
public $isVisibleDuration = false;
public bool $isVisibleDuration = false;
public $isVisibleState = false;
public bool $isVisibleState = false;
public function render()
public function render(): View
{
return view('livewire.plan.create');
}
public function showListDuration()
public function showListDuration(): void
{
$this->isVisibleDuration = ! $this->isVisibleDuration;
}
public function showListState()
public function showListState(): void
{
$this->isVisibleState = ! $this->isVisibleState;
}
public function toggleDuration($duration)
public function toggleDuration(string $duration): void
{
$this->duration = $duration;
$this->isVisibleDuration = false;
}
public function toggleState($state)
public function toggleState(string $state): void
{
$this->state = $state;
$this->isVisibleState = false;
}
public function addPacketOption($options_type, $options_type_input)
public function addPacketOption(array $options_type, array $options_type_input): void
{
$this->$options_type['short'] = $this->$options_type_input['short'];
$this->$options_type['price'] = $this->$options_type_input['price'];
@@ -91,7 +93,7 @@ class Create extends Component
$this->reset('input_items_3');
}
public function publish()
public function publish(): void
{
$this->validate();
@@ -116,19 +118,19 @@ class Create extends Component
$this->redirectRoute('plan.show', $plan);
}
public function addToDrafts()
public function addToDrafts(): void
{
$this->state = 'draft';
$this->publish();
}
public function showPreview()
public function showPreview(): void
{
$this->state = 'unactive';
$this->publish();
}
protected function rules()
protected function rules(): array
{
$rules = [
'name' => 'required|min:3',

View File

@@ -3,6 +3,8 @@
namespace App\Livewire\Plan;
use App\Models\Plan;
use Illuminate\Http\UploadedFile;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\WithFileUploads;
@@ -12,43 +14,43 @@ class Edit extends Component
public Plan $plan;
public $name = '';
public string $name = '';
public $image;
public string|UploadedFile $image = '';
public $duration = '7';
public string|int $duration = '7';
public $state = 'draft';
public string $state = 'draft';
public $type = ['fit' => false, 'slim' => false, 'behavior' => false, 'wellness' => false];
public array $type = ['fit' => false, 'slim' => false, 'behavior' => false, 'wellness' => false];
public $details = '';
public string $details = '';
public $packets_count = 1;
public int $packets_count = 1;
public $packet1_options = [];
public array $packet1_options = [];
public $packet2_options = [];
public array|string $packet2_options = [];
public $packet3_options = [];
public array|string $packet3_options = [];
public $packet1_options_input = [];
public array $packet1_options_input = [];
public $packet2_options_input = [];
public array $packet2_options_input = [];
public $packet3_options_input = [];
public array $packet3_options_input = [];
public $input_items_1 = '';
public string $input_items_1 = '';
public $input_items_2 = '';
public string $input_items_2 = '';
public $input_items_3 = '';
public string $input_items_3 = '';
public $isVisibleDuration = false;
public bool $isVisibleDuration = false;
public $isVisibleState = false;
public bool $isVisibleState = false;
public function mount(Plan $plan)
public function mount(Plan $plan): void
{
$this->plan = $plan;
@@ -96,29 +98,29 @@ class Edit extends Component
// commentsCount
}
public function showListDuration()
public function showListDuration(): void
{
$this->isVisibleDuration = ! $this->isVisibleDuration;
}
public function showListState()
public function showListState(): void
{
$this->isVisibleState = ! $this->isVisibleState;
}
public function toggleDuration($duration)
public function toggleDuration(string $duration): void
{
$this->duration = $duration;
$this->isVisibleDuration = false;
}
public function toggleState($state)
public function toggleState(string $state): void
{
$this->state = $state;
$this->isVisibleState = false;
}
public function addPacketOption($options_type, $options_type_input)
public function addPacketOption(array $options_type, array $options_type_input): void
{
$this->$options_type['short'] = $this->$options_type_input['short'];
$this->$options_type['price'] = $this->$options_type_input['price'];
@@ -135,7 +137,7 @@ class Edit extends Component
$this->reset('input_items_3');
}
public function publish()
public function publish(): void
{
$this->validate();
@@ -158,24 +160,24 @@ class Edit extends Component
$this->redirectRoute('plan.show', $this->plan);
}
public function addToDrafts()
public function addToDrafts(): void
{
$this->state = 'draft';
$this->publish();
}
public function showPreview()
public function showPreview(): void
{
$this->state = 'unactive';
$this->publish();
}
public function render()
public function render(): View
{
return view('livewire.plan.edit');
}
protected function rules()
protected function rules(): array
{
$rules = [
'name' => 'required|min:3',

View File

@@ -3,6 +3,7 @@
namespace App\Livewire\Plan\Like;
use App\Models\Plan;
use Illuminate\View\View;
use Livewire\Attributes\On;
use Livewire\Component;
@@ -10,12 +11,12 @@ class AnnouncementDetails extends Component
{
public Plan $plan;
public function mount(Plan $plan)
public function mount(Plan $plan): void
{
$this->plan = $plan;
}
public function render()
public function render(): View
{
return view('livewire.plan.like.announcement-details');
}

View File

@@ -3,6 +3,7 @@
namespace App\Livewire\Plan\Like;
use App\Models\Plan;
use Illuminate\View\View;
use Livewire\Attributes\On;
use Livewire\Component;
@@ -10,12 +11,12 @@ class AnnouncementFooter extends Component
{
public Plan $plan;
public function mount(Plan $plan)
public function mount(Plan $plan): void
{
$this->plan = $plan;
}
public function render()
public function render(): View
{
return view('livewire.plan.like.announcement-footer');
}

View File

@@ -3,20 +3,19 @@
namespace App\Livewire\Plan;
use App\Models\Plan;
use Illuminate\View\View;
use Livewire\Component;
class LikeCount extends Component
{
public Plan $plan;
protected $listeners = ['liked-details' => '$refresh', 'liked-footer' => '$refresh'];
public function mount(Plan $plan)
public function mount(Plan $plan): void
{
$this->plan = $plan;
}
public function render()
public function render(): View
{
$this->dispatch('liked-details');
$this->dispatch('liked-footer');
@@ -28,4 +27,9 @@ class LikeCount extends Component
]
);
}
protected function getListeners(): array
{
return ['liked-details' => '$refresh', 'liked-footer' => '$refresh'];
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Livewire\Recipe\Comment;
use App\Models\Recipe;
use App\Models\RecipeComment;
use App\Models\User;
use Illuminate\View\View;
use Livewire\Component;
class Create extends Component
@@ -13,23 +14,23 @@ class Create extends Component
public User $user;
public $body = '';
public string $body = '';
public $grade = 0;
public string|int $grade = 0;
public $isChecked = false;
public bool|string $isChecked = false;
public function render()
public function render(): View
{
return view('livewire.recipe.comment.create');
}
public function toggle()
public function toggle(): void
{
$this->isChecked = ! $this->isChecked;
}
public function save()
public function save(): void
{
$this->validate([
'body' => 'required|min:3',

View File

@@ -3,6 +3,7 @@
namespace App\Livewire\Recipe\Comment;
use App\Models\Recipe;
use Illuminate\View\View;
use Livewire\Component;
class Show extends Component
@@ -11,17 +12,28 @@ class Show extends Component
public array $tabpanelState = ['positive' => 'positive', 'negative' => false];
protected $listeners = ['commentAdded' => '$refresh'];
// protected $listeners = ['commentAdded' => '$refresh'];
public function render()
public function render(): View
{
return view('livewire.recipe.comment.show');
}
public function toggleTabpanelState($tabpanelName)
public function toggleTabpanelState(string $tabpanelName): void
{
collect($this->tabpanelState)->keys()->map(fn ($key) => $key === $tabpanelName
? $this->tabpanelState[$tabpanelName] = $tabpanelName
: $this->tabpanelState[$key] = false, array_keys($this->tabpanelState));
collect($this->tabpanelState)->keys()->each(
function ($key) use ($tabpanelName) {
if ($key === $tabpanelName) {
$this->tabpanelState[$tabpanelName] = $tabpanelName;
} else {
$this->tabpanelState[$key] = false;
}
}
);
}
protected function getListeners(): array
{
return ['commentAdded' => '$refresh'];
}
}

View File

@@ -3,18 +3,19 @@
namespace App\Livewire\Recipe\Comment;
use App\Models\RecipeComment;
use Illuminate\View\View;
use Livewire\Component;
class Upvote extends Component
{
public RecipeComment $comment;
public function mount(RecipeComment $comment)
public function mount(RecipeComment $comment): void
{
$this->comment = $comment;
}
public function render()
public function render(): View
{
$upvotes = $this->comment->upvotes()->forRecipeCommentsUpVote($this->comment)->count();
$downvotes = $this->comment->upvotes()->forRecipeCommentsDownVote($this->comment)->count();
@@ -30,7 +31,7 @@ class Upvote extends Component
);
}
public function upvote()
public function upvote(): void
{
if ($this->comment->isUpVoted()) {
$this->comment->removeUpVote();
@@ -49,7 +50,7 @@ class Upvote extends Component
]);
}
public function downvote()
public function downvote(): void
{
if ($this->comment->isDownVoted()) {
$this->comment->removeDownVote();

View File

@@ -4,7 +4,10 @@ namespace App\Livewire\Recipe;
use App\Models\Recipe;
use App\Models\Tag;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use Livewire\Attributes\On;
use Livewire\Component;
use Livewire\WithFileUploads;
@@ -13,45 +16,46 @@ class Create extends Component
{
use WithFileUploads;
public $image;
// public TemporaryUploadedFile $image;
public UploadedFile|null $image = null;
public $state = 'active';
public string $state = 'active';
public $state_ingredient = 'active';
public string $state_ingredient = 'active';
public $state_article = 'active';
public string $state_article = 'active';
public $tags = [];
public array $tags = [];
public $title;
public string $title;
public $type = 'other';
public string $type = 'other';
public $video_url = '';
public string $video_url = '';
public $cooking_time = '10';
public int|string $cooking_time = '10';
public $description = '';
public string $description = '';
public $steps = [['image' => '', 'description' => '']];
public Collection|array $steps = [['image' => '', 'description' => '']];
public $ingredients = [];
public Collection|array $ingredients = [];
public $ingredients_name = '';
public string $ingredients_name = '';
public $ingredients_portion = '';
public string $ingredients_portion = '';
public $ingredients_unit = 'gr';
public string $ingredients_unit = 'gr';
public $state_row = ['ingredient' => 'true', 'article' => 'false'];
protected $listeners = ['stepRemoved' => '$refresh'];
public array $state_row = ['ingredient' => 'true', 'article' => 'false'];
public function toggleStateRow(string $currentRow): void
{
collect($this->state_row)->keys()->map(fn ($key) => $key === $currentRow
collect($this->state_row)->keys()->map(
fn ($key) => $key === $currentRow
? $this->state_row[$currentRow] = 'true'
: $this->state_row[$key] = 'false');
: $this->state_row[$key] = 'false'
);
}
public function addIngredient(): void
@@ -64,19 +68,19 @@ class Create extends Component
$this->reset('ingredients_name', 'ingredients_portion', 'ingredients_unit');
}
public function removeIngredient($i)
public function removeIngredient(int $i): void
{
$newIngredients = collect($this->ingredients)
->forget($i);
$this->ingredients = $newIngredients->toArray();
}
public function addStep()
public function addStep(): void
{
$this->steps[] = ['image' => '', 'description' => ''];
}
public function removeStep($i)
public function removeStep(int $i): void
{
$searchKey = $i - 1;
$newSteps = array_filter(
@@ -92,27 +96,27 @@ class Create extends Component
}
#[On('parentComponentTagAdded')]
public function parentComponentTagAdded(Tag $tag)
public function parentComponentTagAdded(Tag $tag): void
{
$tagIndex = $tag->id;
$this->tags[$tagIndex] = $tag;
}
#[On('parentComponentTagRemoved')]
public function parentComponentTagRemoved($tag)
public function parentComponentTagRemoved(Tag $tag): void
{
$this->tags = collect($this->tags)
->filter(fn ($curTag) => $curTag['name'] !== $tag)
->all();
}
public function draft()
public function draft(): void
{
$this->state = 'archived';
$this->publish();
}
public function preview()
public function preview(): void
{
$this->validate();
@@ -120,11 +124,12 @@ class Create extends Component
$this->publish();
}
public function publish()
public function publish(): void
{
$this->validate();
$recipe = new Recipe();
// $recipe->image = $this->image->store('recipe', 'public');
$recipe->image = $this->image->store('recipe');
$recipe->state = $this->state;
$recipe->type = $this->type;
@@ -145,12 +150,17 @@ class Create extends Component
$this->redirectRoute('recipe.show', $recipe);
}
public function render()
public function render(): View
{
return view('livewire.recipe.create');
}
protected function rules()
protected function getListeners(): array
{
return ['stepRemoved' => '$refresh'];
}
protected function rules(): array
{
return [
'image' => 'required|image|max:2048',
@@ -162,7 +172,7 @@ class Create extends Component
];
}
private function transformSteps($steps)
private function transformSteps(array $steps): array
{
return collect($steps)->map(
function ($step) {

View File

@@ -4,6 +4,9 @@ namespace App\Livewire\Recipe;
use App\Models\Recipe;
use App\Models\Tag;
use Illuminate\Database\Eloquent\Casts\AsCollection;
use Illuminate\Support\Collection;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\WithFileUploads;
@@ -13,43 +16,40 @@ class Edit extends Component
public Recipe $recipe;
public $image;
public string $image;
public $state = 'active';
public string $state = 'active';
public $state_ingredient = 'active';
public string $state_ingredient = 'active';
public $state_article = 'active';
public string $state_article = 'active';
public $type = 'other';
public string $type = 'other';
public $tags;
public Collection $tags;
public $title;
public string $title;
public $video_url;
public string $video_url;
public $cooking_time = '10';
public string|int $cooking_time = '10';
public $description = '';
public string $description = '';
public $steps = [['image' => '', 'description' => '']];
public AsCollection|array|Collection $steps = [['image' => '', 'description' => '']];
public $ingredients = [['name' => '', 'portion' => '']];
public AsCollection|array|Collection $ingredients = [['name' => '', 'portion' => '']];
public $ingredients_name = '';
public string $ingredients_name = '';
public $ingredients_portion = '';
public string $ingredients_portion = '';
public $ingredients_unit = 'gr';
public string $ingredients_unit = 'gr';
public $state_row = ['ingredient' => 'true', 'article' => 'false'];
public array $state_row = ['ingredient' => 'true', 'article' => 'false'];
protected $listeners = ['stepRemoved' => '$refresh', 'parentComponentTagAdded', 'parentComponentTagRemoved'];
public function mount(Recipe $recipe)
public function mount(Recipe $recipe): void
{
$this->name = $recipe->name;
$this->image = $recipe->image;
$this->state = $recipe->state;
$this->type = $recipe->type;
@@ -69,7 +69,7 @@ class Edit extends Component
: $this->state_row[$key] = 'false');
}
public function addIngredient()
public function addIngredient(): void
{
$this->ingredients[] = [
'name' => $this->ingredients_name,
@@ -79,19 +79,19 @@ class Edit extends Component
$this->reset('ingredients_name', 'ingredients_portion', 'ingredients_unit');
}
public function removeIngredient($i)
public function removeIngredient(int $i): void
{
$newIngredients = collect($this->ingredients)
->forget($i);
$this->ingredients = $newIngredients->toArray();
}
public function addStep()
public function addStep(): void
{
$this->steps[] = ['image' => '', 'description' => ''];
}
public function removeStep($i)
public function removeStep(int $i): void
{
if (is_array($this->steps)) {
$steps = $this->steps;
@@ -108,33 +108,34 @@ class Edit extends Component
);
$this->steps = array_values($newSteps);
$this->dispatch('stepRemoved')->self();
}
public function parentComponentTagAdded(Tag $tag)
public function parentComponentTagAdded(Tag $tag): void
{
$this->recipe->tags()->attach($tag['id']);
}
public function parentComponentTagRemoved($tag)
public function parentComponentTagRemoved(Tag $tag): void
{
$selectedTags = Tag::where('name', $tag)->pluck('id');
$this->recipe->tags()->detach($selectedTags);
}
public function draft()
public function draft(): void
{
$this->state = 'archived';
$this->publish();
}
public function preview()
public function preview(): void
{
$this->state = 'archived';
$this->publish();
}
public function publish()
public function publish(): void
{
$this->validate();
@@ -157,12 +158,19 @@ class Edit extends Component
$this->redirectRoute('recipe.show', $recipe);
}
public function render()
public function render(): View
{
return view('livewire.recipe.edit');
}
protected function rules()
// protected $listeners = ['stepRemoved' => '$refresh', 'parentComponentTagAdded', 'parentComponentTagRemoved'];
protected function getListeners(): array
{
return ['stepRemoved' => '$refresh', 'parentComponentTagAdded', 'parentComponentTagRemoved'];
}
protected function rules(): array
{
return [
'image' => 'filled',
@@ -174,7 +182,7 @@ class Edit extends Component
];
}
private function transformSteps($steps)
private function transformSteps(Collection $steps): array
{
return collect($steps)->
map(function ($step) {

View File

@@ -3,20 +3,21 @@
namespace App\Livewire\Recipe;
use App\Models\Recipe;
use Illuminate\View\View;
use Livewire\Component;
class Like extends Component
{
public Recipe $recipe;
public $isIconOnly = false;
public bool $isIconOnly = false;
public function mount(Recipe $recipe)
public function mount(Recipe $recipe): void
{
$this->recipe = $recipe;
}
public function render()
public function render(): View
{
return view('livewire.recipe.like');
}

View File

@@ -3,24 +3,28 @@
namespace App\Livewire\Recipe;
use App\Models\Recipe;
use Illuminate\View\View;
use Livewire\Component;
class LikeCount extends Component
{
public Recipe $recipe;
protected $listeners = ['liked' => '$refresh'];
public function mount(Recipe $recipe)
public function mount(Recipe $recipe): void
{
$this->recipe = $recipe;
}
public function render()
public function render(): View
{
return view(
'livewire.recipe.like-count',
['count' => $this->recipe->likes_count]
);
}
protected function getListeners(): array
{
return ['liked' => '$refresh'];
}
}

View File

@@ -6,6 +6,7 @@ use App\Models\Recipe;
use App\Models\Tag;
use App\Models\User;
use Illuminate\Support\Str;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\WithPagination;
@@ -13,22 +14,22 @@ class ListView extends Component
{
use WithPagination;
public $search = '';
public string $search = '';
public $typeFilter = 'all';
public string $typeFilter = 'all';
public $tag = '';
public string $tag = '';
public $author;
public User|null $author = null;
protected $queryString = [
protected array $queryString = [
'search' => ['except' => ''],
'typeFilter' => ['except' => 'all'],
'tag' => ['except' => ''],
'author' => ['except' => ''],
];
public function render()
public function render(): View
{
if ($this->author) {
$author = $this->author;
@@ -60,7 +61,7 @@ class ListView extends Component
);
}
private function getTagsCollection()
private function getTagsCollection(): array
{
return Recipe::all()->map(
fn ($r) => [

View File

@@ -4,11 +4,13 @@ namespace App\Models;
use CyrildeWit\EloquentViewable\Contracts\Viewable;
use CyrildeWit\EloquentViewable\InteractsWithViews;
/* use Illuminate\Database\Eloquent\Builder; */
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
/* use Illuminate\Database\Eloquent\Casts\Attribute; */
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Support\Str;
/**
* App\Models\BlogPost
@@ -56,17 +58,22 @@ class BlogPost extends Model implements Viewable
{
use HasFactory, InteractsWithViews;
protected $withCount = [
'likes',
'comments',
];
// protected array $withCount = [
// 'likes',
// 'comments',
// ];
public function tags()
public static function getWithLikesAndCommentsCount(): Builder
{
return self::withCount(['likes', 'comments']);
}
public function tags(): MorphToMany
{
return $this->morphToMany(Tag::class, 'taggable');
}
public function author()
public function author(): HasOneThrough
{
return $this
->hasOneThrough(User::class, BlogPostAuthor::class, 'blog_post_id', 'id', 'id', 'user_id')
@@ -79,7 +86,7 @@ class BlogPost extends Model implements Viewable
);
}
public function comments()
public function comments(): HasMany
{
return $this->hasMany(BlogPostComment::class);
}
@@ -89,7 +96,7 @@ class BlogPost extends Model implements Viewable
return $this->hasMany(BlogPostLike::class);
}
public function isLiked(): bool
public function isLiked(): bool|int
{
$curUser = auth()->user();
if ($curUser) {
@@ -109,12 +116,12 @@ class BlogPost extends Model implements Viewable
return false;
}
public function scopeNoEagerLoads($query)
public function scopeNoEagerLoads(Builder $query): Builder
{
return $query->setEagerLoads([]);
}
public function scopeContainsTag($query, $tagString): Builder
public function scopeContainsTag(Builder $query, string $tagString): Builder
{
$tagId = Str::of($tagString)->split('/-/')->first();

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
@@ -39,12 +40,12 @@ class BlogPostComment extends Model
{
use HasFactory;
public function author()
public function author(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
public function blog_post()
public function blog_post(): BelongsTo
{
return $this->belongsTo(BlogPost::class, 'blog_post_id');
}
@@ -54,7 +55,7 @@ class BlogPostComment extends Model
return $this->hasMany(BlogPostCommentUpvote::class, 'blog_post_comment_id');
}
public function isUpVoted(): bool
public function isUpVoted(): bool|int
{
$curUser = auth()->user();
if ($curUser) {
@@ -67,7 +68,7 @@ class BlogPostComment extends Model
return false;
}
public function isDownVoted(): bool
public function isDownVoted(): bool|int
{
$curUser = auth()->user();
if ($curUser) {

View File

@@ -2,8 +2,10 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* App\Models\BlogPostCommentUpvote
@@ -36,28 +38,31 @@ class BlogPostCommentUpvote extends Model
{
use HasFactory;
/**
* @var array<string>
*/
protected $fillable = [
'user_id',
'blog_post_comment_id',
'type',
];
public function author()
public function author(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
public function blog_post_comment()
public function blog_post_comment(): BelongsTo
{
return $this->belongsTo(BlogPostComment::class, 'blog_post_comment_id');
}
public function scopeForBlogPostCommentsUpVote($query, BlogPostComment $comment)
public function scopeForBlogPostCommentsUpVote(Builder $query, BlogPostComment $comment): Builder
{
return $query->where('blog_post_comment_id', $comment->id)->where('type', 'upvote');
}
public function scopeForBlogPostCommentsDownVote($query, BlogPostComment $comment)
public function scopeForBlogPostCommentsDownVote(Builder $query, BlogPostComment $comment): Builder
{
return $query->where('blog_post_comment_id', $comment->id)->where('type', 'downvote');
}

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
/**
* App\Models\BlogPostLike
@@ -30,11 +31,14 @@ class BlogPostLike extends Model
{
use HasFactory;
/**
* @var array<string>
*/
protected $fillable = [
'user_id',
];
public function scopeForBlogPost($query, BlogPost $blogPost)
public function scopeForBlogPost(Builder $query, BlogPost $blogPost): Builder
{
return $query->where('blog_post_id', $blogPost->id);
}

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* App\Models\ChosenPlan
@@ -35,7 +36,7 @@ class ChosenPlan extends Model
{
use HasFactory;
public function user()
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
}

View File

@@ -2,8 +2,10 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* App\Models\CommentUpvote
@@ -42,22 +44,22 @@ class CommentUpvote extends Model
'type',
];
public function plan_comment()
public function plan_comment(): BelongsTo
{
return $this->belongsTo(PlanComment::class, 'comment_id');
}
public function author()
public function author(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
public function scopeForPlanCommentsUpVote($query, PlanComment $comment)
public function scopeForPlanCommentsUpVote(Builder $query, PlanComment $comment): Builder
{
return $query->where('comment_id', $comment->id)->where('type', 'upvote');
}
public function scopeForPlanCommentsDownVote($query, PlanComment $comment)
public function scopeForPlanCommentsDownVote(Builder $query, PlanComment $comment): Builder
{
return $query->where('comment_id', $comment->id)->where('type', 'downvote');
}

View File

@@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Laracasts\Presenter\PresentableTrait;
use Spatie\Sluggable\HasSlug;
@@ -86,35 +87,27 @@ class Plan extends Model implements Viewable
'packet3_options' => 'array',
];
protected $presenter = PlanPresenter::class;
protected string $presenter = PlanPresenter::class;
public function getSlugOptions(): SlugOptions
{
return SlugOptions::create()
->generateSlugsFrom(['name'])
->saveSlugsTo('slug')
// ->slugsShouldBeNoLongerThan(20)
->usingSeparator('_');
// ->usingLanguage('ru')
// ->doNotGenerateSlugsOnUpdate();
}
/**
* Get the route key for the model.
*
* @return string
*/
public function getRouteKeyName()
public function getRouteKeyName(): string
{
return 'slug';
}
public function author()
public function author(): BelongsToMany
{
return $this->belongsToMany(User::class, 'plan_author', 'plan_id', 'user_id');
}
public function comments()
public function comments(): HasMany
{
return $this->hasMany(PlanComment::class);
}
@@ -124,7 +117,7 @@ class Plan extends Model implements Viewable
return $this->hasMany(PlanLike::class);
}
public function isLiked(): bool
public function isLiked(): bool|int
{
if (auth()->user()) {
return auth()->user()->plan_likes()->forPlan($this)->count();
@@ -139,7 +132,6 @@ class Plan extends Model implements Viewable
for ($i = 1; $i <= $this->packets_count; $i++) {
$key = 'packet'.$i.'_options';
// $data = $this->unserializeOptionsObj($this->$key);
$data = $this->$key;
if (! is_null($data)) {
$result = array_merge($result, data_get($data, 'items', []));
@@ -151,7 +143,6 @@ class Plan extends Model implements Viewable
public function types(): Attribute
{
// $data = $this->unserializeOptionsArr($this->type);
$data = $this->type;
return new Attribute(
@@ -164,8 +155,6 @@ class Plan extends Model implements Viewable
$result = 0;
for ($i = 1; $i <= $this->packets_count; $i++) {
$key = 'packet'.$i.'_options';
// dd($this->$key);
// $data = $this->unserializeOptionsObj($this->$key);
$data = $this->$key;
if (! is_null($data)) {
$curPrice = (int) data_get($data, 'price', 0);
@@ -187,31 +176,13 @@ class Plan extends Model implements Viewable
return false;
}
public function scopeNegativeComments(Builder $query)
public function scopeNegativeComments(Builder $query): HasMany
{
return static::comments()->where('grade', '<=', '3');
}
public function scopePositiveComments(Builder $query)
public function scopePositiveComments(Builder $query): HasMany
{
return static::comments()->where('grade', '>', '3');
}
private function unserializeOptionsObj($str)
{
if (preg_match('/^".*"$/', $str)) {
return json_decode(stripslashes(mb_substr($str, 1, -1)));
}
return json_decode(stripslashes($str));
}
private function unserializeOptionsArr($str)
{
if (preg_match('/^".*"$/', $str)) {
return json_decode(stripslashes(mb_substr($str, 1, -1)), true);
}
return json_decode(stripslashes($str), true);
}
}

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
@@ -40,12 +41,12 @@ class PlanComment extends Model
{
use HasFactory;
public function author()
public function author(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
public function plan()
public function plan(): BelongsTo
{
return $this->belongsTo(Plan::class, 'plan_id');
}
@@ -55,7 +56,7 @@ class PlanComment extends Model
return $this->hasMany(CommentUpvote::class, 'comment_id');
}
public function isUpVoted(): bool
public function isUpVoted(): bool|int
{
if (auth()->user()) {
return auth()
@@ -68,7 +69,7 @@ class PlanComment extends Model
return false;
}
public function isDownVoted(): bool
public function isDownVoted(): bool|int
{
if (auth()->user()) {
return auth()

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -34,7 +35,7 @@ class PlanLike extends Model
'user_id',
];
public function scopeForPlan($query, Plan $plan)
public function scopeForPlan(Builder $query, Plan $plan): Builder
{
return $query->where('plan_id', $plan->id);
}

View File

@@ -10,6 +10,8 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Support\Str;
use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions;
@@ -20,9 +22,9 @@ use Spatie\Sluggable\SlugOptions;
* @property string $image public path to image
* @property string $state active/archived
* @property int $cooking_time
* @property AsCollection $ingredients
* @property AsCollection|array $ingredients
* @property string $description
* @property AsCollection $steps
* @property AsCollection|array $steps
* @property string $video_url
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
@@ -93,26 +95,16 @@ class Recipe extends Model implements Viewable
// ->doNotGenerateSlugsOnUpdate();
}
/**
* Get the route key for the model.
*
* @return string
*/
public function getRouteKeyName()
public function getRouteKeyName(): string
{
return 'slug';
}
public function tags()
public function tags(): MorphToMany
{
return $this->morphToMany(Tag::class, 'taggable');
}
/* public function author() */
/* { */
/* return $this->belongsToMany(User::class, 'recipe_author', 'recipe_id', 'user_id'); */
/* } */
public function author(): HasOneThrough
{
return $this
@@ -126,7 +118,7 @@ class Recipe extends Model implements Viewable
);
}
public function comments()
public function comments(): HasMany
{
return $this->hasMany(RecipeComment::class);
}
@@ -136,17 +128,17 @@ class Recipe extends Model implements Viewable
return $this->hasMany(RecipeLike::class);
}
public function scopeNegativeComments(Builder $query)
public function scopeNegativeComments(Builder $query): Builder
{
return static::comments()->where('grade', '<=', '3');
}
public function scopePositiveComments(Builder $query)
public function scopePositiveComments(Builder $query): Builder
{
return static::comments()->where('grade', '>', '3');
}
public function isLiked(): bool
public function isLiked(): bool|int
{
$curUser = auth()->user();
if ($curUser) {
@@ -156,7 +148,7 @@ class Recipe extends Model implements Viewable
return false;
}
public function removeLike(): bool
public function removeLike(): bool|int
{
$curUser = auth()->user();
if ($curUser) {
@@ -166,7 +158,7 @@ class Recipe extends Model implements Viewable
return false;
}
public function scopeContainsTag($query, $tagString): Builder
public function scopeContainsTag(Builder $query, string $tagString): Builder
{
$tagId = Str::of($tagString)->split('/-/')->first();

View File

@@ -4,6 +4,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
@@ -40,12 +41,12 @@ class RecipeComment extends Model
{
use HasFactory;
public function author()
public function author(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
public function recipe()
public function recipe(): BelongsTo
{
return $this->belongsTo(Recipe::class, 'recipe_id');
}
@@ -55,7 +56,7 @@ class RecipeComment extends Model
return $this->hasMany(RecipeCommentUpvote::class, 'recipe_comment_id');
}
public function isUpVoted(): bool
public function isUpVoted(): bool|int
{
$curUser = auth()->user();
if ($curUser) {
@@ -68,7 +69,7 @@ class RecipeComment extends Model
return false;
}
public function isDownVoted(): bool
public function isDownVoted(): bool|int
{
$curUser = auth()->user();
if ($curUser) {
@@ -81,7 +82,7 @@ class RecipeComment extends Model
return false;
}
public function removeUpVote(): bool
public function removeUpVote(): bool|int
{
$curUser = auth()->user();
if ($curUser) {
@@ -94,7 +95,7 @@ class RecipeComment extends Model
return false;
}
public function removeDownVote(): bool
public function removeDownVote(): bool|int
{
$curUser = auth()->user();
if ($curUser) {

View File

@@ -2,8 +2,10 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* App\Models\RecipeCommentUpvote
@@ -42,22 +44,22 @@ class RecipeCommentUpvote extends Model
'type',
];
public function author()
public function author(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
public function recipe_comment()
public function recipe_comment(): BelongsTo
{
return $this->belongsTo(BlogPostComment::class, 'recipe_comment_id');
}
public function scopeForRecipeCommentsUpVote($query, RecipeComment $comment)
public function scopeForRecipeCommentsUpVote(Builder $query, RecipeComment $comment): Builder
{
return $query->where('recipe_comment_id', $comment->id)->where('type', 'upvote');
}
public function scopeForRecipeCommentsDownVote($query, RecipeComment $comment)
public function scopeForRecipeCommentsDownVote(Builder $query, RecipeComment $comment): Builder
{
return $query->where('recipe_comment_id', $comment->id)->where('type', 'downvote');
}

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -34,7 +35,7 @@ class RecipeLike extends Model
'user_id',
];
public function scopeForRecipe($query, Recipe $recipe)
public function scopeForRecipe(Builder $query, Recipe $recipe): Builder
{
return $query->where('recipe_id', $recipe->id);
}

View File

@@ -5,6 +5,7 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Support\Str;
/**
@@ -42,7 +43,7 @@ class Tag extends Model
return $this->morphedByMany(BlogPost::class, 'taggable', 'taggables');
}
public function recipes()
public function recipes(): MorphToMany
{
return $this->morphedByMany(Recipe::class, 'taggable', 'taggables');
}

View File

@@ -2,19 +2,23 @@
namespace App\Presenters;
use App\Models\User;
use Illuminate\Support\Facades\Storage;
use Laracasts\Presenter\Presenter;
/**
* @property User $author
*/
class PlanPresenter extends Presenter
{
public function getAuthorPhoto()
public function getAuthorPhoto(): string
{
$author = $this->getAuthor();
return Storage::url($author->profile_photo_path);
}
public function getAuthor()
public function getAuthor(): User
{
return $this->author->first();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 854 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 254 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 746 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 KiB

View File

@@ -0,0 +1,25 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\BlogPostComment>
*/
class BlogPostCommentFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'grade' => $this->faker->randomDigit(),
'body' => $this->faker->text(),
];
}
}

View File

@@ -5,9 +5,16 @@ namespace Database\Factories;
use App\Models\BlogPost;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use Illuminate\Http\File;
use Illuminate\Support\Facades\Storage;
use App\Models\User;
use Faker\Provider\Youtube;
use Faker\Generator;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\BlogPost>
*
* @property Generator|Youtube $faker
*/
class BlogPostFactory extends Factory
{
@@ -20,28 +27,27 @@ class BlogPostFactory extends Factory
*/
public function definition()
{
$imagePath = storage_path('app/public');
$curImage = $this->faker->image($imagePath.'/blog_posts', 360, 360, 'animals', true, true, 'cats', true, 'jpg');
$curImage = Str::replace($imagePath, '', $curImage);
$faker = \Faker\Factory::create();
$this->faker->addProvider(new Youtube($faker));
return [
'state' => $this->faker->randomElement(['active', 'archived']),
'image' => $curImage,
'image' => $this->generateImageFile('blog_post'),
'description' => $this->faker->realText($this->faker->numberBetween(100, 200)),
'youtube_url' => $this->faker->url(),
'created_at' => $this->faker->dateTimeBetween('-1 week', '+1 week'),
'updated_at' => $this->faker->dateTimeBetween('-1 week', '+1 week'),
'youtube_url' => $this->faker->youtubeRandomUri(),
'title' => $this->faker->realText($this->faker->numberBetween(10, 20)),
];
}
public function some()
private function generateImageFile(string $name): string
{
User::orderBy('created_at', 'desc')->limit(20)->get()->map(function ($user) {
$newBlogPosts = BlogPost::factory()->count(3)->create();
$newBlogPosts->map(function ($post) use ($user) {
$user->author_of_blog_post()->attach($post->id);
});
});
$images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg'];
Storage::fake($name);
$imageFileKey = $this->faker->numberBetween(0, 9);
$imageFilePath = 'database/assets/images/blogPosts/' . $images[$imageFileKey];
$file = new File($imageFilePath);
$fileLocalPath = Storage::putFile($name, $file, 'public');
return $fileLocalPath;
}
}

View File

@@ -6,9 +6,11 @@ use FakerRestaurant\Provider\en_US\Restaurant;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Storage;
use Illuminate\Http\File;
use Faker\Generator;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Plan>
* @property Generator|Restaurant $faker
*/
class PlanFactory extends Factory
{
@@ -16,6 +18,7 @@ class PlanFactory extends Factory
* Define the model's default state.
*
* @return array<string, mixed>
*
*/
public function definition(): array
{
@@ -68,7 +71,7 @@ class PlanFactory extends Factory
];
}
private function generateImageFile(string $name = 'plans')
private function generateImageFile(string $name = 'plans'): string
{
$images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg'];
Storage::fake($name);

View File

@@ -7,7 +7,7 @@ namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PlanComment>
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\RecipeComment>
*/
class RecipeCommentFactory extends Factory
{

View File

@@ -8,9 +8,12 @@ use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Http\File;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Faker\Generator;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Recipe>
*
* @property Generator|Restaurant|Youtube $faker
*/
class RecipeFactory extends Factory
{
@@ -38,7 +41,7 @@ class RecipeFactory extends Factory
];
}
private function generateImageFile(string $name)
private function generateImageFile(string $name): string
{
$images = ['1.jpg', '2.jpg', '3.jpg', '4.jpg', '5.jpg', '6.jpg', '7.jpg', '8.jpg', '9.jpg', '10.jpg'];
Storage::fake($name);
@@ -67,7 +70,7 @@ class RecipeFactory extends Factory
];
}
private function createQuentitySteps($count)
private function createQuentitySteps(int $count): array
{
$result = [];
@@ -78,7 +81,7 @@ class RecipeFactory extends Factory
return $result;
}
private function createQuentityIngredients($count)
private function createQuentityIngredients(int $count): array
{
$result = [];

View File

@@ -3,16 +3,62 @@
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\BlogPost;
use App\Models\User;
use App\Models\BlogPostComment;
use App\Models\Tag;
class BlogPostSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
public function run(): void
{
//
$blogPosts = BlogPost::factory()->count(10)->create();
if (User::count() > 0 && BlogPost::count() > 0) {
$blogPosts->each(
function ($blogPost) {
User::inRandomOrder()
->first()
->author_of_blog_post()
->attach($blogPost->id);
}
);
$comments = BlogPostComment::factory()->count(5)->make();
$comments->each(
static function ($comment): void {
$comment->author()->associate(
User::inRandomOrder()
->first()
->id
);
$comment->blog_post()->associate(
BlogPost::inRandomOrder()
->first()
->id
);
$comment->saveOrFail();
}
);
$blogPosts = BlogPost::all();
$blogPosts->each(
static function ($blogPost): void {
$tags = Tag::factory()->count(5)->create();
$tagsIds = collect($tags)->map(fn($curTag) => $curTag['id']);
$blogPost->tags()->attach($tagsIds);
}
);
}
}
}

View File

@@ -18,5 +18,6 @@ class DatabaseSeeder extends Seeder
$this->call(RecipeAuthor::class);
$this->call(RecipeCommentSeeder::class);
$this->call(RecipeTagSeeder::class);
$this->call(BlogPostSeeder::class);
}
}

View File

@@ -0,0 +1,180 @@
<?php
namespace Tests\Feature\BlogPost;
use App\Livewire\BlogPost\Create;
use App\Models\BlogPost;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\TestCase;
use Illuminate\Http\Testing\File;
class CreateTest extends TestCase
{
use RefreshDatabase;
private File $image;
private BlogPost $blogPost;
protected User $user;
public function setUp(): void
{
$this->refreshApplicationWithLocale('en');
Storage::fake('tmp-for-tests');
$this->image = UploadedFile::fake()->image('blogPost.png');
$this->user = User::factory()->create(['is_consultant' => true]);
$this->blogPost = BlogPost::factory()->make();
}
public function test_show_form_create_blogPost(): void
{
$response = $this
->actingAs($this->user)
->get(route('blog_post.create'));
$response->assertSuccessful();
}
public function test_publish_new_blogPost_success(): void
{
$this->actingAs($this->user);
$blogPostCountAtStart = BlogPost::count();
$testCase = Livewire::test(Create::class)
->set('title', $this->blogPost->title)
->assertSet('title', $this->blogPost->title)
->set('state', $this->blogPost->state)
->assertSet('state', $this->blogPost->state)
->set('image', $this->image)
->set('description', $this->blogPost->description)
->assertSet('description', $this->blogPost->description)
->set('youtube_url', $this->blogPost->youtube_url)
->assertSet('youtube_url', $this->blogPost->youtube_url)
->call('publish')
->assertSuccessful()
->assertHasNoErrors(['title', 'description', 'youtube_url']);
$lastCreatedBlogPost = BlogPost::orderBy('id', 'desc')->first();
$newBlogPostUrl = route('blog_post.show', $lastCreatedBlogPost);
$testCase->assertRedirect($newBlogPostUrl);
Storage::disk('tmp-for-tests')->assertExists($lastCreatedBlogPost->image);
$this->assertEquals($blogPostCountAtStart + 1, BlogPost::count());
$response = $this->actingAs($this->user)->get(route('blog_post.index'));
$response->assertSuccessful();
}
public function test_to_draft_new_blogPost_success(): void
{
$this->actingAs($this->user);
$blogPostCountAtStart = BlogPost::count();
$testCase = Livewire::test(Create::class)
->set('title', $this->blogPost->title)
->assertSet('title', $this->blogPost->title)
->set('state', $this->blogPost->state)
->assertSet('state', $this->blogPost->state)
->set('image', $this->image)
->set('description', $this->blogPost->description)
->assertSet('description', $this->blogPost->description)
->set('youtube_url', $this->blogPost->youtube_url)
->assertSet('youtube_url', $this->blogPost->youtube_url)
->call('draft')
->assertSuccessful()
->assertHasNoErrors(['title', 'description', 'youtube_url']);
self::assertEquals('archived', $testCase->state);
$lastCreatedBlogPost = BlogPost::orderBy('id', 'desc')->first();
$newBlogPostUrl = route('blog_post.show', $lastCreatedBlogPost);
$testCase->assertRedirect($newBlogPostUrl);
Storage::disk('tmp-for-tests')->assertExists($lastCreatedBlogPost->image);
$this->assertEquals($blogPostCountAtStart + 1, BlogPost::count());
$response = $this->actingAs($this->user)->get(route('blog_post.index'));
$response->assertSuccessful();
}
public function test_to_preview_new_blogPost_success(): void
{
$this->actingAs($this->user);
$blogPostCountAtStart = BlogPost::count();
$testCase = Livewire::test(Create::class)
->set('title', $this->blogPost->title)
->assertSet('title', $this->blogPost->title)
->set('state', $this->blogPost->state)
->assertSet('state', $this->blogPost->state)
->set('image', $this->image)
->set('description', $this->blogPost->description)
->assertSet('description', $this->blogPost->description)
->set('youtube_url', $this->blogPost->youtube_url)
->assertSet('youtube_url', $this->blogPost->youtube_url)
->call('preview')
->assertSuccessful()
->assertHasNoErrors(['title', 'description', 'youtube_url']);
self::assertEquals('archived', $testCase->state);
$lastCreatedBlogPost = BlogPost::orderBy('id', 'desc')->first();
$newBlogPostUrl = route('blog_post.show', $lastCreatedBlogPost);
$testCase->assertRedirect($newBlogPostUrl);
Storage::disk('tmp-for-tests')->assertExists($lastCreatedBlogPost->image);
$this->assertEquals($blogPostCountAtStart + 1, BlogPost::count());
$response = $this->actingAs($this->user)->get(route('blog_post.index'));
$response->assertSuccessful();
}
public function test_set_empty_data(): void
{
$this->actingAs($this->user);
$blogPostCountAtStart = BlogPost::count();
Livewire::test(Create::class)
->set('title', null)
->assertSet('title', null)
->set('state', null)
->assertSet('state', null)
->set('image', null)
->set('description', null)
->assertSet('description', null)
->set('youtube_url', null)
->assertSet('youtube_url', null)
->call('publish')
->assertSuccessful()
->assertHasErrors(['image', 'description']);
$this->assertEquals($blogPostCountAtStart, BlogPost::count());
}
}

View File

@@ -0,0 +1,195 @@
<?php
namespace Tests\Feature\BlogPost;
use App\Models\BlogPost;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\TestCase;
use App\Livewire\BlogPost\Edit;
class EditTest extends TestCase
{
use RefreshDatabase;
private UploadedFile $image;
private BlogPost $blogPost;
protected User $user;
public function setUp(): void
{
$this->refreshApplicationWithLocale('en');
Storage::fake('tmp-for-tests');
$this->image = UploadedFile::fake()->image('blogPost.png');
$this->user = User::factory()->create(['is_consultant' => true]);
$this->blogPost = BlogPost::factory()->create();
}
public function test_show_form_edit_blogPost(): void
{
$response = $this
->actingAs($this->user)
->get(route('blog_post.edit', $this->blogPost));
$response->assertSuccessful();
}
public function test_publish_new_blogPost_success(): void
{
$this->actingAs($this->user);
$updatedBlogPostBeforeToAddDatabase = BlogPost::factory()->make();
$testCase = Livewire::test(
Edit::class, [
'blogPost' => $this->blogPost,
]
)
->set('title', $updatedBlogPostBeforeToAddDatabase->title)
->assertSet('title', $updatedBlogPostBeforeToAddDatabase->title)
->set('state', $updatedBlogPostBeforeToAddDatabase->state)
->assertSet('state', $updatedBlogPostBeforeToAddDatabase->state)
->set('image', $this->image)
->set('description', $updatedBlogPostBeforeToAddDatabase->description)
->assertSet('description', $updatedBlogPostBeforeToAddDatabase->description)
->set('youtube_url', $updatedBlogPostBeforeToAddDatabase->youtube_url)
->assertSet('youtube_url', $updatedBlogPostBeforeToAddDatabase->youtube_url)
->call('publish')
->assertSuccessful()
->assertHasNoErrors(['title', 'state', 'description', 'youtube_url']);
$updatedBlogPostAfterToAddDatabase = BlogPost::orderByDesc('id')->first();
$newBlogPostUrl = route('blog_post.show', $updatedBlogPostAfterToAddDatabase);
Storage::disk('tmp-for-tests')->assertExists($updatedBlogPostAfterToAddDatabase->image);
// check data after update recipe
self::assertEquals($updatedBlogPostBeforeToAddDatabase->title, $updatedBlogPostAfterToAddDatabase->title);
self::assertEquals($updatedBlogPostBeforeToAddDatabase->state, $updatedBlogPostAfterToAddDatabase->state);
self::assertEquals($updatedBlogPostBeforeToAddDatabase->description, $updatedBlogPostAfterToAddDatabase->description);
// self::assertEquals($updatedBlogPostBeforeToAddDatabase->youtube_url, $updatedBlogPostAfterToAddDatabase->youtube_url);
$testCase->assertRedirect($newBlogPostUrl);
}
public function test_to_draft_new_blogPost_success(): void
{
$this->actingAs($this->user);
$updatedBlogPostBeforeToAddDatabase = BlogPost::factory()->make();
$testCase = Livewire::test(
Edit::class, [
'blogPost' => $this->blogPost,
]
)
->set('title', $updatedBlogPostBeforeToAddDatabase->title)
->assertSet('title', $updatedBlogPostBeforeToAddDatabase->title)
->set('state', $updatedBlogPostBeforeToAddDatabase->state)
->assertSet('state', $updatedBlogPostBeforeToAddDatabase->state)
->set('image', $this->image)
->set('description', $updatedBlogPostBeforeToAddDatabase->description)
->assertSet('description', $updatedBlogPostBeforeToAddDatabase->description)
->set('youtube_url', $updatedBlogPostBeforeToAddDatabase->youtube_url)
->assertSet('youtube_url', $updatedBlogPostBeforeToAddDatabase->youtube_url)
->call('draft')
->assertSuccessful()
->assertHasNoErrors(['title', 'state', 'description', 'youtube_url']);
$updatedBlogPostAfterToAddDatabase = BlogPost::orderByDesc('id')->first();
$newBlogPostUrl = route('blog_post.show', $updatedBlogPostAfterToAddDatabase);
Storage::disk('tmp-for-tests')->assertExists($updatedBlogPostAfterToAddDatabase->image);
// check data after update recipe
self::assertEquals($updatedBlogPostBeforeToAddDatabase->title, $updatedBlogPostAfterToAddDatabase->title);
self::assertEquals('archived', $updatedBlogPostAfterToAddDatabase->state);
self::assertEquals($updatedBlogPostBeforeToAddDatabase->description, $updatedBlogPostAfterToAddDatabase->description);
// self::assertEquals($updatedBlogPostBeforeToAddDatabase->youtube_url, $updatedBlogPostAfterToAddDatabase->youtube_url);
$testCase->assertRedirect($newBlogPostUrl);
}
public function test_to_preview_new_blogPost_success(): void
{
$this->actingAs($this->user);
$updatedBlogPostBeforeToAddDatabase = BlogPost::factory()->make();
$testCase = Livewire::test(
Edit::class, [
'blogPost' => $this->blogPost,
]
)
->set('title', $updatedBlogPostBeforeToAddDatabase->title)
->assertSet('title', $updatedBlogPostBeforeToAddDatabase->title)
->set('state', $updatedBlogPostBeforeToAddDatabase->state)
->assertSet('state', $updatedBlogPostBeforeToAddDatabase->state)
->set('image', $this->image)
->set('description', $updatedBlogPostBeforeToAddDatabase->description)
->assertSet('description', $updatedBlogPostBeforeToAddDatabase->description)
->set('youtube_url', $updatedBlogPostBeforeToAddDatabase->youtube_url)
->assertSet('youtube_url', $updatedBlogPostBeforeToAddDatabase->youtube_url)
->call('preview')
->assertSuccessful()
->assertHasNoErrors(['title', 'state', 'description', 'youtube_url']);
$updatedBlogPostAfterToAddDatabase = BlogPost::orderByDesc('id')->first();
$newBlogPostUrl = route('blog_post.show', $updatedBlogPostAfterToAddDatabase);
Storage::disk('tmp-for-tests')->assertExists($updatedBlogPostAfterToAddDatabase->image);
// check data after update recipe
self::assertEquals($updatedBlogPostBeforeToAddDatabase->title, $updatedBlogPostAfterToAddDatabase->title);
self::assertEquals('archived', $updatedBlogPostAfterToAddDatabase->state);
self::assertEquals($updatedBlogPostBeforeToAddDatabase->description, $updatedBlogPostAfterToAddDatabase->description);
// self::assertEquals($updatedBlogPostBeforeToAddDatabase->youtube_url, $updatedBlogPostAfterToAddDatabase->youtube_url);
$testCase->assertRedirect($newBlogPostUrl);
}
public function testNothingChange(): void
{
$this->actingAs($this->user);
$blogPostUpdate = Livewire::test(
Edit::class, [
'blogPost' => $this->blogPost,
]
)
->call('publish')
->assertSuccessful()
->assertHasNoErrors(['title', 'state', 'description', 'youtube_url']);
$newBlogPostUrl = route('blog_post.show', $this->blogPost, false);
Storage::disk('tmp-for-tests')->assertMissing($blogPostUpdate->image);
// check data after update recipe
self::assertEquals($this->blogPost->title, $blogPostUpdate->title);
self::assertEquals($this->blogPost->state, $blogPostUpdate->state);
self::assertEquals($this->blogPost->description, $blogPostUpdate->description);
// self::assertEquals($this->blogPost->youtube_url, $blogPostUpdate->youtube_url);
$blogPostUpdate->assertRedirect($newBlogPostUrl);
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Tests\Feature\BlogPost;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class IndexTest extends TestCase
{
use RefreshDatabase;
protected User $user;
public function setUp(): void
{
$this->refreshApplicationWithLocale('en');
$this->user = User::factory()->create(['is_consultant' => true]);
}
public function test_index_page_success(): void
{
$response = $this
->actingAs($this->user)
->get(route('blog_post.index'));
$response
->assertOk();
}
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Tests\Feature\BlogPost;
use Tests\TestCase;
use App\Models\User;
use App\Models\BlogPost;
use Illuminate\Foundation\Testing\RefreshDatabase;
class ShowTest extends TestCase
{
use RefreshDatabase;
private BlogPost $blogPost;
protected User $user;
public function setUp(): void
{
$this->refreshApplicationWithLocale('en');
$this->user = User::inRandomOrder()->first();
$this->blogPost = BlogPost::inRandomOrder()->first();
}
public function test_show_page_success(): void
{
$response = $this->actingAs($this->user)
->get(route('blog_post.show', $this->blogPost));
$response
->assertOk();
}
}

View File

@@ -4,21 +4,21 @@ namespace Tests\Feature\Plan;
use App\Livewire\Plan\Create;
use App\Models\Plan;
// use Livewire\WithFileUploads;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\TestCase;
use Illuminate\Http\Testing\File;
class CreateTest extends TestCase
{
use RefreshDatabase;
private $image;
private File $image;
private $plan;
private Plan $plan;
protected User $user;
@@ -34,7 +34,7 @@ class CreateTest extends TestCase
}
public function test_show_form_create_plan()
public function test_show_form_create_plan(): void
{
$response = $this
->actingAs($this->user)
@@ -76,7 +76,7 @@ class CreateTest extends TestCase
$lastCreatedPlan = Plan::orderBy('id', 'desc')->first();
$newPlanUrl = route('plan.show', $lastCreatedPlan, false);
$newPlanUrl = route('plan.show', $lastCreatedPlan);
$testCase->assertRedirect($newPlanUrl);
@@ -137,6 +137,7 @@ class CreateTest extends TestCase
$planCountAtStart = Plan::count();
$testCase = Livewire::test(Create::class)
->set('name', $this->plan->name)
->assertSet('name', $this->plan->name)
@@ -190,7 +191,7 @@ class CreateTest extends TestCase
->set('packet2_options', null)
->set('packet3_options', null)
->call('publish')
->assertHasErrors(['name', 'image', 'duration', 'details']);
->assertHasErrors(['name', 'image', 'details']);
$this->assertEquals($planCountAtStart, Plan::count());
}

View File

@@ -15,7 +15,7 @@ class EditTest extends TestCase
{
use RefreshDatabase;
private $image;
private UploadedFile $image;
private Plan $plan;
@@ -32,7 +32,7 @@ class EditTest extends TestCase
$this->plan = Plan::factory()->create();
}
public function test_show_form_edit_plan()
public function test_show_form_edit_plan(): void
{
$response = $this
->actingAs($this->user)
@@ -75,7 +75,7 @@ class EditTest extends TestCase
$updatedPlanAfterToAddDatabase = Plan::orderByDesc('id')->first();
$newPlanUrl = route('plan.show', $updatedPlanAfterToAddDatabase, false);
$newPlanUrl = route('plan.show', $updatedPlanAfterToAddDatabase);
Storage::disk('tmp-for-tests')->assertExists($updatedPlanAfterToAddDatabase->image);

View File

@@ -11,7 +11,7 @@ class IndexTest extends TestCase
{
use RefreshDatabase;
private $plan;
public Plan $plan;
protected User $user;
@@ -23,7 +23,7 @@ class IndexTest extends TestCase
$this->plan = Plan::inRandomOrder()->first();
}
public function test_index_page_success()
public function test_index_page_success(): void
{
$response = $this
->actingAs($this->user)

View File

@@ -14,7 +14,7 @@ class ShowTest extends TestCase
// use RefreshDatabase;
use RefreshDatabase;
private $plan;
private Plan $plan;
protected User $user;
@@ -26,7 +26,7 @@ class ShowTest extends TestCase
$this->plan = Plan::inRandomOrder()->first();
}
public function test_show_page_success()
public function test_show_page_success(): void
{
$response = $this->actingAs($this->user)
->get(route('plan.show', $this->plan, false));

View File

@@ -10,6 +10,7 @@ use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\TestCase;
use Illuminate\Http\Testing\File;
/**
* @internal
@@ -22,9 +23,7 @@ final class CreateTest extends TestCase
private Recipe $recipe;
private $image;
private $steps;
private File $image;
public function setUp(): void
{
@@ -114,7 +113,7 @@ final class CreateTest extends TestCase
$newRecipeUrl = route('recipe.show', $lastCreatedRecipe, false);
Storage::disk('tmp-for-tests')->assertExists($lastCreatedRecipe->image);
// Storage::disk('tmp-for-tests')->assertExists($lastCreatedRecipe->image);
$testCase->assertRedirect($newRecipeUrl);
@@ -153,7 +152,7 @@ final class CreateTest extends TestCase
$newRecipeUrl = route('recipe.show', $lastCreatedRecipe, false);
Storage::disk('tmp-for-tests')->assertExists($lastCreatedRecipe->image);
// Storage::disk('tmp-for-tests')->assertExists($lastCreatedRecipe->image);
$testCase->assertRedirect($newRecipeUrl);
@@ -177,7 +176,7 @@ final class CreateTest extends TestCase
->set('type', null)
->set('description', null)
->call('publish')
->assertHasErrors(['image', 'state', 'type', 'description']);
->assertHasErrors(['image', 'description']);
// doesnt to add to database
self::assertEquals($count, Recipe::count());

View File

@@ -11,7 +11,7 @@ class IndexTest extends TestCase
{
use RefreshDatabase;
private Recipe $recipe;
public Recipe $recipe;
protected User $user;
@@ -23,7 +23,7 @@ class IndexTest extends TestCase
$this->recipe = Recipe::inRandomOrder()->first();
}
public function test_index_page_success()
public function test_index_page_success(): void
{
$response = $this
->actingAs($this->user)

View File

@@ -23,7 +23,7 @@ class ShowTest extends TestCase
$this->recipe = Recipe::inRandomOrder()->first();
}
public function test_show_page_success()
public function test_show_page_success(): void
{
$response = $this->actingAs($this->user)
->get(route('recipe.show', $this->recipe, false));