prodV1 #2

Open
RomanGolienko wants to merge 309 commits from prodV1 into main
14 changed files with 532 additions and 0 deletions
Showing only changes of commit 56d4f387b8 - Show all commits

View File

@ -0,0 +1,78 @@
<?php
namespace App\Http\Controllers\Catalog;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreDepartmentRequest;
use App\Http\Requests\StoreDirectionRequest;
use App\Http\Requests\UpdateDepartmentRequest;
use App\Http\Requests\UpdateDirectionRequest;
use App\Models\Department;
use App\Models\Direction;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Foundation\Application;
use Illuminate\Http\RedirectResponse;
class DirectionController extends Controller
{
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$directions = Direction::all();
return view('catalog.direction.index', compact('directions'));
}
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$departments = Department::pluck('name', 'id');
return view('catalog.direction.create', compact('departments'));
}
public function store(StoreDirectionRequest $request): RedirectResponse
{
$validated = $request->validated();
$direction = new Direction();
$direction->name = $validated['name'];
$direction->description = $validated['description'];
$direction->position = $validated['position'];
$direction->slug = $validated['slug'];
$direction->department_id = $validated['department_id'];
$direction->save();
return redirect()->route('directions.index');
}
public function show(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
return view('catalog.direction.show', compact('direction'));
}
public function edit(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
{
$departments = Department::pluck('name', 'id');
return view('catalog.direction.edit', compact('direction', 'departments'));
}
/**
* Update the specified resource in storage.
*/
public function update(UpdateDepartmentRequest $request, Direction $direction)
{
$validated = $request->validated();
$direction->name = $validated['name'];
$direction->description = $validated['description'];
$direction->position = $validated['position'];
$direction->department_id = $validated['department_id'];
$direction->save();
return redirect()->route('directions.index');
}
public function destroy(Direction $direction): RedirectResponse
{
$direction->delete();
return redirect()->route('directions.index');
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StoreDirectionRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'position' => 'required|int|max:255',
'name' => 'required|string|max:255|unique:educational_institutions,name',
'description' => 'string',
'slug' => 'required|string',
'department_id' => 'required|int'
];
}
}

View File

@ -0,0 +1,37 @@
<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
class UpdateDirectionRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array|string>
*/
public function rules(): array
{
return [
'position' => 'int|max:255',
'description' => 'string',
'department_id' => 'int|required',
'name' => [
'required',
'string',
'max:255',
"unique:educational_institutions,name,{$this->direction->id}",
],
];
}
}

24
app/Models/Direction.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Direction extends Model
{
use HasFactory;
protected $fillable = [
'id',
'name',
'description',
'position',
];
public function department(): BelongsTo
{
return $this->belongsTo(Department::class);
}
}

View File

@ -0,0 +1,66 @@
<?php
namespace App\Policies;
use App\Models\Direction;
use App\Models\User;
use Illuminate\Auth\Access\Response;
class DirectionPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
//
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, Direction $direction): bool
{
//
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
//
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, Direction $direction): bool
{
//
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, Direction $direction): bool
{
//
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, Direction $direction): bool
{
//
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, Direction $direction): bool
{
//
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Direction>
*/
class DirectionFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
//
];
}
}

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('directions', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->text('description');
$table->integer('position');
$table->string('slug');
$table->foreignId('department_id')->constrained('departments');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('directions');
}
};

View File

@ -0,0 +1,17 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class DirectionSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
//
}
}

View File

