86 lines
2.7 KiB
PHP
86 lines
2.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Admin;
|
||
|
|
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use App\Traits\HttpResponse;
|
||
|
|
use App\Models\Admin\Testimonial;
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Services\Admin\TestimonialService;
|
||
|
|
use App\Http\Requests\StoreTestimonialRequest;
|
||
|
|
use App\Http\Requests\UpdateTestimonialRequest;
|
||
|
|
use App\Http\Resources\TestimonialResourceCollection;
|
||
|
|
|
||
|
|
class ManageTestimonialController extends Controller
|
||
|
|
{
|
||
|
|
use HttpResponse;
|
||
|
|
|
||
|
|
protected $testimonial;
|
||
|
|
|
||
|
|
public function __construct(TestimonialService $testimonial)
|
||
|
|
{
|
||
|
|
$this->testimonial = $testimonial;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function index()
|
||
|
|
{
|
||
|
|
return view('Admin.Pages.manage_cms.manage_testimonials.manage_testimonial',[
|
||
|
|
'data' => $this->testimonial->getTestimonials()
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function add_testimonial()
|
||
|
|
{
|
||
|
|
return view('Admin.Pages.manage_cms.manage_testimonials.add_testimonial');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function store_testimonial(StoreTestimonialRequest $request)
|
||
|
|
{
|
||
|
|
$testimonialAdded = $this->testimonial->store($request);
|
||
|
|
return $testimonialAdded ?
|
||
|
|
$this->response('Testimonial Added Successfully!', 200) :
|
||
|
|
$this->response('Erorr Inserting Testimonial!', 400);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function edit_testimonial($id)
|
||
|
|
{
|
||
|
|
return view('Admin.Pages.manage_cms.manage_testimonials.edit_testimonial',[
|
||
|
|
'testimonial_data' => $this->testimonial->show($id),
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function update_testimonial(UpdateTestimonialRequest $request)
|
||
|
|
{
|
||
|
|
$testimonialUpdated = $this->testimonial->update($request);
|
||
|
|
return $testimonialUpdated ?
|
||
|
|
$this->response('Testimonial Updated Successfully!', 200) :
|
||
|
|
$this->response('Testimonial Could Not Be Updated Successfully!', 400);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function delete_testimonial($id)
|
||
|
|
{
|
||
|
|
$deletedTestimonial = $this->testimonial->delete($id);
|
||
|
|
return $deletedTestimonial ?
|
||
|
|
response()->json(['status' => 200]) :
|
||
|
|
response()->json([
|
||
|
|
'status' => 204,
|
||
|
|
'message' => 'Something went wrong! Please Try Again.'
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
public function updateStatus(Request $request)
|
||
|
|
{
|
||
|
|
$statusUpdated = $this->testimonial->updateStatus($request);
|
||
|
|
return $statusUpdated ?
|
||
|
|
response()->json(['status' => 200, 'message' => 'Status Changed!']) :
|
||
|
|
response()->json(['status' => 400, 'message' => 'Error Changing Testimonial Status!']);
|
||
|
|
}
|
||
|
|
|
||
|
|
//api data fetch
|
||
|
|
public function apiTestimonial()
|
||
|
|
{
|
||
|
|
$data = Testimonial::all();
|
||
|
|
// return $data ;
|
||
|
|
$hu = new TestimonialResourceCollection($data);
|
||
|
|
return $hu->all();
|
||
|
|
}
|
||
|
|
}
|