1
0
mirror of https://github.com/robonen/education-project.git synced 2026-03-20 02:44:31 +00:00
This commit is contained in:
nikden13
2020-12-16 03:13:20 +07:00
parent c93ffe8b0f
commit 045a767774
22 changed files with 231 additions and 54 deletions

View File

@@ -0,0 +1,65 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\ChatLinkRequest;
use App\Models\ChatLink;
use Illuminate\Database\QueryException;
class ChatLinkController extends Controller
{
//Получение ссылок для класса или для их создателя
public function index()
{
switch(auth()->user()->role->name)
{
case 'student':
$links = ChatLink::all()->where('class_id', auth()->user()->class_id);
break;
case 'teacher':
case 'headteacher':
$links = auth()->user()->chatLinks;
break;
case 'parent':
$links = [];
break;
}
return response()->json($links, 200);
}
//Создание ссылки
public function store(ChatLinkRequest $request)
{
try {
$link = auth()->user()->create($request->all());
} catch (QueryException $e) {
return response()->json(['message'=>'Class not found'], 404);
}
return response()->json($link, 201);
}
//Обновление ссылки
public function update(ChatLink $link, ChatLinkRequest $request)
{
try {
$link->update($request->all());
} catch (QueryException $e) {
return response()->json(['message'=>'Class not found'], 404);
}
return response()->json($link, 200);
}
//Удаление ссылки
public function destroy(ChatLink $link)
{
$link->delete();
return response()->json(null, 204);
}
}