@ -0,0 +1,75 @@
@extends('layouts.admin-layout')
@section('content')
@auth()
<div class="row">
<div class="col">
<h1 class=""> Создать Направление</h1>
{{ Form::open(['url' => route('directions.store'), 'method' => 'POST', 'class' => '']) }}
<div class="col">
<div class="mt-3">
{{ Form::label('position', 'Позиция') }}
</div>
<div class="mt-1">
{{ Form::text('position', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('name', 'Название') }}
</div>
<div class="mt-1">
{{ Form::text('name', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('name') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('description', 'Описание') }}
</div>
<div class="mt-1">
{{ Form::text('description', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('description') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('department_id', 'Кафедры') }}
</div>
<div class="mt-1">
{{ Form::select('department_id', $departments, null, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('department_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('slug', 'URL') }}
</div>
<div class="mt-1">
{{ Form::text('slug', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('slug') }}
@endif
</div>
<div class="mt-3">
{{ Form::submit('Создать', ['class' => 'btn btn-primary']) }}
</div>
</div>
{{ Form::close() }}
</div>
</div>
@endauth
@endsection

View File

@ -0,0 +1,64 @@
@extends('layouts.admin-layout')
@section('content')
@auth()
<div class="row">
<div class="col">
<h1 class=""> Создать кафедру</h1>
{{ Form::open(['url' => route('departments.update', $direction), 'method' => 'PATCH', 'class' => '']) }}
<div class="col">
<div class="mt-3">
{{ Form::label('position', 'Позиция') }}
</div>
<div class="mt-1">
{{ Form::text('position', $direction->position, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('name', 'Название') }}
</div>
<div class="mt-1">
{{ Form::text('name', $direction->name, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('name') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('description', 'Описание') }}
</div>
<div class="mt-1">
{{ Form::text('description', $direction->description, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('description') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('educational_institution_id', 'Факультет') }}
</div>
<div class="mt-1">
{{ Form::select('faculty_id', $departments, $direction->department->id, ['class' => 'form-select']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('educational_institution_id') }}
@endif
</div>
<div class="mt-3">
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
</div>
</div>
{{ Form::close() }}
</div>
</div>
@endauth
@endsection

View File

@ -0,0 +1,43 @@
@extends('layouts.admin-layout')
@section('content')
<div class="container">
<h2>Направления</h2>
<br>
<a href="{{ route('directions.create') }}" class="btn btn-primary">Создать Направление</a>
<br>
<br>
<table class="table">
<thead class="border-b-2 border-solid border-black text-left" style="text-align: left">
<tr>
<th scope="col">Позиция</th>
<th scope="col">Название</th>
<th scope="col">Описание</th>
<th scope="col">Кафедра</th>
<th scope="col">действия</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
@foreach($directions as $direction)
<tr class="">
<th scope="row">{{ $direction->position }}</th>
<td><a href="{{ route('directions.show', $direction) }}">{{ $direction->name }}</a></td>
<td>{{ Str::words($direction->description, 10, '...') }}</td>
<td>{{ $direction->department->name }}</td>
<td>
<a href="{{ route("directions.edit", $direction) }}"
class="btn btn-secondary">редактировать</a>
<a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
href="{{ route('directions.destroy', $direction) }}"
class="btn btn-danger">удалить</a>
</td>
</tr>
@endforeach
</tbody>
</table>
<br>
<br>
</div>
@endsection

View File

@ -0,0 +1,36 @@
@php
use App\Models\Direction;
use App\Models\Department;
use App\Models\EducationalInstitution;use App\Models\Faculty;use Illuminate\Support\Collection;
/** @var Collection|Direction[] $direction */
$department = Department::find($direction->department->id);
$faculty = Faculty::find($department->faculty->id);
$educationalInstitution = EducationalInstitution::find($faculty->educationalInstitution->id);
@endphp
@extends('layouts.admin-layout')
@section('content')
@auth()
<h6>
<a href="{{ route('educational-institutions.show', $educationalInstitution) }}">
{{ $educationalInstitution->name }}
</a>
->
<a href="{{ route('faculties.show', $faculty) }}">{{ $faculty->name }}</a>
->
<a href="{{ route('faculties.show', $department) }}">{{ $department->name }}</a>
-> {{ $direction->name }}
</h6>
<div class="container mt-4">
<h2>Название</h2>
<p>{{ $direction->name }}</p>
<h2>Описание</h2>
<p>{{ $direction->description }}</p>
<h2>Позиция</h2>
<p>{{ $direction->position }}</p>
<h2>Кафедра</h2>
<p><a href="{{ route('departments.show', $department) }}">{{ $department->name }}</a></p>
</div>
@endauth
@endsection

View File

@ -62,6 +62,7 @@
заведения</a></li>
<li class="list-group-item"><a href="{{ route('faculties.index') }}">Факультеты</a></li>
<li class="list-group-item"><a href="{{ route('departments.index') }}">Кафедры</a></li>
<li class="list-group-item"><a href="{{ route('directions.index') }}">Направления</a></li>
</ul>
</aside>
<main class="col-10">@yield('content')</main>

View File

@ -1,6 +1,7 @@
<?php
use App\Http\Controllers\Catalog\DepartmentController;
use App\Http\Controllers\Catalog\DirectionController;
use App\Http\Controllers\Catalog\EducationalInstitutionController;
use App\Http\Controllers\Catalog\FacultyController;
use App\Http\Controllers\DocumentController;
@ -17,6 +18,9 @@ Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () {
Route::resource('/educational-institutions', EducationalInstitutionController::class)
->scoped(['educational_institution' => 'slug']);
Route::resource('/directions', DirectionController::class)
->scoped(['educational_institution' => 'slug']);
Route::resources([
'/files' => DocumentController::class,
'/users' => UserController::class,