V2, better design, more functionalities.

This commit is contained in:
Roberto Guagliardo
2025-07-09 01:22:29 +02:00
parent b324c030f4
commit 2c5d7102ab
87 changed files with 2273 additions and 178 deletions

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
class ContactController extends Controller
{
public function store(Request $request)
{
$validated = $request->validate([
'name' => 'required|max:255',
'message' => 'required|max:5000',
]);
return response()->json(['status' => 'success']);
}
}

View File

@@ -32,7 +32,7 @@ class EducationController extends Controller
$education = Education::create($data);
if ($request->hasFile('afbeelding')) {
$education->addMediaFromRequest('afbeelding')->toMediaCollection('afbeelding');
$education->addMediaFromRequest('afbeelding')->toMediaCollection('image');
}
return redirect()->route('educations.index')->with('success', 'Opleiding toegevoegd.');
@@ -62,8 +62,9 @@ class EducationController extends Controller
$education->update($data);
if ($request->hasFile('afbeelding')) {
$education->clearMediaCollection('afbeelding');
$education->addMediaFromRequest('afbeelding')->toMediaCollection('afbeelding');
$education->clearMediaCollection('image');
$education->addMediaFromRequest('afbeelding')->toMediaCollection('image');
}
return redirect()->route('educations.index')->with('success', 'Opleiding bijgewerkt.');

View File

@@ -7,15 +7,55 @@ use App\Models\Personalia;
use App\Models\Skill;
use App\Models\WorkExperience;
use Illuminate\Http\Request;
use App\Jobs\NotifyTelegramAboutPersonaliaClick;
use App\Jobs\NotifyTelegramAboutContactMessage;
class FrontendController extends Controller
{
public function index()
{
$skills = Skill::all();
$skills = Skill::all()->groupBy('type');
$personalia = Personalia::all();
$education = Education::all();
$experience = WorkExperience::all();
$education = Education::orderBy('startdatum', 'desc')->get();
$experience = WorkExperience::orderBy('startdatum', 'desc')->get();
return view('welcome', compact('skills', 'personalia', 'education', 'experience'));
}
public function getPersonalia($id)
{
$item = Personalia::findOrFail($id);
NotifyTelegramAboutPersonaliaClick::dispatch(
$item,
request()->ip(),
request()->userAgent()
);
return response()->json([
'value' => $item->value,
]);
}
public function message(Request $request)
{
$validated = $request->validate([
'name' => 'required|string|max:255',
'message' => 'required|string|max:5000',
'email' => 'nullable|email|max:255',
'phone' => 'nullable|string|max:50',
]);
NotifyTelegramAboutContactMessage::dispatch(
$validated['name'],
$validated['message'],
$request->ip(),
$request->userAgent(),
$validated['email'] ?? null,
$validated['phone'] ?? null
);
return response()->json(['status' => 'success']);
}
}

View File

@@ -29,11 +29,14 @@ class SkillController extends Controller
*/
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required|string|max:255',
'description' => 'nullable|string',
'rating' => 'required|integer|min:1|max:10',
'rating' => 'required|numeric|min:1|max:10',
'image' => 'nullable|image|max:2048',
'type' => 'required|in:rating,tag,other',
]);
$skill = Skill::create($validated);
@@ -69,8 +72,10 @@ class SkillController extends Controller
$validated = $request->validate([
'title' => 'required|string|max:255',
'description' => 'nullable|string',
'rating' => 'required|integer|min:1|max:10',
'rating' => 'required|numeric|min:1|max:10',
'image' => 'nullable|image|max:2048',
'type' => 'required|in:rating,tag,other',
]);
$skill->update($validated);

View File

