Browse Source

🚧 Corrige l'enregistrement des mises à jour

master
Shikiryu 2 years ago
parent
commit
d4156ce3a3
1 changed files with 11 additions and 3 deletions
  1. +11
    -3
      app/Http/Controllers/HomeController.php

+ 11
- 3
app/Http/Controllers/HomeController.php View File

@@ -58,14 +58,22 @@ class HomeController extends Controller
}
if ($request->isMethod('post')) {
// TODO filter
$updated_deal = \Shikiryu\LBCReposter\Deal::fromJSON($folder_path . '/data.json');

$json_data = \json_decode(file_get_contents($folder_path . '/data.json'), true);
$json_data['subject'] = $request->subject;
$json_data['body'] = $request->body;
$json_data['category'] = $request->category;
$json_data['price'] = $request->price;
$result = file_put_contents($folder_path . '/data.json', \json_encode($json_data, JSON_UNESCAPED_UNICODE)) !== false;
// FIXME when API is updated
/*$updated_deal = \Shikiryu\LBCReposter\Deal::fromJSON($folder_path . '/data.json');
$result =
$updated_deal
->setSubject($request->subject)
->setBody($request->body)
->setCategory($request->category)
->setPrice($request->price)
->save(sprintf('%s/%s', config('app.deals_dir'), $type), false);
->setPrice($request->price);
->save(sprintf('%s/%s', config('app.deals_dir'), $type), false);*/
return redirect()->route('deals.list', ['type' => $type])->with('status', ($result ? 'Deal mis à jour': 'ERREUR'));
}
return view('update', ['deal' => $deal, 'type' => $type]);


Loading…
Cancel
Save