mirror of
https://github.com/robonen/education-project.git
synced 2026-03-20 02:44:31 +00:00
auth
This commit is contained in:
65
app/Http/Controllers/ChatLinkController.php
Normal file
65
app/Http/Controllers/ChatLinkController.php
Normal 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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user