60 lines
2.4 KiB
PHP
60 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Admin\country;
|
|
use App\Models\Admin\Testimonial;
|
|
|
|
class ManageTestimonialController extends Controller {
|
|
|
|
public function index() {
|
|
$countries = country::all()->toArray();
|
|
$testimonial = Testimonial::with('country')->get()->toArray();
|
|
// dd($testimonial);
|
|
return view('Admin.Pages.manage_cms.manage_testimonials.manage_testimonial')->with(['country' => $countries, 'testimonial' => $testimonial]);
|
|
}
|
|
|
|
public function insert(Request $request) {
|
|
|
|
// for image upload end
|
|
$add_testimonial = new Testimonial;
|
|
$add_testimonial->name = $request->input('name');
|
|
if ($request->hasFile('image_path') && $request->file('image_path')->isValid()) {
|
|
$uploadedFile = $request->file('image_path');
|
|
$filename = date('YmdHi') . '_' . str_replace(' ', '', $uploadedFile->getClientOriginalName());
|
|
$uploadedFile->move(public_path('assets/uploads/testimonial/'), $filename);
|
|
$images = 'assets/uploads/testimonial/' . $filename;
|
|
$add_testimonial->image = $images;
|
|
}
|
|
|
|
$add_testimonial->discription = $request->input('discription');
|
|
$add_testimonial->country_xid = $request->input('country');
|
|
$add_testimonial->save();
|
|
|
|
return response()->json(['success' => true, 'status' => 200]);
|
|
}
|
|
|
|
public function delete_test($id) {
|
|
$testimonial = Testimonial::find($id)->delete();
|
|
}
|
|
|
|
public function update(Request $request) {
|
|
$add_testimonial = Testimonial::find($request->test_id);
|
|
$add_testimonial->name = $request->input('edit_name');
|
|
if ($request->hasFile('image_path')) {
|
|
$uploadedFile = $request->image_path;
|
|
$filename = date('YmdHi') . '_' . str_replace(' ', '', $uploadedFile->getClientOriginalName());
|
|
$uploadedFile->move(public_path('/assets/uploads/testimonial'), $filename);
|
|
$images = 'assets/uploads/testimonial/' . $filename;
|
|
$add_testimonial->image = $images;
|
|
}
|
|
$add_testimonial->discription = $request->input('edit_disc');
|
|
$add_testimonial->country_xid = $request->input('country');
|
|
$add_testimonial->save();
|
|
return response()->json(['success' => true, 'status' => 200]);
|
|
}
|
|
|
|
}
|