Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 85e6f11

Browse files
committedJun 13, 2020
Worked on the file upload code.
1 parent f20e3fe commit 85e6f11

File tree

5 files changed

+734
-222
lines changed

5 files changed

+734
-222
lines changed
 

‎app/Http/Livewire/EventAddForm.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
namespace App\Http\Livewire;
44

55
use App\Models\Event;
6-
use Illuminate\Support\Str;
76
use Livewire\Component;
7+
use Illuminate\Support\Str;
8+
use Livewire\WithFileUploads;
89

910
class EventAddForm extends Component
1011
{
12+
use WithFileUploads;
13+
1114
public $eventName;
1215
public $contactName;
1316
public $contactEmail;
1417
public $allowedParticipants;
18+
public $banner;
1519
public $event;
1620

1721
public function mount($event)
@@ -35,13 +39,17 @@ public function submit()
3539
'contactName' => ['required', 'min:3'],
3640
'contactEmail' => ['required', 'email'],
3741
'allowedParticipants' => ['required', 'numeric'],
42+
'banner' => ['required', 'file'],
3843
]);
3944

45+
$filePath = $this->banner->store('public/banners');
46+
4047
$event = [
4148
'event_name' => $this->eventName,
4249
'contact_person' => $this->contactName,
4350
'contact_email' => $this->contactEmail,
4451
'allowed_participant' => $this->allowedParticipants,
52+
'banner' => $filePath,
4553
];
4654

4755
if ($this->event) {

‎composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"laravel/framework": "^7.0",
1616
"laravel/tinker": "^2.0",
1717
"laravel/ui": "^2.0",
18-
"livewire/livewire": "^1.1"
18+
"livewire/livewire": "^1.2"
1919
},
2020
"require-dev": {
2121
"facade/ignition": "^2.0",

‎composer.lock

Lines changed: 709 additions & 220 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎database/migrations/2020_05_17_180854_create_events_table.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public function up()
1919
$table->string('event_name');
2020
$table->string('contact_person');
2121
$table->string('contact_email');
22+
$table->string('banner');
2223
$table->integer('allowed_participant');
2324
$table->integer('registered_participant')->default(0);
2425
$table->timestamps();

‎resources/views/livewire/event-add-form.blade.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ class="form-control" wire:model="allowedParticipants">
3939
<div class="error">{{$message}}</div>
4040
@enderror
4141
</div>
42+
<div class="form-group">
43+
<label for="banner">Event banner</label>
44+
<input type="file" name="banner" id="banner"
45+
class="form-control" wire:model="banner">
46+
@error('banner')
47+
<div class="error">{{$message}}</div>
48+
@enderror
49+
@if ($banner)
50+
<img src="{{ $banner->temporaryUrl() }}" class="w-50 p-4">
51+
@endif
52+
@if (!$banner && isset($event->banner))
53+
<img src="{{ Storage::url($event->banner) }}" class="w-50 p-4">
54+
@endif
55+
</div>
4256
<button class="btn btn-success mr-4">Save</button>
4357
<a href="{{route('home')}}">Back</a>
4458
</form>

0 commit comments

Comments
 (0)
Please sign in to comment.