- prepare messages
This commit is contained in:
parent
a7e93681f3
commit
620217e1d5
27
app/Http/Controllers/Api/MessageController.php
Normal file
27
app/Http/Controllers/Api/MessageController.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\MessageRequest;
|
||||||
|
use App\Models\Message;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
|
class MessageController extends Controller
|
||||||
|
{
|
||||||
|
public function store(MessageRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$data = $request->toArray();
|
||||||
|
Message::query()->create([
|
||||||
|
'message' => $data['message'],
|
||||||
|
'email' => $data['email'],
|
||||||
|
'sender' => $data['sender'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Dziękuję za wiadomość! Odpowiem możliwie najszybciej.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -5,11 +5,15 @@ declare(strict_types=1);
|
|||||||
namespace App\Http\Controllers\Dashboard;
|
namespace App\Http\Controllers\Dashboard;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Resources\MessageCollection;
|
||||||
|
use App\Models\Message;
|
||||||
use Inertia\Response as InertiaResponse;
|
use Inertia\Response as InertiaResponse;
|
||||||
|
|
||||||
class MessageController extends Controller
|
class MessageController extends Controller
|
||||||
{
|
{
|
||||||
public function index() : InertiaResponse {
|
public function index() : InertiaResponse {
|
||||||
return inertia('Messages/Index');
|
return inertia('Messages/Index', [
|
||||||
|
'messages' => new MessageCollection(Message::all()),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ class Kernel extends HttpKernel
|
|||||||
\App\Http\Middleware\TrimStrings::class,
|
\App\Http\Middleware\TrimStrings::class,
|
||||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||||
Core::class,
|
Core::class,
|
||||||
\App\Http\Middleware\HandleInertiaRequests::class,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $middlewareGroups = [
|
protected $middlewareGroups = [
|
||||||
@ -29,6 +28,7 @@ class Kernel extends HttpKernel
|
|||||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||||
\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class,
|
\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::class,
|
||||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
|
\App\Http\Middleware\HandleInertiaRequests::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
'api' => [
|
'api' => [
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Http\Middleware;
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
use Illuminate\Http\Middleware\TrustProxies as Middleware;
|
||||||
|
31
app/Http/Requests/MessageRequest.php
Normal file
31
app/Http/Requests/MessageRequest.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class MessageRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'message' => 'required|string|min:3|max:500',
|
||||||
|
'sender' => 'required|string|min:3|max:50',
|
||||||
|
'email' => 'required|email|max:250',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function messages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'message.required' => 'Pole wiadomości jest wymagane.',
|
||||||
|
'sender.required' => 'Pole nadawcy jest wymagane.',
|
||||||
|
'email.required' => 'Pole e-mail jest wymagane.',
|
||||||
|
'message.min' => 'Pole wiadomości wymaga 3 znaki.',
|
||||||
|
'sender.min' => 'Pole nadawcy wymaga 3 znaki.',
|
||||||
|
'email.email' => 'Pole musi być e-mailem.',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
17
app/Http/Resources/MessageCollection.php
Normal file
17
app/Http/Resources/MessageCollection.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||||
|
|
||||||
|
class MessageCollection extends ResourceCollection
|
||||||
|
{
|
||||||
|
public function toArray($request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'data' => $this->collection,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
22
app/Http/Resources/MessageResource.php
Normal file
22
app/Http/Resources/MessageResource.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class MessageResource extends JsonResource
|
||||||
|
{
|
||||||
|
public static $wrap = null;
|
||||||
|
|
||||||
|
public function toArray($request): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'sender' => $this->sender,
|
||||||
|
'email' => $this->email,
|
||||||
|
'message' => $this->message,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
21
app/Models/Message.php
Normal file
21
app/Models/Message.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id
|
||||||
|
* @param string $message
|
||||||
|
* @param string $email
|
||||||
|
* @param string $sender
|
||||||
|
*/
|
||||||
|
class Message extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('messages', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('message', 500);
|
||||||
|
$table->string('email', 250);
|
||||||
|
$table->string('sender', 50);
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('messages');
|
||||||
|
}
|
||||||
|
};
|
@ -1,3 +1,12 @@
|
|||||||
|
<script setup>
|
||||||
|
defineProps({
|
||||||
|
messages: {
|
||||||
|
type: Object,
|
||||||
|
default: {},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<InertiaHead title="Wiadomości" />
|
<InertiaHead title="Wiadomości" />
|
||||||
<div class="p-4">
|
<div class="p-4">
|
||||||
@ -5,30 +14,42 @@
|
|||||||
<h1 class="text-3xl font-roboto font-light">Wiadomości</h1>
|
<h1 class="text-3xl font-roboto font-light">Wiadomości</h1>
|
||||||
</header>
|
</header>
|
||||||
<div class="overflow-x-auto">
|
<div class="overflow-x-auto">
|
||||||
<table v-if="cvs.data.length" class="w-full min-w-[600px] border-separate border-spacing-y-2 cursor-pointer">
|
<table v-if="messages.data.length" class="table-fixed w-full min-w-[600px] border-separate border-spacing-y-2 cursor-pointer">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col class="w-min" />
|
<col class="w-[40px] max-w-[60px]" />
|
||||||
|
<col class="w-[250px]" />
|
||||||
|
<col class="w-auto" />
|
||||||
|
<col class="w-[50px]" />
|
||||||
</colgroup>
|
</colgroup>
|
||||||
<thead class="text-left bg-gray-100">
|
<thead class="text-left bg-gray-100">
|
||||||
<th class="p-2 text-center">ID</th>
|
<th class="w-[40px] max-w-[60px] p-2 text-center">ID</th>
|
||||||
<th class="p-2">Wysyłający</th>
|
<th class="w-[250px] p-2">Wysyłający</th>
|
||||||
<th class="w-[100px] p-2 whitespace-nowrap">E-mail</th>
|
<th class="p-2">E-mail</th>
|
||||||
<th class="p-2"></th>
|
<th class="w-[50px] p-2"></th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<!-- <InertiaLink
|
<InertiaLink
|
||||||
as="tr"
|
as="tr"
|
||||||
v-for="(cv, key) in cvs.data"
|
v-for="(message, key) in messages.data"
|
||||||
:key="key"
|
:key="key"
|
||||||
class="px-3 py-2 bg-white hover:bg-neutral-200 rounded-md z-10"
|
class="px-3 py-2 bg-white hover:bg-neutral-200 rounded-md z-10"
|
||||||
:href="`/dashboard/message/${cv.token}`">
|
:href="`/dashboard/message/${message.id}`">
|
||||||
<td></td>
|
<td class="p-2 w-[60px] text-center">#{{ message.id }}</td>
|
||||||
<td></td>
|
<td class="p-2 whitespace-nowrap overflow-hidden overflow-ellipsis">{{ message.sender }}</td>
|
||||||
<td></td>
|
<td class="p-2">{{ message.email }}</td>
|
||||||
<td></td>
|
<td class="flex items-center justify-end gap-2 p-3 z-50">
|
||||||
</InertiaLink> -->
|
<InertiaLink
|
||||||
|
as="button"
|
||||||
|
class="px-3 py-3 text-red-600 hover:text-red-800"
|
||||||
|
:href="`/dashboard/message/${message.id}/delete`"
|
||||||
|
title="Usuń projekt z listy"><FontAwesomeIcon :icon="['fas', 'trash']" /></InertiaLink>
|
||||||
|
</td>
|
||||||
|
</InertiaLink>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<div v-else>
|
||||||
|
Lista pusta!
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -27,9 +27,8 @@ defineProps({
|
|||||||
</InertiaLink>
|
</InertiaLink>
|
||||||
<nav>
|
<nav>
|
||||||
<ul class="flex gap-3 items-center font-bold">
|
<ul class="flex gap-3 items-center font-bold">
|
||||||
<li><InertiaLink class="text-white active:text-kamilcraft-green hover:text-black hover:underline" href="/dashboard">Dashboard</InertiaLink></li>
|
|
||||||
<li><InertiaLink class="text-white active:text-kamilcraft-green hover:text-black hover:underline" href="/dashboard/cv">CV</InertiaLink></li>
|
<li><InertiaLink class="text-white active:text-kamilcraft-green hover:text-black hover:underline" href="/dashboard/cv">CV</InertiaLink></li>
|
||||||
<li><InertiaLink class="text-white active:text-kamilcraft-green hover:text-black hover:underline" href="/dashboard/message">Wiadomości</InertiaLink></li>
|
<li><InertiaLink class="text-white active:text-kamilcraft-green hover:text-black hover:underline" href="/dashboard/message">Msg</InertiaLink></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
@ -19,3 +19,5 @@ Route::prefix('project')->group(function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Route::get('cv/{cv}', 'CVController@show');
|
Route::get('cv/{cv}', 'CVController@show');
|
||||||
|
|
||||||
|
Route::post('message', 'MessageController@store');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user