-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
47e333a
commit da58f9b
Showing
16 changed files
with
922 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Http\Requests\FaqRequest; | ||
use App\Models\Faq; | ||
use Illuminate\Http\RedirectResponse; | ||
use Inertia\Response; | ||
|
||
class FaqController extends Controller | ||
{ | ||
public function index(): Response | ||
{ | ||
$faqs = Faq::query() | ||
->orderByDesc("created_at") | ||
->get(); | ||
|
||
return inertia("Dashboard/FAQ/Index", [ | ||
"faqs" => $faqs, | ||
"total" => Faq::query()->count(), | ||
"lastUpdate" => Faq::query()->orderByDesc("updated_at")->first()?->updated_at->diffForHumans(), | ||
]); | ||
} | ||
|
||
public function create(): Response | ||
{ | ||
return inertia("Dashboard/FAQ/Create"); | ||
} | ||
|
||
public function store(FaqRequest $request): RedirectResponse | ||
{ | ||
Faq::query()->create($request->validated()); | ||
|
||
return redirect() | ||
->route("faqs.index") | ||
->with("success", "Dodano FAQ"); | ||
} | ||
|
||
public function edit(Faq $faq): Response | ||
{ | ||
return inertia("Dashboard/FAQ/Edit", [ | ||
"faq" => $faq, | ||
]); | ||
} | ||
|
||
public function update(FaqRequest $request, Faq $faq): RedirectResponse | ||
{ | ||
$faq->update($request->validated()); | ||
|
||
return redirect() | ||
->route("faqs.index") | ||
->with("success", "Zaktualizowano FAQ"); | ||
} | ||
|
||
public function destroy(Faq $faq): RedirectResponse | ||
{ | ||
$faq->delete(); | ||
|
||
return redirect()->back() | ||
->with("success", "Usunięto FAQ"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Requests; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class FaqRequest extends FormRequest | ||
{ | ||
public function rules(): array | ||
{ | ||
return [ | ||
"question" => ["required", "max:255"], | ||
"answer" => ["required", "max:65000"], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Database\Eloquent\Casts\Attribute; | ||
use Illuminate\Database\Eloquent\Concerns\HasUlids; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Stevebauman\Purify\Facades\Purify; | ||
|
||
/** | ||
* @property string $id | ||
* @property string $question | ||
* @property string $answer | ||
* @property Carbon $created_at | ||
* @property Carbon $updated_at | ||
*/ | ||
class Faq extends Model | ||
{ | ||
use HasFactory; | ||
use HasUlids; | ||
|
||
protected $guarded = []; | ||
|
||
protected function answer(): Attribute | ||
{ | ||
return Attribute::make( | ||
set: fn(?string $value): string => Purify::clean($value), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\Faq; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends Factory<Faq> | ||
*/ | ||
class FaqFactory extends Factory | ||
{ | ||
public function definition(): array | ||
{ | ||
return [ | ||
"question" => fake()->sentence(), | ||
"answer" => fake()->realText(), | ||
]; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
database/migrations/2023_09_27_193906_create_faqs_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?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("faqs", function (Blueprint $table): void { | ||
$table->ulid("id")->primary(); | ||
$table->string("question"); | ||
$table->longText("answer"); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::dropIfExists("faqs"); | ||
} | ||
}; |
Oops, something went wrong.