Я пытаюсь обновить модальную форму, но по какой-то причине после нажатия кнопки обновления ничего не изменилось. Я пытался dd request->role_name
, но похоже, что он не уловил значение, которое я ввел с помощью формы выбора. Удаление и создание работает отлично. Я предоставлю контроллер создания и удаления, если вы все хотите знать.
Таблица, которую я использовал:
bas_role
id
name
bas__app
id
app_name
bas_role_app
id
role_id(f_key)
app_name(f_key)
Маршрут:
Route::get('/roleapp', 'RoleAppController@display');
Route::post('/roleapp/update/{roleapp}', 'RoleAppController@update');
Route::get('ajaxdata/getapp','RoleAppController@getroleapp')->name('ajaxdata.getroleapp');
Контроллер:
public function display(Request $request)
{
$routes = preg_match('/([a-z]*)@([a-z]*)/i', Route::currentRouteAction(), $matches);
$routes = $matches[0];
$action = $matches[2];
if (Auth::check()) {
$id = Auth::id();
DB::beginTransaction();
try {
$profile_data = User::find($id);
ActivityLog::create([
'inserted_date' => Carbon::now()->TimeZone('asia/jakarta'),
'username' => $profile_data->username,
'application' =>$routes,
'creator' => "System",
'ip_user' => $request->ip(),
'action' => $action,
'description' => $profile_data->username. " is looking at roleApp",
'user_agent' => $request->server('HTTP_USER_AGENT')
]);
// $pagination = TRUE;
$app =DB::table('bas_role_app')
->join('bas_role_app','bas_app.app_name','=','bas_role_app.app_name')
->join('bas_role','bas_role_app.role_id','=','bas_role.id')
->from('bas_app')
->distinct()
// ->where('role_user.role_id', 4)
->select('bas_role_app.app_name','bas_role.name','bas_role_app.id','bas_role_app.role_id')
// ->from('bas_app')
// // ->where('role_user.role_id', 4)
->groupBy('bas_app.app_name','bas_role.name','bas_role_app.id')
->Orderby('bas_role_app.id')
->get();
// dd($app);
$bas_role = Role::distinct()->select('id','name')->get();
$bas_app =App::distinct()->select('id','app_name')->get();
DB::commit();
} catch (\Exception $ex) {
DB::rollback();
return response()->json(['error' => $ex->getMessage()], 500);
}
return view('/roleapp', ['app' => $app, 'bas_app'=> $bas_app, 'bas_role' => $bas_role]);
// return view('/roleapp', ['app' => $app, 'bas_app' => $bas_app]);
}else {
return view("login");
}
}
public function getroleapp(){
$app = DB::table('bas_role_app')
->join('bas_role_app','bas_app.app_name','=','bas_role_app.app_name')
->join('bas_role','bas_role_app.role_id','=','bas_role.id')
->from('bas_app')
->select('bas_role_app.app_name','bas_role.name','bas_role_app.id')
->get();
return Datatables::of($app)->make(true);
}
public function update(Request $request, $id)
{
$routes = preg_match('/([a-z]*)@([a-z]*)/i', Route::currentRouteAction(), $matches);
$routes = $matches[0];
$action = $matches[2];
if (Auth::check()) {
$idUser = Auth::id();
DB::beginTransaction();
DB::table('bas_role_app')
->where('id', $id)
->update([
'role_id' => $request->role_name ,
'app_name' => $request->app_name,
]);
// dd($request->role_name);
return redirect('/roleapp')->with('message', 'Role App data update success!');
} else {
return view("login");
}
RoleApp.blade. php
@extends('layouts.master')
@section('title','Role App')
@section('content')
@if($errors->any())
<div class="alert alert-danger alert-dismissible fade show" role="alert">
{{ implode(', ', $errors->all(':message')) }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
@endif
@if(session()->has('message'))
<div class="alert alert-success">
{{ session()->get('message') }}
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
@endif
<div class="container mt-5">
<div class="row">
<div class="col-12">
<!-- Modal -->
<div class="float-left">
<div class="form-group mx-sm-3 mb-2">
<form class="form-inline">
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#exampleModalCenter">
<i class="ni ni-fat-add"></i>
</button>
</div>
</form>
</div>
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Add New Role</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
//Create new role app
<div class="modal-body">
<form action="roleapp/create" method="POST">
{{ csrf_field() }}
<div class="form-group">
<label class="control-label">Role Name:</label>
<select class="form-control select2bs4" data-live-search="true" data-placeholder="Choose Role Name" tabindex="1" name="role_name" style="width: 100%;" required>
<option value="">Choose Role Name.......</option>
@foreach ($bas_role as $category)
<option value="{{ $category->id }}">{{ $category->name }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label class="control-label">App Name:</label>
<select class="form-control select2bs4" data-placeholder="Choose App Name" tabindex="1" name="app_name" style="width: 100%;" required>
<option value="">Choose App Name.......</option>
@foreach ($bas_app as $category)
<option value="{{ $category->app_name }}">{{ $category->app_name }}</option>
@endforeach
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><i class="ni ni-fat-remove"></i></button>
<button type="submit" class="btn btn-primary"><i class="ni ni-check-bold"></i></button>
</div>
</form>
</div>
</div>
</div>
//show role app table
<table class="table table-striped" id="app">
<thead>
<tr>
<th scope="col">id</th>
<th scope="col">Role Name</th>
<th scope="col">App Name</th>
<th scope="col">Action</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody id="dynamic-row">
</tbody>
</table>
@foreach ($app as $p)
<div class="modal fade" id="modal_edit_{{$p->id}}" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Edit RoleApp</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
//Update a role app
<div class="modal-body">
<form id="app_form_{{$p->id}}" action="{{ url('roleapp/update', [$p->id]) }}" method="POST">
<input type="hidden" name="_token" value="{{ csrf_token() }}" form="app_form_{{$p->id}}" />
<div class="form-group">
<label class="control-label">Role Name:</label>
<select class="form-control select2bs4" data-placeholder="Choose Role Name" tabindex="1" name="role_name" style="width: 100%;" required>
<option value="{{$p->id}}">{{$p->name}}</option>
@foreach ($bas_role as $category)
<option value="{{ $p->role_id }}">{{ $category->name }}</option>
@endforeach
</select>
</div>
<div class="form-group">
<label class="control-label">App Name:</label>
<select class="form-control select2bs4" data-placeholder="Choose App Name" tabindex="1" name="app_name" style="width: 100%;" required>
<option value="{{$p->app_name}}">{{$p->app_name}}</option>
@foreach ($bas_app as $category)
<option value="{{ $p->app_name }}">{{ $category->app_name }}</option>
@endforeach
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal"><i class="ni ni-fat-remove"></i></button>
<button type="submit" form="app_form_{{$p->id}}" class="btn btn-primary"><i class="ni ni-check-bold"></i></button>
</div>
</form>
</div>
</div>
</div>
@endforeach
//delete a roleapp
@foreach ($app as $p)
<div class="modal fade" id="modal_hapus_{{$p->id}}" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Data akan dihapus</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Data yang dihapus tidak dapat dikembalikan!
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success" data-dismiss="modal"><i class="ni ni-fat-remove"></i></button>
<a href="{{ url('roleapp/delete', [$p->id]) }}" class="btn btn-danger"><i class="ni ni-check-bold"></i></a>
</div>
</div>
</div>
</div>
@endforeach
</div>
</div>
</div>
<link rel="stylesheet" href="{{ asset('css/breadcrumb.css') }}">
<script>
//load search, individual or not
var row = 0;
$(document).ready(function() {
$('#app thead tr').clone(true).appendTo( '#app thead' );
$('#app thead tr:eq(1) th').each( function (i) {
if (row < 3) {
var title = $(this).text();
$(this).html('<input type="text" placeholder="Search ' + title + '" />');
} else {
$(this).html('');
}
row++;
$( 'input', this ).on( 'keyup change', function () {
if ( table.column(i).search() !== this.value ) {
table
.column(i)
.search( this.value )
.draw();
}
} );
} );
//load datatable processing, using serverside yajra, with pagination option, also action button as well
var table = $('#app').DataTable({
"processing": true,
"serverSide": true,
"ajax": "{{ route('ajaxdata.getroleapp') }}",
"lengthMenu" : [[20, 50, 100, 500, 1000, -1],[20, 50, 100, 500, 1000, "All"]],
"columns":[
{ "data": "id" },
{ "data": "name" },
{ "data": "app_name" },
{
sortable: false,
"render": function ( data, type, full, meta ) {
return '<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal_edit_'+full.id+'"><i class="ni ni-single-02"></i></button>';
}
},
{
sortable: false,
"render": function ( data, type, full, meta ) {
return '<button type="button" class="btn btn-danger" data-toggle="modal" data-target="#modal_hapus_'+full.id+'"><i class="ni ni-fat-delete"></i></button>';
}
},
],
});
$('.selectpicker').selectpicker({
style: 'btn-default',
// size: false
});
} );
</script>
{{--
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.13.1/js/bootstrap-select.min.js"></script> --}}
@endsection