--- /dev/null
+<?php
+
+namespace App\Http\Controllers;
+
+use Illuminate\Http\Request;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Route;
+use Illuminate\Support\Facades\Validator;
+use App\Models\Review;
+use App\Models\SProperty;
+use App\Helpers\ContextLaraKnife;
+use App\Helpers\ViewHelper;
+use App\Helpers\DbHelper;
+use App\Helpers\Helper;
+use App\Helpers\Pagination;
+
+class ReviewController extends Controller
+{
+ /**
+ * Show the form for creating a new resource.
+ */
+ public function create(Request $request)
+ {
+ if ($request->btnSubmit === 'btnCancel') {
+ $rc = redirect('/review-index');
+ } else {
+ $fields = $request->all();
+ if (count($fields) === 0) {
+ $fields = [
+ 'nickname' => '',
+ 'stars' => '',
+ 'title' => '',
+ 'comment' => '',
+ 'email' => ''
+ ];
+ }
+ $context = new ContextLaraKnife($request, $fields);
+ $rc = view('review.create', [
+ 'context' => $context,
+ ]);
+ }
+ return $rc;
+ }
+ /**
+ * Show the form for editing the specified resource.
+ */
+ public function edit(Review $review, Request $request)
+ {
+ if ($request->btnSubmit === 'btnCancel') {
+ $rc = redirect('/review-index');
+ } else {
+ $fields = $request->all();
+ if (count($fields) === 0) {
+ $fields = [
+ 'nickname' => '',
+ 'stars' => '',
+ 'title' => '',
+ 'comment' => '',
+ 'email' => ''
+ ];
+ }
+ $context = new ContextLaraKnife($request, null, $review);
+ $rc = view('review.edit', [
+ 'context' => $context,
+ ]);
+ }
+ return $rc;
+ }
+ /**
+ * Remove the specified resource from storage.
+ */
+ public function destroy(Review $review, Request $request)
+ {
+ if ($request->btnSubmit === 'btnDelete') {
+ $review->delete();
+ }
+ return redirect('/review-index');
+ }
+ /**
+ * Display the database records of the resource.
+ */
+ public function index(Request $request)
+ {
+ if ($request->btnSubmit === 'btnNew') {
+ return redirect('/review-create');
+ } else {
+ $sql = 'SELECT t0.*'
+ . ' FROM reviews t0'
+ ;
+ $parameters = [];
+ $fields = $request->all();
+ if (count($fields) == 0) {
+ $fields = [
+ 'nickname' => '',
+ 'stars' => '',
+ 'title' => '',
+ 'comment' => '',
+ 'email' => '',
+ '_sortParams' => 'id:asc'
+ . ';nickname:desc'
+ ];
+ } else {
+ $conditions = [];
+ ViewHelper::addConditionPattern($conditions, $parameters, 'nickname');
+ ViewHelper::addConditionPattern($conditions, $parameters, 'title');
+ ViewHelper::addConditionPattern($conditions, $parameters, 'comment');
+ ViewHelper::addConditionPattern($conditions, $parameters, 'email');
+ ViewHelper::addConditionComparism($conditions, $parameters, 'stars', null, '=');
+ $sql = DbHelper::addConditions($sql, $conditions);
+ }
+ $sql = DbHelper::addOrderBy($sql, $fields['_sortParams']);
+ $pagination = new Pagination($sql, $parameters, $fields);
+ $records = $pagination->records;
+ $context = new ContextLaraKnife($request, $fields);
+ return view('review.index', [
+ 'context' => $context,
+ 'records' => $records,
+ 'pagination' => $pagination
+ ]);
+ }
+ }
+ /**
+ * Returns the validation rules.
+ * @return array<string, string> The validation rules.
+ */
+ private function rules(bool $isCreate=false): array
+ {
+ $rc = [
+ 'nickname' => 'required',
+ 'stars' => 'required|integer|min:1|max:5',
+ 'title' => 'required',
+ 'comment' => '',
+ 'email' => 'required|email'
+ ];
+ return $rc;
+ }
+ public static function routes()
+ {
+ Route::get('/review-index', [ReviewController::class, 'index'])->middleware('auth');
+ Route::post('/review-index', [ReviewController::class, 'index'])->middleware('auth');
+ Route::get('/review-create', [ReviewController::class, 'create'])->middleware('auth');
+ Route::put('/review-store', [ReviewController::class, 'store'])->middleware('auth');
+ Route::post('/review-edit/{review}', [ReviewController::class, 'edit'])->middleware('auth');
+ Route::get('/review-edit/{review}', [ReviewController::class, 'edit'])->middleware('auth');
+ Route::post('/review-update/{review}', [ReviewController::class, 'update'])->middleware('auth');
+ Route::get('/review-show/{review}/delete', [ReviewController::class, 'show'])->middleware('auth');
+ Route::delete('/review-show/{review}/delete', [ReviewController::class, 'destroy'])->middleware('auth');
+ }
+ /**
+ * Display the specified resource.
+ */
+ public function show(Review $review, Request $request)
+ {
+ if ($request->btnSubmit === 'btnCancel') {
+ $rc = redirect('/review-index')->middleware('auth');
+ } else {
+ $context = new ContextLaraKnife($request, null, $review);
+ $rc = view('review.show', [
+ 'context' => $context,
+ 'mode' => 'delete'
+ ]);
+ }
+ return $rc;
+ }
+
+ /**
+ * Store a newly created resource in storage.
+ */
+ public function store(Request $request)
+ {
+ $rc = null;
+ if ($request->btnSubmit === 'btnStore') {
+ $fields = $request->all();
+ $validator = Validator::make($fields, $this->rules(true));
+ if ($validator->fails()) {
+ $rc = back()->withErrors($validator)->withInput();
+ } else {
+ $validated = $validator->validated();
+ $validated['comment'] = strip_tags($validated['comment']);
+ Review::create($validated);
+ }
+ }
+ if ($rc == null){
+ $rc = redirect('/review-index');
+ }
+ return $rc;
+ }
+ /**
+ * Update the specified resource in storage.
+ */
+ public function update(Review $review, Request $request)
+ {
+ $rc = null;
+ if ($request->btnSubmit === 'btnStore') {
+ $fields = $request->all();
+ $validator = Validator::make($fields, $this->rules(false));
+ if ($validator->fails()) {
+ $rc = back()->withErrors($validator)->withInput();
+ } else {
+ $validated = $validator->validated();
+ $validated['comment'] = strip_tags($validated['comment']);
+ $review->update($validated);
+ }
+ }
+ if ($rc == null){
+ $rc = redirect('/review-index');
+ }
+ return $rc;
+ }
+}
--- /dev/null
+@extends('layouts.backend')
+
+@section('content')
+<form id="review-index" action="/review-index" method="POST">
+ @csrf
+ <x-laraknife.panels.index title="{{ __('Reviews') }}">
+ <x-laraknife.panels.filter legend="{{ $pagination->legendText() }}">
+ <x-laraknife.forms.string position="first" name="text" label="Text" value="{{ $context->valueOf('text') }}" width2="4" />
+ <x-laraknife.forms.string position="last" name="stars" label="Stars" value="{{ $context->valueOf('stars') }}" width2="4" />
+ </x-laraknife.panels.filter>
+ <x-laraknife.panels.index-button buttonType="new"/>
+ <x-laraknife.panels.sortable-table :context="$context" :pagination="$pagination">
+ <thead>
+ <tr>
+ <th></th>
+ <th sortId="nickname">{{__('Nickname')}}</th>
+ <th sortId="stars">{{__('Stars')}}</th>
+ <th sortId="title">{{__('Title')}}</th>
+ <th sortId="comment">{{__('Comment')}}</th>
+ <th sortId="email">{{__('Email')}}</th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+@foreach ($records as $review)
+ <tr>
+ <td><x-laraknife.icons.change-record module="review" no="{{ $review->id }}" /></td>
+ <td>{{$review->nickname}}</td>
+ <td>{{$review->stars}}</td>
+ <td>{{$review->title}}</td>
+ <td>{{$review->comment}}</td>
+ <td>{{$review->email}}</td>
+ <td><x-laraknife.icons.delete-record module="review" no="{{ $review->id }}" /></td>
+ </tr>
+@endforeach
+ </tbody>
+ </x-laraknife.panels.sortable-table>
+ </x-laraknife.panels.index>
+</form>
+@endsection
<?php
use Illuminate\Support\Facades\Route;
-use App\Http\Controllers\RoleController;
-use App\Http\Controllers\UserController;
-use App\Http\Controllers\SPropertyController;
-use App\Http\Controllers\MenuitemController;
-use App\Http\Controllers\NoteController;
use App\Http\Controllers\FileController;
-use App\Http\Controllers\WordController;
+use App\Http\Controllers\NoteController;
use App\Http\Controllers\NounController;
+use App\Http\Controllers\RoleController;
+use App\Http\Controllers\TermController;
+use App\Http\Controllers\UserController;
use App\Http\Controllers\VerbController;
+use App\Http\Controllers\WordController;
use App\Http\Controllers\PhraseController;
-use App\Http\Controllers\TermController;
+use App\Http\Controllers\ReviewController;
+use App\Http\Controllers\MenuitemController;
+use App\Http\Controllers\SPropertyController;
Route::get('/', function () {
return redirect('/menuitem-menu_main');
VerbController::routes();
PhraseController::routes();
+ReviewController::routes();