🚧 Corrige l'enregistrement des mises à jour

This commit is contained in:
Shikiryu 2017-12-10 22:20:58 +01:00
parent be5336fc13
commit d4156ce3a3
1 changed files with 11 additions and 3 deletions

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]);