Yusuf
2 years ago
3 changed files with 105 additions and 1 deletions
@ -0,0 +1,84 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Http\Controllers; |
||||||
|
|
||||||
|
use Illuminate\Http\Request; |
||||||
|
use App\Models\ProjectPhase; |
||||||
|
|
||||||
|
class ProjectPhaseController extends Controller |
||||||
|
{ |
||||||
|
public function add(Request $request) |
||||||
|
{ |
||||||
|
$this->validate($request, [ |
||||||
|
'name' => 'required' |
||||||
|
]); |
||||||
|
|
||||||
|
$data = $request->all(); |
||||||
|
|
||||||
|
$data['created_by'] = $this->currentName; |
||||||
|
|
||||||
|
if(!ProjectPhase::create($data)) |
||||||
|
return response()->json(['status'=>'failed','message'=>'Failed to add data','code'=> 500], 500); |
||||||
|
|
||||||
|
return response()->json(['status'=>'success','message'=>'data added!','code'=>200], 200); |
||||||
|
} |
||||||
|
|
||||||
|
public function edit($id){ |
||||||
|
if(!$id || (int) $id < 0 || $id=="") |
||||||
|
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
|
|
||||||
|
if(!$result = ProjectPhase::find($id)) |
||||||
|
return response()->json(['status'=>'failed','message'=>'Failed to get data!','code'=> 404], 404); |
||||||
|
|
||||||
|
return response()->json(['status'=>'success','code'=>200,'data'=>$result], 200); |
||||||
|
} |
||||||
|
|
||||||
|
public function update(Request $request, $id) |
||||||
|
{ |
||||||
|
if(!$id || (int) $id < 0 || $id=="") |
||||||
|
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||||
|
|
||||||
|
if(!$data = ProjectPhase::find($id)) |
||||||
|
return response()->json(['status'=>'failed','message'=>'data role not found!','code'=>400], 400); |
||||||
|
|
||||||
|
if(!$data->update($request->all())) |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project type failed updated!','code'=>400], 400); |
||||||
|
|
||||||
|
return response()->json(['status'=>'success','message'=>'Data berhasil disimpan!','code'=>200], 200); |
||||||
|
} |
||||||
|
|
||||||
|
public function delete($id) |
||||||
|
{ |
||||||
|
|
||||||
|
if(!$data = ProjectPhase::find($id)) |
||||||
|
return response()->json(['status'=>'failed','message'=>'data project phase not found!','code'=>400], 400); |
||||||
|
|
||||||
|
if(!$data->delete()) |
||||||
|
return response()->json(['status'=>'failed','message'=>'Data gagal dihapus!','code'=> 500], 500); |
||||||
|
|
||||||
|
return response()->json(['status'=>'success','message'=>'Data berhasil dihapus!','code'=>200], 200); |
||||||
|
} |
||||||
|
|
||||||
|
public function search(Request $request) |
||||||
|
{ |
||||||
|
$payload = $request->all(); |
||||||
|
$dataBuilder = $this->setUpPayload($payload, 'm_proyek_phase'); |
||||||
|
$builder = $dataBuilder['builder']; |
||||||
|
$countBuilder = $dataBuilder['count']; |
||||||
|
$dataGet = $builder->get(); |
||||||
|
$totalRecord = $countBuilder->count(); |
||||||
|
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||||
|
} |
||||||
|
|
||||||
|
public function list() |
||||||
|
{ |
||||||
|
$data = ProjectPhase::all(); |
||||||
|
$countData = $data->count(); |
||||||
|
|
||||||
|
if(!$data) |
||||||
|
return response()->json(['status'=>'failed','message'=>'failed get list project type, please try again later!','code'=>400], 400); |
||||||
|
|
||||||
|
return response()->json(['status'=>'success','code'=>200,'data'=>$data, 'totalRecord'=>$countData], 200); |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace App\Models; |
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model; |
||||||
|
|
||||||
|
class ProjectPhase extends Model |
||||||
|
{ |
||||||
|
protected $table = 'm_proyek_phase'; |
||||||
|
|
||||||
|
const CREATED_AT = 'created_at'; |
||||||
|
const UPDATED_AT = 'updated_at'; |
||||||
|
|
||||||
|
protected $fillable = [ |
||||||
|
'name', 'color', 'order', 'created_at', 'created_by', 'updated_at', 'updated_by' |
||||||
|
]; |
||||||
|
} |
Loading…
Reference in new issue