diff --git a/app/Http/Controllers/Admin/CompanyController.php b/app/Http/Controllers/Admin/CompanyController.php index 7faacad..1bae8c3 100644 --- a/app/Http/Controllers/Admin/CompanyController.php +++ b/app/Http/Controllers/Admin/CompanyController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Admin; +use App\Classes\Meta; use App\Http\Controllers\Controller; use App\Http\Requests\PagesRequest; use App\Http\Requests\SEORequest; @@ -79,6 +80,23 @@ class CompanyController extends Controller return redirect()->route('admin.editor-seo'); } + public function editor_seo_ajax(Request $request) { + $url = $request->get('url'); // post('url'); + $metaData = Array(); + //$url = json_decode($url, true); + + if (!empty($url)) { + + $meta = new Meta($url); + $meta->parse(); + $metaData = $meta->finalize(); + + return json_encode($metaData); + } else { + return json_encode(Array('Error URL')); + } + } + public function editor_seo_edit(SEO $page) { return view('admin.seo.edit', compact('page')); } diff --git a/app/Http/Requests/SEORequest.php b/app/Http/Requests/SEORequest.php index afea372..92db7a7 100644 --- a/app/Http/Requests/SEORequest.php +++ b/app/Http/Requests/SEORequest.php @@ -13,7 +13,7 @@ class SEORequest extends FormRequest */ public function authorize() { - return false; + return true; } /** @@ -24,7 +24,38 @@ class SEORequest extends FormRequest public function rules() { return [ - // + 'title' => [ + 'required', + 'string', + 'min:3', + 'max:255', + ], + 'url' => [ + 'required', + 'string', + 'min: 5', + 'max:2555', + ], + ]; + } + + public function messages() { + return [ + 'required' => 'Поле :attribute обязательно для ввода', + 'unique' => 'Поле :attribute должно быть уникальным', + 'mimes' => 'Допускаются файлы только с расширением jpeg,jpg,png', + 'min' => [ + 'string' => 'Поле «:attribute» должно быть не меньше :min символов', + 'integer' => 'Поле «:attribute» должно быть :min или больше', + 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' + ], + + 'max' => [ + 'string' => 'Поле «:attribute» должно быть не больше :max символов', + 'integer' => 'Поле «:attribute» должно быть :max или меньше', + 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' + ], + ]; } } diff --git a/app/Models/SEO.php b/app/Models/SEO.php index 6c38696..e00e00c 100644 --- a/app/Models/SEO.php +++ b/app/Models/SEO.php @@ -8,4 +8,11 @@ use Illuminate\Database\Eloquent\Model; class SEO extends Model { use HasFactory; + + protected $fillable = [ + 'url', + 'title', + 'description', + 'keywords', + 'name', ]; } diff --git a/resources/views/admin/seo/add.blade.php b/resources/views/admin/seo/add.blade.php index e69de29..77fde58 100644 --- a/resources/views/admin/seo/add.blade.php +++ b/resources/views/admin/seo/add.blade.php @@ -0,0 +1,7 @@ +@extends('layout.admin', ['title' => 'Админка - Добавление SEO страницы']) + +@section('content') +
+ @include('admin.seo.form') +
+@endsection diff --git a/resources/views/admin/seo/edit.blade.php b/resources/views/admin/seo/edit.blade.php index e69de29..4b574b6 100644 --- a/resources/views/admin/seo/edit.blade.php +++ b/resources/views/admin/seo/edit.blade.php @@ -0,0 +1,7 @@ +@extends('layout.admin', ['title' => 'Админка - Редактирование SEO страницы']) + +@section('content') +
+ @include('admin.seo.form') +
+@endsection diff --git a/resources/views/admin/seo/form.blade.php b/resources/views/admin/seo/form.blade.php index e69de29..e44cbe6 100644 --- a/resources/views/admin/seo/form.blade.php +++ b/resources/views/admin/seo/form.blade.php @@ -0,0 +1,100 @@ +@csrf + +@isset($page) + @method('PUT') +@endisset + +
+ + +
+ Получить мета-данные

+
+
+ +
+ +
+ +
+
+ +
+
+
diff --git a/routes/web.php b/routes/web.php index 7dd4198..d62310d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -184,6 +184,7 @@ Route::group([ Route::get('editor-seo', [CompanyController::class, 'editor_seo'])->name('editor-seo'); Route::get('editor-seo/add', [CompanyController::class, 'editor_seo_add'])->name('add-seo'); Route::post('editor-seo/add', [CompanyController::class, 'editor_seo_store'])->name('add-seo-store'); + Route::get('editor-seo/ajax', [CompanyController::class, 'editor_seo_ajax'])->name('ajax.seo'); Route::get('editor-seo/edit/{page}', [CompanyController::class, 'editor_seo_edit'])->name('edit-seo'); Route::put('editor-seo/edit/{page}', [CompanyController::class, 'editor_seo_update'])->name('update-seo'); Route::delete('editor-seo/delete/{page}', [CompanyController::class, 'editor_seo_destroy'])->name('delete-seo');