This repository has been archived on 2021-01-24. You can view files and clone it, but cannot push or open issues or pull requests.
laravel-elearning/app/Group.php

55 lines
932 B
PHP

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;
use App\Test;
class Group extends Model
{
protected $fillable = ["name"];
public function users()
{
return $this->hasMany(User::class);
}
public function tests()
{
return $this->hasMany(Test::class);
}
public function getGroupTests()
{
return $this->tests;
}
public function getGroupUsers()
{
return $this->users;
}
public function addGroup($request)
{
$this->name = $request["name"];
$this->save();
return true;
}
public function updateGroup($request)
{
$this->update($request);
return true;
}
public function deleteGroup()
{
if (Auth::user()->isAdministrator()) {
$this->delete();
return true;
}
return false;
}
}