diff --git a/app/Http/Controllers/Admin/AdminController.php b/app/Http/Controllers/Admin/AdminController.php index a261d8f..30daf91 100644 --- a/app/Http/Controllers/Admin/AdminController.php +++ b/app/Http/Controllers/Admin/AdminController.php @@ -3,11 +3,14 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; +use App\Http\Requests\CompanyRequest; +use App\Models\Company; use App\Models\Employer; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; +use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Validator; class AdminController extends Controller @@ -159,4 +162,49 @@ class AdminController extends Controller } } + public function profile() { + $id = Auth::user()->id; + $user = User::find($id); + + return view('admin.profile', compact('user')); + } + + public function store_profile(Request $request) { + $id = Auth::user()->id; + $user = User::find($id); + + return redirect()->route('admin.profile'); + } + + public function config_form() { + $config = Company::find(1); + return view('admin.config', compact('config')); + } + + public function store_config(CompanyRequest $request) { + $config = Company::find(1); + + $params = $request->all(); + unset($params['logo']); + unset($params['image']); + + if ($request->has('logo')) { + Storage::delete($config->logo); + $params['logo'] = $request->file('logo')->store('config', 'public'); + } + + if ($request->has('image')) { + Storage::delete($config->image); + $params['image'] = $request->file('image')->store('config', 'public'); + } + + if (is_null($config)) { + Company::create($params); + } else { + $config->update($params); + } + + return redirect()->route('admin.config'); + } + } diff --git a/app/Http/Controllers/Admin/CompanyController.php b/app/Http/Controllers/Admin/CompanyController.php new file mode 100644 index 0000000..da215ff --- /dev/null +++ b/app/Http/Controllers/Admin/CompanyController.php @@ -0,0 +1,11 @@ + + */ + public function rules() + { + return [ + 'name' => 'required|min:1|max:255', + 'email' => 'required|email|min:5', + 'logo' => [ + 'mimes:jpeg,jpg,png,ico', + 'max:10000' + ], + 'image' => [ + 'mimes:jpeg,jpg,png', + 'max:10000' + ], + ]; + } + + public function messages() { + return [ + 'required' => 'Поле :attribute обязательно для ввода', + 'min' => [ + 'string' => 'Поле «:attribute» должно быть не меньше :min символов', + 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' + ], + 'max' => [ + 'string' => 'Поле «:attribute» должно быть не больше :max символов', + 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' + ], + 'email' => 'Это поле должно быть формата email', + ]; + } +} diff --git a/app/Models/Answer.php b/app/Models/Answer.php new file mode 100644 index 0000000..c2e96b1 --- /dev/null +++ b/app/Models/Answer.php @@ -0,0 +1,11 @@ +id(); + $table->string('name', 255)->nullable(true); + $table->boolean('is_email')->default(false); + $table->bigInteger('employer_id')->nullable(false); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('contacts'); + } +}; diff --git a/database/migrations/2023_05_22_084651_create_flots_table.php b/database/migrations/2023_05_22_084651_create_flots_table.php new file mode 100644 index 0000000..23e6d81 --- /dev/null +++ b/database/migrations/2023_05_22_084651_create_flots_table.php @@ -0,0 +1,35 @@ +id(); + $table->string('name', 255)->nullable(true); + $table->text('text')->nullable(true); + $table->string('image', 255)->nullable(true); + $table->bigInteger('employer_id')->nullable(false); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('flots'); + } +}; diff --git a/database/migrations/2023_05_22_084739_create_answers_table.php b/database/migrations/2023_05_22_084739_create_answers_table.php new file mode 100644 index 0000000..2c1de7e --- /dev/null +++ b/database/migrations/2023_05_22_084739_create_answers_table.php @@ -0,0 +1,39 @@ +id(); + $table->bigInteger('employer_id')->nullable(false); + $table->integer('plus')->default(0); + $table->integer('minus')->default(0); + $table->integer('rate')->nullable(true); + $table->string('title', 255)->nullable(true); + $table->string('text', 255)->nullable(true); + $table->boolean('is_moderate')->default(false); + $table->bigInteger('user_id')->nullable(false); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('answers'); + } +}; diff --git a/database/migrations/2023_05_22_085010_create_companies_table.php b/database/migrations/2023_05_22_085010_create_companies_table.php new file mode 100644 index 0000000..f02cd40 --- /dev/null +++ b/database/migrations/2023_05_22_085010_create_companies_table.php @@ -0,0 +1,43 @@ +id(); + $table->string('name', 255)->nullable(true); + $table->string('address', 255)->nullable(true); + $table->string('fio_director', 255)->nullable(true); + $table->string('email', 255)->nullable(true); + $table->string('telephone', 255)->nullable(true); + $table->string('site', 255)->nullable(true); + $table->string('telegram', 255)->nullable(true); + $table->string('vkontact', 255)->nullable(true); + $table->string('logo', 255)->nullable(true); + $table->string('image', 255)->nullable(true); + $table->string('map', 255)->nullable(true); + $table->text('text')->nullable(true); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('companies'); + } +}; diff --git a/resources/views/admin/config.blade.php b/resources/views/admin/config.blade.php new file mode 100644 index 0000000..b3b25de --- /dev/null +++ b/resources/views/admin/config.blade.php @@ -0,0 +1,189 @@ +@extends('layout.admin', ['title' => 'Админка - Настройки']) + +@section('content') +