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 4c7743a

Browse files
committedJun 7, 2020
07 and 08 Videos for registrations to an event added
1 parent 98ff301 commit 4c7743a

14 files changed

+241
-1
lines changed
 

‎.idea/workspace.xml

Lines changed: 22 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎app/Http/Controllers/EventController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Models\Event;
6+
57
class EventController extends Controller
68
{
79
public function add()
810
{
911
return view('pages.event-add-page');
1012
}
13+
14+
public function register(Event $event)
15+
{
16+
return view('pages.event-register', [
17+
'event' => $event,
18+
]);
19+
}
1120
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
class RegistrationController extends Controller
8+
{
9+
//
10+
}

‎app/Http/Livewire/EventAddForm.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Http\Livewire;
44

55
use App\Models\Event;
6+
use Illuminate\Support\Str;
67
use Livewire\Component;
78

89
class EventAddForm extends Component
@@ -47,6 +48,7 @@ public function submit()
4748
Event::find($this->event->id)
4849
->update($event);
4950
} else {
51+
$event['identifier'] = Str::random(10);
5052
Event::create($event);
5153
}
5254

‎app/Http/Livewire/EventRegister.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace App\Http\Livewire;
4+
5+
use App\Models\Event;
6+
use App\Rules\AlreadyRegistered;
7+
use Livewire\Component;
8+
9+
class EventRegister extends Component
10+
{
11+
public $event;
12+
public $email;
13+
public $name;
14+
15+
public function submit()
16+
{
17+
$this->validate([
18+
'email' => ['required', new AlreadyRegistered($this->event->id)],
19+
'name' => ['required'],
20+
]);
21+
22+
$event = Event::find($this->event->id);
23+
24+
$event->registrations()->create([
25+
'name' => $this->name,
26+
'email' => $this->email,
27+
]);
28+
29+
$event->increment('registered_participant');
30+
31+
$this->redirectRoute('event.register', ['event' => $this->event->identifier]);
32+
}
33+
34+
public function mount(Event $event)
35+
{
36+
$this->event = $event;
37+
}
38+
39+
public function render()
40+
{
41+
return view('livewire.event-register');
42+
}
43+
}

‎app/Models/Event.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,10 @@
77
class Event extends Model
88
{
99
protected $guarded = [];
10+
11+
public function registrations()
12+
{
13+
return $this->hasMany(Registration::class)
14+
->orderByDesc('id');
15+
}
1016
}

‎app/Models/Registration.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Registration extends Model
8+
{
9+
protected $guarded = [];
10+
11+
public function event()
12+
{
13+
return $this->belongsTo(Event::class);
14+
}
15+
}

‎app/Rules/AlreadyRegistered.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace App\Rules;
4+
5+
use App\Models\Registration;
6+
use Illuminate\Contracts\Validation\Rule;
7+
8+
class AlreadyRegistered implements Rule
9+
{
10+
private $eventId;
11+
12+
public function __construct($eventId)
13+
{
14+
$this->eventId = $eventId;
15+
}
16+
17+
public function passes($attribute, $value)
18+
{
19+
$count = Registration::query()
20+
->where('event_id', $this->eventId)
21+
->where('email', $value)
22+
->count();
23+
24+
return $count === 0;
25+
}
26+
27+
public function message()
28+
{
29+
return 'You are already registered to this event.';
30+
}
31+
}

‎database/migrations/2020_05_17_180854_create_events_table.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ public function up()
1515
{
1616
Schema::create('events', function (Blueprint $table) {
1717
$table->id();
18+
$table->string('identifier', 10);
1819
$table->string('event_name');
1920
$table->string('contact_person');
2021
$table->string('contact_email');
2122
$table->integer('allowed_participant');
2223
$table->integer('registered_participant')->default(0);
2324
$table->timestamps();
25+
26+
$table->index(['identifier']);
2427
});
2528
}
2629

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class CreateRegistrationsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('registrations', function (Blueprint $table) {
17+
$table->id();
18+
$table->string('name');
19+
$table->string('email');
20+
$table->unsignedBigInteger('event_id');
21+
$table->timestamps();
22+
23+
$table->index(['event_id']);
24+
});
25+
}
26+
27+
/**
28+
* Reverse the migrations.
29+
*
30+
* @return void
31+
*/
32+
public function down()
33+
{
34+
Schema::dropIfExists('registrations');
35+
}
36+
}

‎resources/views/livewire/event-listing.blade.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<thead>
44
<tr>
55
<th>#</th>
6+
<th>Identifier</th>
67
<th>Event name</th>
78
<th>Contact person</th>
89
<th>Contact email</th>
@@ -15,6 +16,7 @@
1516
@foreach($events as $event)
1617
<tr>
1718
<td>{{$event->id}}</td>
19+
<td>{{$event->identifier}}</td>
1820
<td>{{$event->event_name}}</td>
1921
<td>{{$event->contact_person}}</td>
2022
<td>{{$event->contact_email}}</td>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<div class="content">
2+
<h2>Event name: {{$event->event_name}}</h2>
3+
<div class="row mb-3">
4+
<div class="col-md-12">
5+
<div class="card">
6+
<div class="card-body">
7+
<p>Contact person: {{$event->contact_person}}</p>
8+
<p>Contact email: <a href="mailto:{{$event->contact_email}}">{{$event->contact_email}}</a></p>
9+
10+
@if($event->allowed_participant !== 0)
11+
<p>Total seats: {{$event->allowed_participant}}</p>
12+
<p>Seats available: {{$event->allowed_participant - $event->registered_participant}}</p>
13+
@endif
14+
</div>
15+
</div>
16+
</div>
17+
</div>
18+
19+
<div class="row">
20+
<div class="col-md-12">
21+
<div class="card">
22+
<div class="card-body">
23+
<p>If you are interested to join this event, enter your email address below:</p>
24+
25+
<form wire:submit.prevent="submit" class="w-50">
26+
<div class="form-group">
27+
<input type="text" name="name" id="name" class="form-control"
28+
wire:model="name" placeholder="Enter your name" autocomplete="off"
29+
tabindex="1">
30+
@error('name')
31+
<div class="error">{{$message}}</div>
32+
@enderror
33+
</div>
34+
35+
<div class="form-group">
36+
<input type="text" name="email_address" id="email_address" class="form-control"
37+
wire:model="email" placeholder="Enter your email address" autocomplete="off"
38+
tabindex="2">
39+
@error('email')
40+
<div class="error">{{$message}}</div>
41+
@enderror
42+
</div>
43+
44+
<button class="btn btn-success">Register</button>
45+
</form>
46+
</div>
47+
</div>
48+
</div>
49+
</div>
50+
</div>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@extends('layouts.app')
2+
@section('content')
3+
<div class="container">
4+
<div class="row justify-content-center">
5+
<div class="col-md-12">
6+
@livewire('event-register', ['event' => $event])
7+
</div>
8+
</div>
9+
</div>
10+
@endsection

‎routes/web.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@
1515
Route::get('/event/add', [EventController::class, 'add'])->name('event.add');
1616
Route::livewire('/event/view/{event}', 'event-view')->name('event.view');
1717
});
18+
19+
Route::get('/register/{event:identifier}', [EventController::class, 'register'])->name('event.register');

0 commit comments

Comments
 (0)
Please sign in to comment.