kevin00830 / promoter-auto

0 stars 0 forks source link

Export Json #1

Open kevin00830 opened 10 months ago

kevin00830 commented 10 months ago

This is auto flow chat which show whatsapp auto reply. I have to export into Json and if data is not exist, it should be added in DB.

public function exportJson(Request $request) { $group_id =auth()->user()->id; // Get authenticated user group_id $fileName = $request['exportJsonName'];

    File::put(public_path("uploads/{$group_id}/{$request['exportJsonName']}.json"), $request['data']);

    return response()->json(['message' => 'Data exported successfully']);
}
pioneer830 commented 10 months ago

Hi Kevin, You can use firstOrCreat function for it like this.

$record = FlowSavedPath::firstOrCreate( ['flow_name' => $fileName], [ 'path' => "https://auto.notifire-api.com/uploads/{$group_id}/{$fileName}.json", 'group_id' => $group_id, ] );

kevin00830 commented 10 months ago

Great! Thanks for your help!