@@ -31,7 +31,7 @@ class WorkExperienceController extends Controller
$experience = WorkExperience::create($data);
if ($request->hasFile('afbeelding')) {
$experience->addMediaFromRequest('afbeelding')->toMediaCollection('afbeelding');
$experience->addMediaFromRequest('afbeelding')->toMediaCollection('image');
}
return redirect()->route('work-experiences.index')->with('success', 'Ervaring toegevoegd.');
@@ -58,11 +58,13 @@ class WorkExperienceController extends Controller
'afbeelding' => 'nullable|image|max:2048',
]);
$workExperience->update($data);
if ($request->hasFile('afbeelding')) {
$workExperience->clearMediaCollection('afbeelding');
$workExperience->addMediaFromRequest('afbeelding')->toMediaCollection('afbeelding');
$workExperience->clearMediaCollection('image');
$workExperience->addMediaFromRequest('afbeelding')->toMediaCollection('image');
}
return redirect()->route('work-experiences.index')->with('success', 'Ervaring bijgewerkt.');

View File

@@ -0,0 +1,60 @@
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Http;
class NotifyTelegramAboutContactMessage implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected string $name;
protected string $message;
protected string $ip;
protected string $userAgent;
protected string $email;
protected string $phone;
public function __construct(string $name, string $message, string $ip, string $userAgent, ?string $email = null, ?string $phone = null)
{
$this->name = $name;
$this->message = $message;
$this->ip = $ip;
$this->userAgent = $userAgent;
$this->email = $email;
$this->phone = $phone;
}
public function handle()
{
$email = $this->email ?? '';
$phone = $this->phone ?? '';
$text = <<<TEXT
📩 *Nieuw contactbericht ontvangen*
👤 Naam: *{$this->name}*
💬 Bericht:
{$this->message}
📧 Email: {$email}
📱 Telefoon: {$phone}
🌐 IP: {$this->ip}
🧭 User Agent: `{$this->userAgent}`
🕒 Tijdstip: *{now()->format('d-m-Y H:i')}*
TEXT;
Http::post("https://api.telegram.org/bot" . config('services.telegram.bot_token') . "/sendMessage", [
'chat_id' => config('services.telegram.chat_id'),
'text' => $text,
'parse_mode' => 'Markdown',
]);
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Jobs;
use App\Models\Personalia;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Http;
class NotifyTelegramAboutPersonaliaClick implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $personalia;
protected $ip;
protected $userAgent;
public function __construct(Personalia $personalia, $ip, $userAgent)
{
$this->personalia = $personalia;
$this->ip = $ip;
$this->userAgent = $userAgent;
}
public function handle()
{
$message = <<<TEXT
👤 *Persoonlijke gegevens bekeken*
Naam: {$this->personalia->value}
IP: {$this->ip}
User Agent: `{$this->userAgent}`
📅 Tijdstip: *{$this->personalia->updated_at->format('d-m-Y H:i')}*
TEXT;
Http::post("https://api.telegram.org/bot" . config('services.telegram.bot_token') . "/sendMessage", [
'chat_id' => config('services.telegram.chat_id'),
'text' => $message,
'parse_mode' => 'Markdown',
]);
}
}

View File

@@ -16,4 +16,13 @@ class Education extends Model implements HasMedia
'einddatum',
'beschrijving',
];
public function image()
{
return $this->getFirstMedia('image');
}
public function imageUrl()
{
return $this->image() ? $this->image()->getUrl() : null;
}
}

View File

@@ -10,4 +10,13 @@ class Personalia extends Model
protected $casts = [
'hidden' => 'boolean',
];
public function image()
{
return $this->getFirstMedia('image');
}
public function imageUrl()
{
return $this->image() ? $this->image()->getUrl() : null;
}
}

View File

@@ -11,5 +11,14 @@ class Skill extends Model implements HasMedia
{
use InteractsWithMedia;
protected $fillable = ['title', 'description', 'rating'];
protected $fillable = ['title', 'description', 'rating', 'type'];
public function image()
{
return $this->getFirstMedia('image');
}
public function imageUrl()
{
return $this->image() ? $this->image()->getUrl() : null;
}
}

View File

@@ -18,5 +18,14 @@ class WorkExperience extends Model implements HasMedia
'beschrijving',
];
public function image()
{
return $this->getFirstMedia('image');
}
public function imageUrl()
{
return $this->image() ? $this->image()->getUrl() : null;
}
// Als je mediaconversies of image handling wil: hier kun je die later toevoegen
}