refactoring fix lint Direction resource
This commit is contained in:
parent
1091847227
commit
c5abf73eb0
|
@ -1,10 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Catalog;
|
namespace App\Http\Controllers\admin\Catalog;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\StoreDirectionRequest;
|
use App\Http\Requests\admin\Catalog\StoreDirectionRequest;
|
||||||
use App\Http\Requests\UpdateDepartmentRequest;
|
use App\Http\Requests\admin\Catalog\UpdateDepartmentRequest;
|
||||||
|
use App\Http\Requests\admin\Catalog\UpdateDirectionRequest;
|
||||||
use App\Models\Department;
|
use App\Models\Department;
|
||||||
use App\Models\Direction;
|
use App\Models\Direction;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
|
@ -17,13 +18,13 @@ class DirectionController extends Controller
|
||||||
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||||
{
|
{
|
||||||
$directions = Direction::all();
|
$directions = Direction::all();
|
||||||
return view('catalog.direction.index', compact('directions'));
|
return view('admin.catalog.direction.index', compact('directions'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||||
{
|
{
|
||||||
$departments = Department::pluck('name', 'id');
|
$departments = Department::pluck('name', 'id');
|
||||||
return view('catalog.direction.create', compact('departments'));
|
return view('admin.catalog.direction.create', compact('departments'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(StoreDirectionRequest $request): RedirectResponse
|
public function store(StoreDirectionRequest $request): RedirectResponse
|
||||||
|
@ -43,22 +44,23 @@ class DirectionController extends Controller
|
||||||
|
|
||||||
public function show(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
public function show(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||||
{
|
{
|
||||||
return view('catalog.direction.show', compact('direction'));
|
return view('admin.catalog.direction.show', compact('direction'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
public function edit(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||||
{
|
{
|
||||||
$departments = Department::pluck('name', 'id');
|
$departments = Department::pluck('name', 'id');
|
||||||
return view('catalog.direction.edit', compact('direction', 'departments'));
|
return view('admin.catalog.direction.edit', compact('direction', 'departments'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(UpdateDepartmentRequest $request, Direction $direction): RedirectResponse
|
public function update(UpdateDirectionRequest $request, Direction $direction): RedirectResponse
|
||||||
{
|
{
|
||||||
$validated = $request->validated();
|
$validated = $request->validated();
|
||||||
|
|
||||||
$direction->name = $validated['name'];
|
$direction->name = $validated['name'];
|
||||||
$direction->description = $validated['description'];
|
$direction->description = $validated['description'];
|
||||||
$direction->position = $validated['position'];
|
$direction->position = $validated['position'];
|
||||||
|
$direction->slug = $validated['slug'];
|
||||||
$direction->department_id = $validated['department_id'];
|
$direction->department_id = $validated['department_id'];
|
||||||
$direction->save();
|
$direction->save();
|
||||||
|
|
|
@ -1,24 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Requests\Catalog;
|
namespace App\Http\Requests\admin\Catalog;
|
||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
class StoreDirectionRequest extends FormRequest
|
class StoreDirectionRequest extends FormRequest
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Determine if the user is authorized to make this request.
|
|
||||||
*/
|
|
||||||
public function authorize(): bool
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return true;
|
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
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
|
@ -1,31 +1,24 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Requests\Catalog;
|
namespace App\Http\Requests\admin\Catalog;
|
||||||
|
|
||||||
use Illuminate\Contracts\Validation\ValidationRule;
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
class UpdateDirectionRequest extends FormRequest
|
class UpdateDirectionRequest extends FormRequest
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Determine if the user is authorized to make this request.
|
|
||||||
*/
|
|
||||||
public function authorize(): bool
|
public function authorize(): bool
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the validation rules that apply to the request.
|
|
||||||
*
|
|
||||||
* @return array<string, ValidationRule|array|string>
|
|
||||||
*/
|
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'position' => 'int|max:255',
|
'position' => 'int|max:255',
|
||||||
'description' => 'string',
|
'description' => 'string',
|
||||||
'department_id' => 'int|required',
|
'department_id' => 'int|required',
|
||||||
|
'slug' => 'required|string',
|
||||||
'name' => [
|
'name' => [
|
||||||
'required',
|
'required',
|
||||||
'string',
|
'string',
|
|
@ -1,66 +0,0 @@
|
||||||
<?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
|
|
||||||
{
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,20 +4,16 @@ namespace Database\Factories;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
/**
|
|
||||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Direction>
|
|
||||||
*/
|
|
||||||
class DirectionFactory extends Factory
|
class DirectionFactory extends Factory
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Define the model's default state.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function definition(): array
|
public function definition(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
//
|
'name' => fake()->name(),
|
||||||
|
'description' => fake()->text(),
|
||||||
|
'slug' => fake()->slug(),
|
||||||
|
'position' => fake()->randomDigit(),
|
||||||
|
'department_id' => 1,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,16 +2,13 @@
|
||||||
|
|
||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
use App\Models\Direction;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class DirectionSeeder extends Seeder
|
class DirectionSeeder extends Seeder
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Run the database seeds.
|
|
||||||
*/
|
|
||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
//
|
Direction::factory(3)->create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
@extends('layouts.admin-layout')
|
@extends('layouts.admin-layout')
|
||||||
@section('content')
|
@section('content')
|
||||||
|
|
||||||
@auth()
|
@auth()
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
@extends('layouts.admin-layout')
|
@extends('layouts.admin-layout')
|
||||||
@section('content')
|
@section('content')
|
||||||
|
|
||||||
@auth()
|
@auth()
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
|
@ -53,6 +53,17 @@
|
||||||
{{ $errors->first('educational_institution_id') }}
|
{{ $errors->first('educational_institution_id') }}
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mt-3">
|
||||||
|
{{ Form::label('slug', 'URL') }}
|
||||||
|
</div>
|
||||||
|
<div class="mt-1">
|
||||||
|
{{ Form::text('slug', $direction->slug, ['class' => 'form-control']) }}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
@if ($errors->any())
|
||||||
|
{{ $errors->first('slug') }}
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
|
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
|
||||||
</div>
|
</div>
|
|
@ -13,6 +13,7 @@
|
||||||
<th scope="col">Позиция</th>
|
<th scope="col">Позиция</th>
|
||||||
<th scope="col">Название</th>
|
<th scope="col">Название</th>
|
||||||
<th scope="col">Описание</th>
|
<th scope="col">Описание</th>
|
||||||
|
<th scope="col">URL</th>
|
||||||
<th scope="col">Кафедра</th>
|
<th scope="col">Кафедра</th>
|
||||||
<th scope="col">действия</th>
|
<th scope="col">действия</th>
|
||||||
<th scope="col"></th>
|
<th scope="col"></th>
|
||||||
|
@ -24,6 +25,7 @@
|
||||||
<th scope="row">{{ $direction->position }}</th>
|
<th scope="row">{{ $direction->position }}</th>
|
||||||
<td><a href="{{ route('directions.show', $direction) }}">{{ $direction->name }}</a></td>
|
<td><a href="{{ route('directions.show', $direction) }}">{{ $direction->name }}</a></td>
|
||||||
<td>{{ Str::words($direction->description, 10, '...') }}</td>
|
<td>{{ Str::words($direction->description, 10, '...') }}</td>
|
||||||
|
<td>{{ $direction->slug }}</td>
|
||||||
<td>{{ $direction->department->name }}</td>
|
<td>{{ $direction->department->name }}</td>
|
||||||
<td>
|
<td>
|
||||||
<a href="{{ route("directions.edit", $direction) }}"
|
<a href="{{ route("directions.edit", $direction) }}"
|
||||||
|
@ -39,5 +41,4 @@
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@endsection
|
@endsection
|
|
@ -0,0 +1,108 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\admin\catalog;
|
||||||
|
|
||||||
|
use App\Models\Department;
|
||||||
|
use App\Models\Direction;
|
||||||
|
use App\Models\EducationalInstitution;
|
||||||
|
use App\Models\Faculty;
|
||||||
|
use App\Models\User;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class DirectionTest extends TestCase
|
||||||
|
{
|
||||||
|
private User $user;
|
||||||
|
private Direction $direction;
|
||||||
|
private array $data;
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
EducationalInstitution::factory()->create();
|
||||||
|
Faculty::factory()->create();
|
||||||
|
Department::factory()->create();
|
||||||
|
|
||||||
|
$this->direction = Direction::factory()->create();
|
||||||
|
$this->data = Direction::factory()->make()->only([
|
||||||
|
'position',
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
'slug',
|
||||||
|
'department_id',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->user = User::factory()->create([
|
||||||
|
'name' => 'admin',
|
||||||
|
'email' => 'test@example.com',
|
||||||
|
'password' => 123456
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIndexDirectionsPage(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->get(route('directions.index'));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreateDirectionPage(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->get(route('directions.create'));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testStoreDirection(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->post(route('directions.store', $this->data));
|
||||||
|
|
||||||
|
$response->assertRedirect(route('directions.index'));
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('directions', $this->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testShowDirectionPage(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->get(route('directions.show', $this->direction));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEditDirectionPage(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->get(route('directions.edit', $this->direction));
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateDirection(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->patch(route('directions.update', $this->direction), $this->data);
|
||||||
|
|
||||||
|
$response->assertRedirect(route('directions.index'));
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('directions', $this->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDestroyDirection(): void
|
||||||
|
{
|
||||||
|
$response = $this->actingAs($this->user)
|
||||||
|
->withSession(['banned' => false])
|
||||||
|
->delete(route('directions.destroy', $this->direction));
|
||||||
|
|
||||||
|
$response->assertRedirect(route('directions.index'));
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('directions', $this->direction->toArray());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue