Correction code style

This commit is contained in:
m.zargarov 2024-05-06 17:51:16 +04:00
parent 67a02034f1
commit fb2fda38bb
14 changed files with 26 additions and 28 deletions

View File

@ -12,7 +12,8 @@ class GradeController extends Controller
{ {
public function __construct( public function __construct(
protected ServiceInterface $service, protected ServiceInterface $service,
){} ) {
}
/** /**
* Display a listing of the resource. * Display a listing of the resource.
@ -46,7 +47,7 @@ class GradeController extends Controller
public function show(Grade $grade): View public function show(Grade $grade): View
{ {
return view('grades.show', [ return view('grades.show', [
'grade' => $grade, 'grade' => $grade,
]); ]);
} }

View File

@ -13,7 +13,8 @@ class StudentController extends Controller
{ {
public function __construct( public function __construct(
protected ServiceInterface $service protected ServiceInterface $service
){} ) {
}
/** /**
* Display a listing of the resource. * Display a listing of the resource.

View File

@ -12,7 +12,8 @@ class SubjectController extends Controller
{ {
public function __construct( public function __construct(
protected ServiceInterface $service, protected ServiceInterface $service,
){} ) {
}
/** /**
* Display a listing of the resource. * Display a listing of the resource.
@ -20,7 +21,7 @@ class SubjectController extends Controller
public function index(): View public function index(): View
{ {
return view('subjects.index', [ return view('subjects.index', [
"subjects" => $this->service->getAll(), 'subjects' => $this->service->getAll(),
]); ]);
} }
@ -49,7 +50,7 @@ class SubjectController extends Controller
public function show(Subject $subject): View public function show(Subject $subject): View
{ {
return view('subjects.show', [ return view('subjects.show', [
"subject" => $subject 'subject' => $subject,
]); ]);
} }

View File

@ -13,7 +13,8 @@ class SubjectTeacherController extends Controller
{ {
public function __construct( public function __construct(
protected ServiceInterface $service, protected ServiceInterface $service,
){} ) {
}
public function create(Teacher $teacher): View public function create(Teacher $teacher): View
{ {
@ -25,7 +26,7 @@ class SubjectTeacherController extends Controller
public function store(SubjectTeacherPostRequest $request, Teacher $teacher): RedirectResponse public function store(SubjectTeacherPostRequest $request, Teacher $teacher): RedirectResponse
{ {
return redirect()->route('teachers.show', $this->service->create($request->validated(), $teacher)); return redirect()->route('teachers.show', $this->service->create($request->validated(), $teacher));
} }
public function edit(Teacher $teacher, Subject $subject): View public function edit(Teacher $teacher, Subject $subject): View

View File

@ -12,7 +12,8 @@ class TeacherController extends Controller
{ {
public function __construct( public function __construct(
protected ServiceInterface $service protected ServiceInterface $service
){} ) {
}
/** /**
* Display a listing of the resource. * Display a listing of the resource.

View File

@ -2,8 +2,6 @@
namespace App\Http\Requests; namespace App\Http\Requests;
use App\Enums\RoleEnum;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
class StudentPostRequest extends FormRequest class StudentPostRequest extends FormRequest

View File

@ -2,8 +2,6 @@
namespace App\Http\Requests; namespace App\Http\Requests;
use App\Enums\RoleEnum;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest; use Illuminate\Foundation\Http\FormRequest;
class TeacherPostRequest extends FormRequest class TeacherPostRequest extends FormRequest

View File

@ -2,12 +2,13 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\Builder;
class Student extends Model class Student extends Model
{ {
use HasFactory; use HasFactory;
@ -33,7 +34,7 @@ class Student extends Model
public function scopeFilter(Builder $query): void public function scopeFilter(Builder $query): void
{ {
$name = request('name'); $name = request('name');
$query->when($name, function (Builder $query, $name){ $query->when($name, function (Builder $query, $name) {
$query->whereRaw('CONCAT (name, \' \', surname, \' \', patronymic) ilike ?', ["$name%"]); $query->whereRaw('CONCAT (name, \' \', surname, \' \', patronymic) ilike ?', ["$name%"]);
$query->orWhereRaw('CONCAT (name, \' \', patronymic, \' \', surname) ilike ?', ["$name%"]); $query->orWhereRaw('CONCAT (name, \' \', patronymic, \' \', surname) ilike ?', ["$name%"]);
$query->orWhereRaw('CONCAT (surname, \' \', name, \' \', patronymic) ilike ?', ["$name%"]); $query->orWhereRaw('CONCAT (surname, \' \', name, \' \', patronymic) ilike ?', ["$name%"]);
@ -46,7 +47,7 @@ class Student extends Model
public function fio(): Attribute public function fio(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: fn () => $this->last_name . " " . $this->name . " " . $this->middle_name, get: fn () => $this->last_name.' '.$this->name.' '.$this->middle_name,
); );
} }
} }

View File

@ -2,12 +2,13 @@
namespace App\Models; namespace App\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\Builder;
class Teacher extends Model class Teacher extends Model
{ {
use HasFactory; use HasFactory;
@ -37,7 +38,7 @@ class Teacher extends Model
public function scopeFilter(Builder $query): void public function scopeFilter(Builder $query): void
{ {
$name = request('name'); $name = request('name');
$query->when($name, function (Builder $query, $name){ $query->when($name, function (Builder $query, $name) {
$query->whereRaw('CONCAT (name, \' \', surname, \' \', patronymic) ilike ?', ["$name%"]); $query->whereRaw('CONCAT (name, \' \', surname, \' \', patronymic) ilike ?', ["$name%"]);
$query->orWhereRaw('CONCAT (name, \' \', patronymic, \' \', surname) ilike ?', ["$name%"]); $query->orWhereRaw('CONCAT (name, \' \', patronymic, \' \', surname) ilike ?', ["$name%"]);
$query->orWhereRaw('CONCAT (surname, \' \', name, \' \', patronymic) ilike ?', ["$name%"]); $query->orWhereRaw('CONCAT (surname, \' \', name, \' \', patronymic) ilike ?', ["$name%"]);
@ -50,7 +51,7 @@ class Teacher extends Model
public function fio(): Attribute public function fio(): Attribute
{ {
return Attribute::make( return Attribute::make(
get: fn () => $this->last_name . " " . $this->name . " " . $this->middle_name, get: fn () => $this->last_name.' '.$this->name.' '.$this->middle_name,
); );
} }
} }

View File

@ -8,7 +8,6 @@ use Illuminate\Pagination\LengthAwarePaginator;
class GradeService implements ServiceInterface class GradeService implements ServiceInterface
{ {
public function getAll(): LengthAwarePaginator public function getAll(): LengthAwarePaginator
{ {
return Grade::filter()->paginate(5)->withQueryString(); return Grade::filter()->paginate(5)->withQueryString();

View File

@ -3,9 +3,7 @@
namespace App\Services; namespace App\Services;
use App\Models\Student; use App\Models\Student;
use App\Models\Teacher;
use App\Models\User; use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\LengthAwarePaginator;
class StudentService implements ServiceInterface class StudentService implements ServiceInterface

View File

@ -8,7 +8,6 @@ use Illuminate\Pagination\LengthAwarePaginator;
class SubjectService implements ServiceInterface class SubjectService implements ServiceInterface
{ {
public function getAll(): LengthAwarePaginator public function getAll(): LengthAwarePaginator
{ {
return Subject::filter()->paginate(5)->withQueryString(); return Subject::filter()->paginate(5)->withQueryString();

View File

@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Model;
class SubjectTeacherService implements ServiceInterface class SubjectTeacherService implements ServiceInterface
{ {
public function getAll(Teacher $teacher = null): Collection public function getAll(?Teacher $teacher = null): Collection
{ {
return $teacher->subjects; return $teacher->subjects;
} }
@ -19,14 +19,14 @@ class SubjectTeacherService implements ServiceInterface
return Subject::all(); return Subject::all();
} }
public function create(array $data, Model $model = null): Teacher public function create(array $data, ?Model $model = null): Teacher
{ {
$model->subjects()->syncWithoutDetaching($data['subject_id']); $model->subjects()->syncWithoutDetaching($data['subject_id']);
return $model; return $model;
} }
public function update(Model $model, array $data, Model $subject = null): Teacher public function update(Model $model, array $data, ?Model $subject = null): Teacher
{ {
$model->subjects()->detach($subject->id); $model->subjects()->detach($subject->id);
$model->subjects()->attach($data['subject_id']); $model->subjects()->attach($data['subject_id']);
@ -34,7 +34,7 @@ class SubjectTeacherService implements ServiceInterface
return $model; return $model;
} }
public function delete(Model $model, Model $subject = null): Teacher public function delete(Model $model, ?Model $subject = null): Teacher
{ {
$model->subjects()->detach($subject); $model->subjects()->detach($subject);

View File

@ -2,7 +2,6 @@
namespace App\Services; namespace App\Services;
use App\Models\Student;
use App\Models\Teacher; use App\Models\Teacher;
use App\Models\User; use App\Models\User;
use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\LengthAwarePaginator;