English 中文(简体)
API 不返回 Laravel 8 中的最新数据
原标题:API not returning latest data in laravel 8
I am using laravel 8 for my flutter app. In this, Api s are not returning latest data after edit/update. Even on another api of getting that data. To add data I am following code: $input = $request->all(); $validation = Validator::make($input, [ // image => required|image|max:2048 , user_id => required , team_name => required , description => required , status => required , members => required ]); if ($validation->fails()) { return response()->json([ success => false, data => , message => implode( , , $validation->errors()->all()), ]); exit(); } if (isset($request[ team_name ]) && !empty($request[ members ]) && !empty($request[ description ]) && !empty($request[ status ])) { $team_url = strtolower(str_replace( , _ , $request[ team_name ])); $check_record = TeamModel::where( team_name , $request[ team_name ])->count(); if ($check_record > 0) { /* means already exists */ return response()->json([ success => false, message => Team name already exists , data => [] ], 200); die(); } } // $name = $request->file( image )->getClientOriginalName(); $teamModel = new TeamModel(); // uploading image starts if ($request->hasFile( image )) { $fileName = teams- . time() . . . $request->file( image )->getClientOriginalExtension(); $path = $request->file( image )->move( images , $fileName); $teamModel->image = images/ . $fileName; } // uploading image ends // $teamModel->image = images/ ; $teamModel->team_name = $input[ team_name ]; $teamModel->team_url = Str::slug($request[ team_name ], _ ); $teamModel->description = $input[ description ]; $teamModel->created_by = $input[ user_id ]; $teamModel->status = $input[ status ]; if ($teamModel->save()) { $members = array($input[ user_id ]); // $request[ members ][ owner ] = 1; if (!empty($request[ members ])) { $members = array_merge($members, $input[ members ]); } //Add Member if (!empty($members)) { foreach ($members as $mem) { $isSelf = $input[ user_id ] == $mem ? 1 : 0; // $owner = auth()->user()->id == $mem ? 1 : 0; $arrData = [ team_id => $teamModel->id, user_id => $mem, request_by => $input[ user_id ], is_accepted => $isSelf, seen_status => $isSelf, owner => $isSelf ]; DB::table( team_members )->insert($arrData); } } // $teamModel->image = $base_url . $teamModel->image; if ($teamModel->image != null || !empty($teamModel->image)) $teamModel->image = $base_url . $teamModel->image; else $teamModel->image = ; return response()->json([ success => true, message => Team created successfully , data => $teamModel ], 200); } else { return response()->json([ success => true, message => Unable to create team! Please try again. , data => $teamModel ], 200); } To update code: $id = $input[ id ]; if (!isset($input[ members ])) { return response()->json([ success => false, message => Please select team members first! , data => [] ], 200); } $input = $request->all(); $validation = Validator::make($input, [ // image => required|image|max:2048 , id => required , user_id => required , team_name => required , description => required , status => required , members => required ]); if ($validation->fails()) { return response()->json([ success => false, data => , message => implode( , , $validation->errors()->all()), ]); exit(); } if (isset($request[ team_name ]) && !empty($request[ members ]) && !empty($request[ description ]) && !empty($request[ status ])) { $team_url = strtolower(str_replace( , _ , $request[ team_name ])); $check_record = TeamModel::where( team_name , $request[ team_name ])->count(); if ($check_record > 1) { /* means already exists */ return response()->json([ success => false, message => Team name already exists , data => [] ], 200); die(); } } $teamModel = TeamModel::find($id); $teamModel->team_name = $request[ team_name ]; $teamModel->description = $request[ description ]; $teamModel->team_url = Str::slug($request[ team_name ], _ ); // uploading image starts if ($request->hasFile( image )) { if (file_exists($teamModel->image)) { unlink($teamModel->image); } $fileName = teams- . time() . . . $request->file( image )->getClientOriginalExtension(); $path = $request->file( image )->move( images , $fileName); $teamModel->image = images/ . $fileName; } // uploading image ends $teamModel->status = $request[ status ]; if ($teamModel->save()) { //Add Member $members = $input[ members ]; if (!empty($members)) { foreach ($members as $mem) { $isSelf = $input[ user_id ] == $mem ? 1 : 0; $arrData = [ team_id => $teamModel->id, user_id => $mem, request_by => $input[ user_id ], is_accepted => $isSelf, seen_status => $isSelf ]; if (!team_member($teamModel->id, $mem)) DB::table( team_members )->insert($arrData); } } if ($teamModel->image != null || !empty($teamModel->image)) $teamModel->image = $base_url . $teamModel->image; else $teamModel->image = ; return response()->json([ success => true, message => Team updated successfully , data => $teamModel ], 200); } else { return response()->json([ success => false, message => Unable to update team! please try again. , data => [] ], 200); } I am using following way to return response: return response()->json([ success => true, message => Success message , data => $data ], 200); I have explored many articles and tried clearing cache by commands but none of them is worked. I am not able to understand why it s getting too much cache even on json.
问题回答
I solved this problem. It was the cache issue from the server. To figure out this issue, I tested my code on another server.




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签