refactor

parent 1488ee49
......@@ -19,7 +19,13 @@ class PublikasiArtikelController extends Controller
public function index(Request $request)
{
$data['tingkat'] = $request->tingkat;
$data['rs'] = PublikasiArtikel::query()->with('biodata')->where('jenis', strtoupper(substr($request->tingkat, 0, 1)))->orderBy('updated_at', 'desc')->get();
$data['rs'] = PublikasiArtikel::query()
->with('biodata')
->where('jenis', strtoupper(substr($request->tingkat, 0, 1)))
->orderBy('updated_at', 'desc')
->get();
return view('user.publikasiartikel.index', $data);
}
......@@ -32,6 +38,7 @@ class PublikasiArtikelController extends Controller
{
$data['tingkat'] = $request->tingkat;
$data['edit'] = false;
return view('user.publikasiartikel.create', $data);
}
......@@ -44,18 +51,21 @@ class PublikasiArtikelController extends Controller
public function store(Request $request)
{
$data = $request->except('_token');
Validator::make($data, PublikasiArtikel::RULES, PublikasiArtikel::ERROR_MESSAGES)->validate();
$jenis = $data['jenis'];
$data['userid_created'] = Auth::user()->id;
$data['userid_updated'] = Auth::user()->id;
$data['jenis'] = strtoupper(substr($data['jenis'], 0, 1));
try{
PublikasiArtikel::query()->create($data);
return redirect()->intended('publikasiartikel?tingkat='.$jenis);
}
catch(Exception $ex){
dd($ex);
return redirect()->back()->withInput();
}
}
......@@ -82,6 +92,7 @@ class PublikasiArtikelController extends Controller
$data['data'] = PublikasiArtikel::query()->find(decrypt($id));
$data['tingkat'] = $data['data']->jenis == 'R' ? 'Regional' : ($data['data']->jenis == 'N' ? 'Nasional' : ($data['data']->jenis == 'I' ? 'Internasional' : ''));
$data['edit'] = true;
return view('user.publikasiartikel.create', $data);
}
......@@ -95,7 +106,9 @@ class PublikasiArtikelController extends Controller
public function update(Request $request, $id)
{
$data = $request->except('_token');
Validator::make($data, PublikasiArtikel::RULES, PublikasiArtikel::ERROR_MESSAGES)->validate();
$jenis = $data['jenis'];
$data['userid_created'] = Auth::user()->id;
$data['userid_updated'] = Auth::user()->id;
......@@ -103,6 +116,7 @@ class PublikasiArtikelController extends Controller
try{
PublikasiArtikel::query()->find(decrypt($id))->update($data);
return redirect()->intended('publikasiartikel?tingkat='.$jenis);
}
catch(Exception $ex){
......@@ -120,6 +134,7 @@ class PublikasiArtikelController extends Controller
{
try{
PublikasiArtikel::query()->find(decrypt($id))->delete();
return redirect()->back();
}
catch(Exception $ex){
......
......@@ -141,7 +141,11 @@
url:"{{ route('adminremove-role') }}",
type:"POST",
dataType:"html",
data:{user_id:user_id, role_id:role_id, _token:token},
data:{
user_id:user_id,
role_id:role_id,
_token:token
},
success: function(result){
$(element).parent().parent().remove();
}
......@@ -154,7 +158,11 @@
url:"{{ route('adminadd-role') }}",
type:"POST",
dataType:"html",
data:{user_id:user_id, role_id:role_id, _token:token},
data:{
user_id:user_id,
role_id:role_id,
_token:token
},
success: function(result){
$('#'+user_token).append(result);
}
......
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