forked from aslan/applicant-site
add EducationalInstitution resource
This commit is contained in:
parent
cc7d6eb5ea
commit
06c16d95c1
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\StoreEducationalInstitutionRequest;
|
||||
use App\Http\Requests\UpdateEducationalInstitutionRequest;
|
||||
use App\Models\EducationalInstitution;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Foundation\Application;
|
||||
|
||||
class EducationalInstitutionController extends Controller
|
||||
{
|
||||
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||
{
|
||||
$educationalInstitutions = EducationalInstitution::all();
|
||||
return view('educational-institution.index', compact('educationalInstitutions'));
|
||||
}
|
||||
|
||||
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
||||
{
|
||||
return view('educational-institution.create');
|
||||
}
|
||||
|
||||
public function store(StoreEducationalInstitutionRequest $request)
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
$educationalInstitution = new EducationalInstitution();
|
||||
$educationalInstitution->name = $validated['name'];
|
||||
$educationalInstitution->description = $validated['description'];
|
||||
$educationalInstitution->position = $validated['position'];
|
||||
$educationalInstitution->save();
|
||||
|
||||
return redirect()->route('educational-institutions.index');
|
||||
}
|
||||
|
||||
public function show(EducationalInstitution $educationalInstitution)
|
||||
{
|
||||
return view('educational-institution.show', compact('educationalInstitution'));
|
||||
}
|
||||
|
||||
public function edit(EducationalInstitution $educationalInstitution)
|
||||
{
|
||||
return view('educational-institution.edit', compact('educationalInstitution'));
|
||||
}
|
||||
|
||||
public function update(UpdateEducationalInstitutionRequest $request, EducationalInstitution $educationalInstitution)
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
$educationalInstitution->name = $validated['name'];
|
||||
$educationalInstitution->description = $validated['description'];
|
||||
$educationalInstitution->position = $validated['position'];
|
||||
$educationalInstitution->save();
|
||||
|
||||
return redirect()->route('educational-institutions.index');
|
||||
}
|
||||
|
||||
public function destroy(EducationalInstitution $educationalInstitution)
|
||||
{
|
||||
$educationalInstitution->delete();
|
||||
|
||||
return redirect()->route('educational-institutions.index');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StoreEducationalInstitutionRequest 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' => 'int|max:255',
|
||||
'name' => 'required|string|max:255|unique:educational_institutions,name',
|
||||
'description' => 'string',
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateEducationalInstitutionRequest 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' => 'int|max:255',
|
||||
'name' => 'required|string|max:255|unique:educational_institutions,name',
|
||||
'description' => 'string',
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EducationalInstitution extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\EducationalInstitution;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class EducationalInstitutionPolicy
|
||||
{
|
||||
/**
|
||||
* 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, EducationalInstitution $educationalInstitution): 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, EducationalInstitution $educationalInstitution): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, EducationalInstitution $educationalInstitution): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, EducationalInstitution $educationalInstitution): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, EducationalInstitution $educationalInstitution): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\EducationalInstitution>
|
||||
*/
|
||||
class EducationalInstitutionFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
<?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('educational_institutions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->text('description');
|
||||
$table->integer('position');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('educational_institutions');
|
||||
}
|
||||
};
|
|
@ -13,8 +13,8 @@ class DatabaseSeeder extends Seeder
|
|||
*/
|
||||
public function run(): void
|
||||
{
|
||||
User::factory(10)->create();
|
||||
|
||||
// User::factory(10)->create();
|
||||
//
|
||||
User::factory()->create([
|
||||
'name' => 'admin',
|
||||
'email' => 'test@example.com',
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class EducationalInstitutionSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
@extends('layouts.admin-layout')
|
||||
@section('content')
|
||||
|
||||
@auth()
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1 class=""> Создать учебное заведение</h1>
|
||||
{{ Form::open(['url' => route('educational-institutions.store'), 'method' => 'POST', 'class' => '']) }}
|
||||
<div class="col">
|
||||
<div>
|
||||
{{ Form::label('position', 'Позиция') }}
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
{{ Form::text('position', '', ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('position') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{{ Form::label('name', 'Название') }}
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
{{ Form::text('name', '', ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('name') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{{ Form::label('description', 'Описание') }}
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
{{ Form::text('description', '', ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('description') }}
|
||||
@endif
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
{{ Form::submit('создать', ['class' => 'btn btn-primary']) }}
|
||||
</div>
|
||||
</div>
|
||||
{{ Form::close() }}
|
||||
</div>
|
||||
</div>
|
||||
@endauth
|
||||
@endsection
|
|
@ -0,0 +1,53 @@
|
|||
@extends('layouts.admin-layout')
|
||||
@section('content')
|
||||
|
||||
@auth()
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h1 class="">Изменить учебное заведение</h1>
|
||||
{{ Form::open(['url' => route('educational-institutions.update', $educationalInstitution), 'method' => 'PATCH', 'class' => '']) }}
|
||||
<div class="col">
|
||||
<div>
|
||||
{{ Form::label('position', 'Позиция') }}
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
{{ Form::text('position', $educationalInstitution->position, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('position') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{{ Form::label('name', 'Название') }}
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
{{ Form::text('name', $educationalInstitution->name, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('name') }}
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{{ Form::label('description', 'Описание') }}
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
{{ Form::text('description', $educationalInstitution->description, ['class' => 'form-control']) }}
|
||||
</div>
|
||||
<div>
|
||||
@if ($errors->any())
|
||||
{{ $errors->first('description') }}
|
||||
@endif
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
|
||||
</div>
|
||||
</div>
|
||||
{{ Form::close() }}
|
||||
</div>
|
||||
</div>
|
||||
@endauth
|
||||
@endsection
|
|
@ -0,0 +1,42 @@
|
|||
@extends('layouts.admin-layout')
|
||||
@section('content')
|
||||
<div class="container">
|
||||
<h2>Учебные заведения</h2>
|
||||
<br>
|
||||
<a href="{{ route('educational-institutions.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>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="accordion" id="accordionExample">
|
||||
@foreach($educationalInstitutions as $educationalInstitution)
|
||||
<tr class="">
|
||||
<th scope="row">{{ $educationalInstitution->position }}</th>
|
||||
<td>{{ $educationalInstitution->name }}</td>
|
||||
<td>{{ $educationalInstitution->description }}</td>
|
||||
<td><a href="{{ route("educational-institutions.edit", $educationalInstitution) }}"
|
||||
class="btn btn-secondary">редактировать</a>
|
||||
<a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
|
||||
href="{{ route('educational-institutions.destroy', $educationalInstitution) }}"
|
||||
class="btn btn-danger">
|
||||
удалить
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
<br>
|
||||
<br>
|
||||
</div>
|
||||
|
||||
@endsection
|
|
@ -54,6 +54,7 @@
|
|||
@if(!is_null(Auth::getUser()) && Auth::getUser()->name === 'admin')
|
||||
{{-- <li class="list-group-item"></li>--}}
|
||||
<li class="list-group-item"><a href="{{ route('users.index') }}">Список администраторов</a></li>
|
||||
<li class="list-group-item"><a href="{{ route('educational-institutions.index') }}">Учебные заведения</a></li>
|
||||
@endif
|
||||
</ul>
|
||||
</aside>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\EducationalInstitutionController;
|
||||
use App\Http\Controllers\FileController;
|
||||
use App\Http\Controllers\PageController;
|
||||
use App\Http\Controllers\ProfileController;
|
||||
|
@ -24,6 +25,7 @@ Route::get('/', function () {
|
|||
|
||||
Route::resource('/users', UserController::class)->middleware(['auth', 'verified']);
|
||||
Route::resource('/admin-reception-screen', ReceptionScreenController::class)->middleware(['auth', 'verified']);
|
||||
Route::resource('/educational-institutions', EducationalInstitutionController::class)->middleware(['auth', 'verified']);
|
||||
Route::get('/files', [FileController::class, 'index'])->name('files.index');
|
||||
Route::post('/files', [FileController::class, 'store'])->name('files.store');
|
||||
Route::get('/files/create/{file?}', [FileController::class, 'create'])->name('files.create');
|
||||
|
|
Loading…
Reference in New Issue