Skip to content

Commit b68dff6

Browse files
committed
Finalizando Detalhes Conteudo & Iniciando Upload de Videos
1 parent 9bf8c58 commit b68dff6

File tree

12 files changed

+354
-23
lines changed

12 files changed

+354
-23
lines changed

app/Livewire/Forms/ContentForm.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
namespace App\Livewire\Forms;
44

55
use App\Models\Content;
6+
use Illuminate\Support\Facades\Storage;
67
use Livewire\Attributes\Validate;
78
use Livewire\Form;
89
use Livewire\Attributes\Rule;
910

1011
class ContentForm extends Form
1112
{
12-
#[Rule('required|min:30')]
13+
#[Rule('required|min:10')]
1314
public string $title;
1415

1516
#[Rule('nullable|min:30')]
@@ -21,14 +22,17 @@ class ContentForm extends Form
2122
#[Rule('required')]
2223
public string $slug;
2324

24-
public string $cover;
25+
#[Rule('nullable|image')]
26+
public $cover;
2527

2628
#[Rule('required')]
2729
public string $status = 'DRAFT';
2830

2931
#[Rule('required')]
3032
public string $type = 'MOVIE';
3133

34+
public ?string $coverReal;
35+
3236
public function setContent(Content $content)
3337
{
3438
$this->title = $content->title;
@@ -37,6 +41,7 @@ public function setContent(Content $content)
3741
$this->type = $content->type;
3842
$this->status = $content->status;
3943
$this->slug = $content->slug;
44+
$this->coverReal = $content->cover;
4045
}
4146

4247
public function save(): bool
@@ -45,6 +50,7 @@ public function save(): bool
4550

4651
$data = $this->all();
4752
$data['code'] = str()->uuid();
53+
$data['cover'] = $data['cover']?->store('contents', 'public');
4854

4955
Content::create($data);
5056

@@ -56,9 +62,17 @@ public function update(int $content): bool
5662
$this->validate();
5763

5864
$data = $this->all();
59-
6065
$content = Content::find($content);
6166

67+
if($data['cover']) {
68+
$disk = Storage::disk('public');
69+
70+
if($content->cover && $disk->exists($content->cover))
71+
$disk->delete($content->cover);
72+
73+
$data['cover'] = $data['cover']->store('contents', 'public');
74+
}
75+
6276
return $content->update($data);
6377
}
6478
}

app/Livewire/Media/CreateContent.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
use App\Livewire\Forms\ContentForm;
66
use Livewire\Component;
7+
use Livewire\WithFileUploads;
78

89
class CreateContent extends Component
910
{
11+
use WithFileUploads;
12+
1013
public $labelButton = 'Criar Conteúdo';
1114

1215
public ContentForm $form;

app/Livewire/Media/EditContent.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
use App\Livewire\Forms\ContentForm;
66
use App\Models\Content;
7-
use Livewire\Component;
7+
use Livewire\{WithFileUploads, Component};
88

99
class EditContent extends Component
1010
{
11+
use WithFileUploads;
12+
1113
public $content;
1214

1315
public $labelButton = 'Atualizar Conteúdo';

app/Livewire/Media/RemoveContent.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Livewire\Media;
44

55
use App\Models\Content;
6+
use Illuminate\Support\Facades\Storage;
67
use Livewire\Component;
78

89
class RemoveContent extends Component
@@ -17,9 +18,14 @@ public function mount(int $content)
1718
public function remove()
1819
{
1920
$content = Content::findOrFail($this->content);
21+
22+
$disk = Storage::disk('public');
23+
if($disk->exists($content->cover)) $disk->delete($content->cover);
24+
2025
$content->delete();
2126

22-
$this->dispatch('content_removed_' . $this->content);
27+
session()->flash('success', 'Conteúdo removido com sucesso!');
28+
return redirect()->route('media.contents.index');
2329
}
2430

2531
public function render()

app/Livewire/Media/VideoUpload.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace App\Livewire\Media;
4+
5+
use Livewire\{WithFileUploads, Component};
6+
7+
class VideoUpload extends Component
8+
{
9+
use WithFileUploads;
10+
11+
public $videos;
12+
13+
public function storeVideos()
14+
{
15+
dd($this->videos);
16+
}
17+
18+
public function render()
19+
{
20+
return view('livewire.media.video-upload');
21+
}
22+
}

config/livewire.php

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|---------------------------------------------------------------------------
7+
| Class Namespace
8+
|---------------------------------------------------------------------------
9+
|
10+
| This value sets the root class namespace for Livewire component classes in
11+
| your application. This value will change where component auto-discovery
12+
| finds components. It's also referenced by the file creation commands.
13+
|
14+
*/
15+
16+
'class_namespace' => 'App\\Livewire',
17+
18+
/*
19+
|---------------------------------------------------------------------------
20+
| View Path
21+
|---------------------------------------------------------------------------
22+
|
23+
| This value is used to specify where Livewire component Blade templates are
24+
| stored when running file creation commands like `artisan make:livewire`.
25+
| It is also used if you choose to omit a component's render() method.
26+
|
27+
*/
28+
29+
'view_path' => resource_path('views/livewire'),
30+
31+
/*
32+
|---------------------------------------------------------------------------
33+
| Layout
34+
|---------------------------------------------------------------------------
35+
| The view that will be used as the layout when rendering a single component
36+
| as an entire page via `Route::get('/post/create', CreatePost::class);`.
37+
| In this case, the view returned by CreatePost will render into $slot.
38+
|
39+
*/
40+
41+
'layout' => 'components.layouts.app',
42+
43+
/*
44+
|---------------------------------------------------------------------------
45+
| Lazy Loading Placeholder
46+
|---------------------------------------------------------------------------
47+
| Livewire allows you to lazy load components that would otherwise slow down
48+
| the initial page load. Every component can have a custom placeholder or
49+
| you can define the default placeholder view for all components below.
50+
|
51+
*/
52+
53+
'lazy_placeholder' => null,
54+
55+
/*
56+
|---------------------------------------------------------------------------
57+
| Temporary File Uploads
58+
|---------------------------------------------------------------------------
59+
|
60+
| Livewire handles file uploads by storing uploads in a temporary directory
61+
| before the file is stored permanently. All file uploads are directed to
62+
| a global endpoint for temporary storage. You may configure this below:
63+
|
64+
*/
65+
66+
'temporary_file_upload' => [
67+
'disk' => null, // Example: 'local', 's3' | Default: 'default'
68+
'rules' => ['required', 'file', 'max:204800'], // Example: ['file', 'mimes:png,jpg'] | Default: ['required', 'file', 'max:12288'] (12MB)
69+
'directory' => null, // Example: 'tmp' | Default: 'livewire-tmp'
70+
'middleware' => null, // Example: 'throttle:5,1' | Default: 'throttle:60,1'
71+
'preview_mimes' => [ // Supported file types for temporary pre-signed file URLs...
72+
'png', 'gif', 'bmp', 'svg', 'wav', 'mp4',
73+
'mov', 'avi', 'wmv', 'mp3', 'm4a',
74+
'jpg', 'jpeg', 'mpga', 'webp', 'wma',
75+
],
76+
'max_upload_time' => 5, // Max duration (in minutes) before an upload is invalidated...
77+
'cleanup' => true, // Should cleanup temporary uploads older than 24 hrs...
78+
],
79+
80+
/*
81+
|---------------------------------------------------------------------------
82+
| Render On Redirect
83+
|---------------------------------------------------------------------------
84+
|
85+
| This value determines if Livewire will run a component's `render()` method
86+
| after a redirect has been triggered using something like `redirect(...)`
87+
| Setting this to true will render the view once more before redirecting
88+
|
89+
*/
90+
91+
'render_on_redirect' => false,
92+
93+
/*
94+
|---------------------------------------------------------------------------
95+
| Eloquent Model Binding
96+
|---------------------------------------------------------------------------
97+
|
98+
| Previous versions of Livewire supported binding directly to eloquent model
99+
| properties using wire:model by default. However, this behavior has been
100+
| deemed too "magical" and has therefore been put under a feature flag.
101+
|
102+
*/
103+
104+
'legacy_model_binding' => false,
105+
106+
/*
107+
|---------------------------------------------------------------------------
108+
| Auto-inject Frontend Assets
109+
|---------------------------------------------------------------------------
110+
|
111+
| By default, Livewire automatically injects its JavaScript and CSS into the
112+
| <head> and <body> of pages containing Livewire components. By disabling
113+
| this behavior, you need to use @livewireStyles and @livewireScripts.
114+
|
115+
*/
116+
117+
'inject_assets' => true,
118+
119+
/*
120+
|---------------------------------------------------------------------------
121+
| Navigate (SPA mode)
122+
|---------------------------------------------------------------------------
123+
|
124+
| By adding `wire:navigate` to links in your Livewire application, Livewire
125+
| will prevent the default link handling and instead request those pages
126+
| via AJAX, creating an SPA-like effect. Configure this behavior here.
127+
|
128+
*/
129+
130+
'navigate' => [
131+
'show_progress_bar' => true,
132+
'progress_bar_color' => '#2299dd',
133+
],
134+
135+
/*
136+
|---------------------------------------------------------------------------
137+
| HTML Morph Markers
138+
|---------------------------------------------------------------------------
139+
|
140+
| Livewire intelligently "morphs" existing HTML into the newly rendered HTML
141+
| after each update. To make this process more reliable, Livewire injects
142+
| "markers" into the rendered Blade surrounding @if, @class & @foreach.
143+
|
144+
*/
145+
146+
'inject_morph_markers' => true,
147+
148+
/*
149+
|---------------------------------------------------------------------------
150+
| Pagination Theme
151+
|---------------------------------------------------------------------------
152+
|
153+
| When enabling Livewire's pagination feature by using the `WithPagination`
154+
| trait, Livewire will use Tailwind templates to render pagination views
155+
| on the page. If you want Bootstrap CSS, you can specify: "bootstrap"
156+
|
157+
*/
158+
159+
'pagination_theme' => 'tailwind',
160+
];

resources/views/livewire/media/create-content.blade.php

Lines changed: 0 additions & 3 deletions
This file was deleted.

resources/views/livewire/media/edit-content.blade.php

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)