🚧 Ajoute la suppression

This commit is contained in:
Clement Desmidt 2017-11-13 20:51:16 +01:00
parent 7e454a06ad
commit f02a22c8b3
3 changed files with 16 additions and 0 deletions

View File

@ -49,4 +49,18 @@ class HomeController extends Controller
} }
return view('view', ['deal' => $deal, 'type' => $type]); return view('view', ['deal' => $deal, 'type' => $type]);
} }
public function delete($type, $id)
{
$result = false;
$folder = sprintf('%s/%s/%s', config('app.deals_dir'), $type, $id);
if (file_exists($folder)) {
$files = array_diff(scandir($folder), ['.','..']);
foreach ($files as $file) {
(is_dir(sprintf('%s/%s', $folder, $file))) ? delete_folder(sprintf('%s/%s', $folder, $file)) : unlink(sprintf('%s/%s', $folder, $file));
}
$result = rmdir($folder);
}
return redirect()->route('deals.list', ['type' => $type])->with('status', ($result ? 'Deal supprimé': 'ERREUR'));
}
} }

View File

@ -36,6 +36,7 @@
</td> </td>
<td> <td>
<a href="<?php echo route('deals.view', ['type' => $type, 'id' => $deal->getId()]); ?>">Voir</a> <a href="<?php echo route('deals.view', ['type' => $type, 'id' => $deal->getId()]); ?>">Voir</a>
<a href="<?php echo route('deals.delete', ['type' => $type, 'id' => $deal->getId()]); ?>">Supprimer</a>
</td> </td>
</tr> </tr>
@endforeach</tbody> @endforeach</tbody>

View File

@ -21,3 +21,4 @@ Route::get('/deals/list/{type}', 'HomeController@list')->name('deals.list');
Route::get('/deals/view/{type}/{id}', 'HomeController@view')->name('deals.view'); Route::get('/deals/view/{type}/{id}', 'HomeController@view')->name('deals.view');
Route::get('/deals/delete/{type}/{id}', 'HomeController@delete')->name('deals.delete');