77 lines
2.7 KiB
PHP
77 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Models\Testimonial;
|
|
use App\Models\TestimonialImages;
|
|
use Validator;
|
|
|
|
|
|
class TestimonialController extends Controller
|
|
{
|
|
public function get_Testimonial() {
|
|
$token = readHeaderToken();
|
|
if ($token) {
|
|
$testdata = Testimonial::with('testimonial_data')->inRandomOrder()->get();
|
|
// echo "<pre>";
|
|
// print_r($testdata);
|
|
// exit;
|
|
// foreach ($testdata as $val) {
|
|
|
|
// foreach($val['testimonial_data'] as $k =>$image){
|
|
// $testdata[$k]['image'] = ListingImageUrl('testimonial', $val['image']);
|
|
// }
|
|
|
|
// }
|
|
return response([
|
|
'user' => $testdata,
|
|
], 200);
|
|
}
|
|
}
|
|
|
|
public function store_testimonial(Request $req) {
|
|
|
|
$validator = Validator::make($req->all(), [
|
|
'user_name' => 'required',
|
|
'image' => 'required|image|mimes:jpg,png,jpeg,gif',
|
|
'title' => 'required',
|
|
'description' => 'required',
|
|
'rating' => 'required',
|
|
]);
|
|
if ($validator->fails()) {
|
|
return response()->json([
|
|
'error' => $validator->errors()], 401);
|
|
}
|
|
$testimonials = new Testimonial();
|
|
$testimonials->user_name = $req->input('user_name');
|
|
// $testimonials->image = $req->input('image');
|
|
$testimonials->title = $req->input('title');
|
|
$testimonials->description = $req->input('description');
|
|
$testimonials->rating = $req->input('rating');
|
|
if ($req->hasFile('image')) {
|
|
$file = $req->file('image');
|
|
$ext = $file->extension();
|
|
$file_name = time() . '.' . $ext;
|
|
$path = public_path() . '/uploads/testimonial/';
|
|
$file->move($path, $file_name);
|
|
$testimonials->image = url('/public/uploads/testimonial/' . $file_name);
|
|
}
|
|
$storetestimonial = $testimonials->save();
|
|
if ($storetestimonial == 1) {
|
|
return response()->json([
|
|
'success' => true,
|
|
'status' => 200,
|
|
'message' => 'Testimonial Added Successfully',
|
|
]);
|
|
} else {
|
|
return response()->json([
|
|
'success' => true,
|
|
'error' => 400,
|
|
'message' => 'Please Try Again',
|
|
]);
|
|
}
|
|
}
|
|
}
|