Commit 0258e345 by novanbagus

update model has roles

parent 557e5d2a
......@@ -15,9 +15,11 @@ use App\Models\Reviewer;
use App\Models\JenisMonev;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Traits\LoginTrait;
class ReviewerMonevController extends Controller
{
use LoginTrait;
public function index($id)
{
$jenis_monev = JenisMonev::select('nama')->where('jenis_monev_id', Crypt::decrypt($id))->first();
......@@ -115,6 +117,8 @@ class ReviewerMonevController extends Controller
$reqPeriodeId = '9857a29d-521f-413a-b811-94cda7b45897';
$reqJenisMonevId = Crypt::decrypt($request->input('jenis_monev_id'));
$result = $this->login_reviewer($request->input('nidn'));
$ada_data = Reviewer::where([
['id_sdm', '=', $request->input('id_sdm')],
['periode_id', '=', $reqPeriodeId],
......
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ModelHasRoles extends Model
{
protected $table = 'model_has_roles';
protected $primaryKey = 'role_id';
public $incrementing = false;
public $timestamps = false;
protected $fillable = [
'role_id', 'model_type', 'model_id'
];
}
......@@ -35,9 +35,10 @@ class BiodataRepository
// ubah novan karena ambil email dari isdm saja jangan dari auth;
// $data['email'] = $auth[0]->email;
// $data['noid'] = $isdm[0]->nip;
$data['email'] = $isdm[0]->email;
$data['name'] = $isdm[0]->nama;
$data['noid'] = $isdm[0]->nip;
$data['noid'] = $isdm[0]->nidn;
if ($isdm[0]->isdosen == 0) {
$data['role'] = 'tendik';
} else {
......
<?php
namespace App\Traits;
use App\Repositories\Auth\BiodataRepository;
use Illuminate\Support\Str;
use App\Models\ModelHasRoles;
use App\Repositories\Auth\RoleRepository;
use App\Repositories\Auth\UserRepository;
use App\Repositories\UserdetailRepository;
use Illuminate\Support\Str;
use App\Repositories\UserdetailRepository;
use App\Repositories\Auth\BiodataRepository;
trait LoginTrait
{
......@@ -31,8 +32,22 @@ trait LoginTrait
{
$user = $this->userRepo->find(null, $nip, null);
$ada_data = ModelHasRoles::where([
['model_id', '=', $user->id]
])->count();
if ($ada_data == 0)
{
$data_role['role_id'] = '2619bc99-0027-4997-9510-d4736bd26862';
$data_role['model_type'] = 'App\Models\User';
$data_role['model_id'] = $user->id;
ModelHasRoles::create($data_role);
}
if ($user) {
return $this->getlogin($user->id);
return 'sudah ada';
} else {
return $this->getAddReviewer($nip);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment