save to codehub
This commit is contained in:
81
app/Http/Controllers/API/ShareYourThoughtsController.php
Normal file
81
app/Http/Controllers/API/ShareYourThoughtsController.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\ShareYourThought;
|
||||
use App\Models\User;
|
||||
use App\Models\UserThought;
|
||||
use Auth;
|
||||
|
||||
class ShareYourThoughtsController extends Controller {
|
||||
|
||||
public function add_thoughts(Request $request) {
|
||||
try {
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
$user_id = $token['sub'];
|
||||
$user = auth()->user();
|
||||
// print_r($user);exit;
|
||||
|
||||
// check validation
|
||||
// $validator = Validator::make($request->all(), [
|
||||
// 'rating' => 'required|integer|min:1|max:5',
|
||||
// ]);
|
||||
// if ($validator->fails()) {
|
||||
// return response()->json([
|
||||
// 'error' => $validator->errors()], 401);
|
||||
// }
|
||||
|
||||
$thoughts = new ShareYourThought;
|
||||
$thoughts->rating = $request->input('rating');
|
||||
$thoughts->user_id = $user_id;
|
||||
$thoughts->save();
|
||||
$msg = "Thank You Review Added Successfully.";
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => $msg,
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("Update Complete/Update Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
public function get_thought_id() {
|
||||
try {
|
||||
// print_r(User::first()->user);exit;
|
||||
$token = readHeaderToken();
|
||||
if ($token) {
|
||||
// $user_id = $token['sub'];
|
||||
$data = UserThought::where('is_active', '1')->inRandomOrder()->get();
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Data fetched successfully.',
|
||||
'result' => $data
|
||||
]);
|
||||
} else {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Authentication failed.',
|
||||
]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Log::error("User data listing Failed : " . $e->getMessage());
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Something Went wrong.',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user