B8f7a improve templates pages for seo (#5)
* Templates * access templates without login also * Set required on UI * Improve templates pages for SEO * test case for Templates * Refactor SitemapController * Cosmetic changes to templates Co-authored-by: Julien Nahum <jhumanj@MacBook-Pro-de-Julien.local>
This commit is contained in:
45
app/Http/Requests/Templates/CreateTemplateRequest.php
Normal file
45
app/Http/Requests/Templates/CreateTemplateRequest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Templates;
|
||||
|
||||
use App\Models\Template;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreateTemplateRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'form' => 'required|array',
|
||||
'name' => 'required|string|max:60',
|
||||
'slug' => 'required|string|unique:templates',
|
||||
'description' => 'required|string|max:2000',
|
||||
'image_url' => 'required|string',
|
||||
'questions' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function getTemplate() : Template
|
||||
{
|
||||
$structure = $this->form;
|
||||
$ignoreKeys = ['id','creator','creator_id','created_at','updated_at','extra','workspace','submissions','submissions_count','views','views_count'];
|
||||
foreach($structure as $key=>$val){
|
||||
if(in_array($key, $ignoreKeys)){
|
||||
$structure[$key] = null;
|
||||
}
|
||||
}
|
||||
return new Template([
|
||||
'name' => $this->name,
|
||||
'slug' => $this->slug,
|
||||
'description' => $this->description,
|
||||
'image_url' => $this->image_url,
|
||||
'structure' => $structure,
|
||||
'questions' => $this->questions ?? []
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user