Skip to content

Commit

Permalink
+ FAQ database and BREAD
Browse files Browse the repository at this point in the history
  • Loading branch information
James-jamames committed Jan 15, 2024
1 parent b96d012 commit 51ecaf7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
37 changes: 37 additions & 0 deletions server/app/Models/FAQ.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use TCG\Voyager\Traits\Translatable;

class FAQ extends Model
{
use HasFactory, Translatable;

protected $translatable = ['question', 'answer'];
protected $table = "faq";

protected $fillable = [
'question',
'answer',
];

public static function getTranslate(string $lang)
{
$faq = FAQ::withTranslation($lang)->get();

foreach($faq as $element)
{
foreach($element->translations as $translation)
{
$element[$translation->column_name] = $translation->value;
}

unset($element->translations);
}

return $faq;
}
}
5 changes: 5 additions & 0 deletions server/routes/web.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use App\Http\Controllers\FormController;
use App\Models\FAQ;
use App\Models\Methodology;
use App\Models\News;
use App\Models\Team;
Expand Down Expand Up @@ -51,6 +52,10 @@
return Methodology::getTranslate($lang);
});

Route::get('/api/FAQ/{lang}', function (string $lang) {
return FAQ::getTranslate($lang);
});

Route::group(['prefix' => 'admin'], function () {
Voyager::routes();
});

0 comments on commit 51ecaf7

Please sign in to comment.