ardhi
2 years ago
3 changed files with 85 additions and 0 deletions
@ -0,0 +1,57 @@
|
||||
<?php |
||||
|
||||
namespace App\Http\Controllers; |
||||
|
||||
use Illuminate\Http\Request; |
||||
use App\Models\ProjectComment; |
||||
|
||||
class ProjectCommentController extends Controller |
||||
{ |
||||
public function add(Request $request) |
||||
{ |
||||
$data = $request->all(); |
||||
|
||||
$data['created_by'] = $this->currentName; |
||||
|
||||
$result = ProjectComment::create($data); |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'add comment successfully!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'add comment failed!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function update(Request $request, $id) |
||||
{ |
||||
if(!$id || (int) $id < 0 || $id==""){ |
||||
return response()->json(['status'=>'failed','message'=>'id is required!','code'=>400], 400); |
||||
} |
||||
|
||||
$data = ProjectComment::find($id); |
||||
|
||||
if($data){ |
||||
$result = $data->update($request->all()); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data project not found!','code'=>400], 400); |
||||
die(); |
||||
} |
||||
|
||||
if($result){ |
||||
return response()->json(['status'=>'success','message'=>'data project successfully updated!','code'=>200], 200); |
||||
}else{ |
||||
return response()->json(['status'=>'failed','message'=>'data project failed updated!','code'=>400], 400); |
||||
} |
||||
} |
||||
|
||||
public function search(Request $request) |
||||
{ |
||||
$payload = $request->all(); |
||||
$dataBuilder = $this->setUpPayload($payload, 'm_project_comment'); |
||||
$builder = $dataBuilder['builder']; |
||||
$countBuilder = $dataBuilder['count']; |
||||
$dataGet = $builder->get(); |
||||
$totalRecord = $countBuilder->count(); |
||||
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); |
||||
} |
||||
} |
@ -0,0 +1,24 @@
|
||||
<?php |
||||
|
||||
namespace App\Models; |
||||
|
||||
use Illuminate\Database\Eloquent\Model; |
||||
|
||||
class ProjectComment extends Model |
||||
{ |
||||
protected $table = 'm_project_comment'; |
||||
|
||||
const CREATED_AT = 'created_at'; |
||||
const UPDATED_AT = 'updated_at'; |
||||
|
||||
protected $fillable = [ |
||||
'sender_id', |
||||
'project_id', |
||||
'gantt_id', |
||||
'comment', |
||||
'created_at', |
||||
'created_by', |
||||
'updated_at', |
||||
'updated_by' |
||||
]; |
||||
} |
Loading…
Reference in new issue