Skip to content

Commit

Permalink
#13 - contact management (#41)
Browse files Browse the repository at this point in the history
* #13 - wip

* #13 - wip, refactor

* #13 - wip, refactor

* #13 - wip, working on icons

* #13 - wip, refactored views to match new changes in forms

* #15 - wip

* #13 - finished working on basic version, added test

* #13 - added spatie/laravel-options
  • Loading branch information
KarolZygadlo authored Oct 4, 2023
1 parent de82ed6 commit e926d78
Show file tree
Hide file tree
Showing 23 changed files with 794 additions and 18 deletions.
16 changes: 16 additions & 0 deletions app/Enums/Icons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace App\Enums;

enum Icons: string
{
case AtSymbol = "at-symbol";
case Envelope = "envelope";
case Exclamation = "exclamation";
case Github = "github";
case Information = "information";
case Linkedin = "linkedin";
case Slack = "slack";
}
71 changes: 71 additions & 0 deletions app/Http/Controllers/Dashboard/ContactInfoController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Dashboard;

use App\Enums\Icons;
use App\Http\Controllers\Controller;
use App\Http\Requests\ContactInfoRequest;
use App\Models\ContactInfo;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Response;
use Spatie\LaravelOptions\Options;

class ContactInfoController extends Controller
{
public function index(Request $request): Response
{
$contactInfos = ContactInfo::query()
->orderByDesc("created_at")
->get();

return inertia("Dashboard/ContactInfo/Index", [
"contactInfos" => $contactInfos,
"total" => ContactInfo::query()->count(),
"lastUpdate" => ContactInfo::query()->orderByDesc("updated_at")->first()?->updated_at->diffForHumans(),
]);
}

public function create(): Response
{
return inertia("Dashboard/ContactInfo/Create", [
"icons" => Options::forEnum(Icons::class)->toArray(),
]);
}

public function store(ContactInfoRequest $request): RedirectResponse
{
ContactInfo::query()->create($request->validated());

return redirect()
->route("contactInfo.index")
->with("success", "Dodano formę kontaktu");
}

public function edit(ContactInfo $contactInfo): Response
{
return inertia("Dashboard/ContactInfo/Edit", [
"contactInfo" => $contactInfo,
"icons" => Options::forEnum(Icons::class)->toArray(),
]);
}

public function update(ContactInfoRequest $request, ContactInfo $contactInfo): RedirectResponse
{
$contactInfo->update($request->validated());

return redirect()
->route("contactInfo.index")
->with("success", "Zaktualizowano formę kontaktu");
}

public function destroy(ContactInfo $contactInfo): RedirectResponse
{
$contactInfo->delete();

return redirect()->back()
->with("success", "Usunięto formę kontaktu");
}
}
21 changes: 21 additions & 0 deletions app/Http/Requests/ContactInfoRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests;

use App\Enums\Icons;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules\Enum;

class ContactInfoRequest extends FormRequest
{
public function rules(): array
{
return [
"label" => ["required", "string", "max:255"],
"identifier" => ["required", "string", "max:255"],
"icon" => ["required", new Enum(Icons::class)],
];
}
}
26 changes: 26 additions & 0 deletions app/Models/ContactInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

/**
* @property string $id
* @property string $email
* @property string $github_handle
* @property string $alternative_channel
* @property Carbon $created_at
* @property Carbon $updated_at
*/
class ContactInfo extends Model
{
use HasFactory;
use HasUlids;

protected $guarded = [];
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"laravel/framework": "^10.13.0",
"laravel/sanctum": "^3.2.5",
"laravel/tinker": "^2.8.1",
"spatie/laravel-options": "^1.1",
"stevebauman/purify": "^6.0"
},
"require-dev": {
Expand Down
156 changes: 144 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions database/factories/ContactInfoFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Enums\Icons;
use App\Models\ContactInfo;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends Factory<ContactInfo>
*/
class ContactInfoFactory extends Factory
{
public function definition(): array
{
return [
"label" => fake()->domainWord(),
"identifier" => fake()->url(),
"icon" => fake()->randomElement(Icons::class),
];
}
}
Loading

0 comments on commit e926d78

Please sign in to comment.