55 lines
932 B
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;
|
|
}
|
|
}
|