diff --git a/app/Http/Controllers/Admin/PageCrudController.php b/app/Http/Controllers/Admin/PageCrudController.php new file mode 100644 index 0000000..ba3f604 --- /dev/null +++ b/app/Http/Controllers/Admin/PageCrudController.php @@ -0,0 +1,82 @@ +type('number'); + * - CRUD::addColumn(['name' => 'price', 'type' => 'number']); + */ + } + + /** + * Define what happens when the Create operation is loaded. + * + * @see https://backpackforlaravel.com/docs/crud-operation-create + * @return void + */ + protected function setupCreateOperation() + { + CRUD::setValidation(PageRequest::class); + + CRUD::field('title'); + CRUD::field('content')->type('ckeditor'); + + /** + * Fields can be defined using the fluent syntax or array syntax: + * - CRUD::field('price')->type('number'); + * - CRUD::addField(['name' => 'price', 'type' => 'number'])); + */ + } + + /** + * Define what happens when the Update operation is loaded. + * + * @see https://backpackforlaravel.com/docs/crud-operation-update + * @return void + */ + protected function setupUpdateOperation() + { + $this->setupCreateOperation(); + } +} diff --git a/app/Http/Controllers/Api/MultimediaController.php b/app/Http/Controllers/Api/MultimediaController.php index 98584ea..bc048b9 100644 --- a/app/Http/Controllers/Api/MultimediaController.php +++ b/app/Http/Controllers/Api/MultimediaController.php @@ -9,7 +9,10 @@ class MultimediaController extends ApiController { public function index($category) { - $medias = MultimediaCategory::where('id', $category)->with('medias')->get()->first()->medias; - return $this->respondWithCollection($medias, new MediaTransformer()); + $medias = MultimediaCategory::where('id', $category)->with('medias')->get()->first(); + if($medias){ + return $this->respondWithCollection($medias->medias, new MediaTransformer()); + } + return $this->errorNotFound(); } } diff --git a/app/Http/Controllers/Api/PageController.php b/app/Http/Controllers/Api/PageController.php new file mode 100644 index 0000000..78b7c68 --- /dev/null +++ b/app/Http/Controllers/Api/PageController.php @@ -0,0 +1,23 @@ +page; + if(!$page_title){ + return $this->errorWrongArgs(); + } + $page = Page::where('title', $page_title)->get()->first(); + if($page){ + return $this->respondWithItem($page, new PageTransformer($this->locale)); + } + return $this->errorNotFound(); + } +} diff --git a/app/Http/Requests/PageRequest.php b/app/Http/Requests/PageRequest.php new file mode 100644 index 0000000..5e923e6 --- /dev/null +++ b/app/Http/Requests/PageRequest.php @@ -0,0 +1,55 @@ +check(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules() + { + return [ + // 'name' => 'required|min:5|max:255' + ]; + } + + /** + * Get the validation attributes that apply to the request. + * + * @return array + */ + public function attributes() + { + return [ + // + ]; + } + + /** + * Get the validation messages that apply to the request. + * + * @return array + */ + public function messages() + { + return [ + // + ]; + } +} diff --git a/app/Http/Requests/StorePageRequest.php b/app/Http/Requests/StorePageRequest.php new file mode 100644 index 0000000..949f021 --- /dev/null +++ b/app/Http/Requests/StorePageRequest.php @@ -0,0 +1,30 @@ +locale = $locale; + } + + public function transform(Page $page) + { + return [ + 'id' => $page->id, + 'title' => $page->title, + 'content' => $page->getTranslations('content', [$this->locale])[$this->locale] ?? '-', + ]; + } +} \ No newline at end of file diff --git a/database/factories/PageFactory.php b/database/factories/PageFactory.php new file mode 100644 index 0000000..297b5e6 --- /dev/null +++ b/database/factories/PageFactory.php @@ -0,0 +1,20 @@ +id(); + $table->string('title')->unique(); + $table->longText('content'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('pages'); + } +} diff --git a/database/seeders/PageSeeder.php b/database/seeders/PageSeeder.php new file mode 100644 index 0000000..7ca95f0 --- /dev/null +++ b/database/seeders/PageSeeder.php @@ -0,0 +1,18 @@ + Tarifs - \ No newline at end of file + + \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index 14857d6..ee0a6d5 100644 --- a/routes/api.php +++ b/routes/api.php @@ -12,6 +12,7 @@ use App\Http\Controllers\Api\DocumentController; use App\Http\Controllers\Api\TarifController; use App\Http\Controllers\Api\MultimediaCategoryController; use App\Http\Controllers\Api\MultimediaController; +use App\Http\Controllers\Api\PageController; use App\Http\Controllers\Api\VideoController; /* @@ -45,4 +46,5 @@ Route::get('tariffs', [TarifController::class, 'index']); Route::get('contacts', [ContactController::class, 'index']); Route::get('video', [VideoController::class, 'index']); +Route::get('pages', [PageController::class, 'index']); diff --git a/routes/backpack/custom.php b/routes/backpack/custom.php index ec6ca93..7d1b2fb 100644 --- a/routes/backpack/custom.php +++ b/routes/backpack/custom.php @@ -27,4 +27,5 @@ Route::group([ Route::crud('multimedia', 'MultimediaCrudController'); Route::crud('contact', 'ContactCrudController'); Route::crud('video', 'VideoCrudController'); + Route::crud('page', 'PageCrudController'); }); // this should be the absolute last line of this file \ No newline at end of file