✨ Ajoute des vues
This commit is contained in:
@@ -2,14 +2,15 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Deal;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Create a new controller instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
@@ -25,4 +26,27 @@ class HomeController extends Controller
|
||||
{
|
||||
return view('home');
|
||||
}
|
||||
|
||||
public function list($type)
|
||||
{
|
||||
$deals = [];
|
||||
$folder_path = sprintf('%s/%s', config('app.deals_dir'), $type);
|
||||
if (file_exists($folder_path)) {
|
||||
foreach (new \RecursiveDirectoryIterator($folder_path) as $folder) {
|
||||
if (file_exists($folder->getPathname().'/data.json')) {
|
||||
$deals[] = new Deal($folder_path, $folder->getBasename());
|
||||
}
|
||||
}
|
||||
}
|
||||
return view('list', ['deals' => $deals, 'type' => $type]);
|
||||
}
|
||||
|
||||
public function view($type, $id)
|
||||
{
|
||||
$folder_path = sprintf('%s/%s/%s', config('app.deals_dir'), $type, $id);
|
||||
if (file_exists($folder_path)) {
|
||||
$deal = new Deal(sprintf('%s/%s', config('app.deals_dir'), $type), $id);
|
||||
}
|
||||
return view('view', ['deal' => $deal, 'type' => $type]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user