You've already forked isop-mirror
feat: implement student management features including listing, editing, and updating student data
This commit is contained in:
@@ -8,7 +8,8 @@ use Illuminate\Http\Request;
|
||||
|
||||
class CompanyController extends Controller
|
||||
{
|
||||
public function all_simple() {
|
||||
public function all_simple()
|
||||
{
|
||||
$companies = Company::all()->makeHidden(['created_at', 'updated_at']);
|
||||
|
||||
$companies->each(function ($company) {
|
||||
@@ -18,6 +19,84 @@ class CompanyController extends Controller
|
||||
return response()->json($companies);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific company with contact details.
|
||||
*/
|
||||
public function get(int $id)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if ($user->role !== 'ADMIN') {
|
||||
abort(403, 'Unauthorized');
|
||||
}
|
||||
|
||||
$company = Company::find($id);
|
||||
|
||||
if (!$company) {
|
||||
return response()->json([
|
||||
'message' => 'No such company exists.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
$company->contact = User::find($company->contact)->makeHidden(['created_at', 'updated_at', 'email_verified_at']);
|
||||
|
||||
return response()->json($company);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update company information and contact person.
|
||||
*/
|
||||
public function update_all(int $id, Request $request)
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
if ($user->role !== 'ADMIN') {
|
||||
abort(403, 'Unauthorized');
|
||||
}
|
||||
|
||||
$company = Company::find($id);
|
||||
|
||||
if (!$company) {
|
||||
return response()->json([
|
||||
'message' => 'No such company exists.'
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Validácia dát
|
||||
$request->validate([
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'address' => ['required', 'string', 'max:500'],
|
||||
'ico' => ['required', 'integer'],
|
||||
'hiring' => ['required', 'boolean'],
|
||||
'contact.name' => ['required', 'string', 'max:255'],
|
||||
'contact.email' => ['required', 'email', 'max:255', 'unique:users,email,' . $company->contact],
|
||||
'contact.phone' => ['nullable', 'string', 'max:20'],
|
||||
]);
|
||||
|
||||
// Aktualizácia Company údajov
|
||||
$company->update([
|
||||
'name' => $request->name,
|
||||
'address' => $request->address,
|
||||
'ico' => $request->ico,
|
||||
'hiring' => $request->hiring,
|
||||
]);
|
||||
|
||||
// Aktualizácia kontaktnej osoby
|
||||
if ($request->has('contact')) {
|
||||
$contactPerson = User::find($company->contact);
|
||||
|
||||
if ($contactPerson) {
|
||||
$contactPerson->update([
|
||||
'name' => $request->contact['name'],
|
||||
'email' => $request->contact['email'],
|
||||
'phone' => $request->contact['phone'] ?? null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user