add api display content
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Symfony\Component\Process;
|
||||
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||
|
||||
class AdminSetup extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'setup:first';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'This command for initialize dan .env';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$envFile = base_path('.env');
|
||||
$envExample = base_path('.env.example');
|
||||
|
||||
// Copy .env.example jika belum ada
|
||||
if (! File::exists($envFile)) {
|
||||
File::copy($envExample, $envFile);
|
||||
$this->info('.env berhasil dibuat dari .env.example');
|
||||
}
|
||||
|
||||
$dbConnection = $this->choice(
|
||||
'Pilih database yang digunakan',
|
||||
['mysql', 'pgsql', 'sqlite'],
|
||||
1 // default pgsql
|
||||
);
|
||||
|
||||
$dbHost = $this->ask('Masukkan IP Address / Host', '127.0.0.1');
|
||||
$dbPort = $this->ask(
|
||||
'Masukkan Port Database',
|
||||
$dbConnection === 'mysql' ? '3306' : '5432'
|
||||
);
|
||||
$dbDatabase = $this->ask('Masukkan Nama Database', 'parkir');
|
||||
$dbUsername = $this->ask('Masukkan Username Database', 'postgres');
|
||||
$dbPassword = $this->secret('Masukkan Password Database');
|
||||
|
||||
$env = file_get_contents($envFile);
|
||||
|
||||
$replacements = [
|
||||
'APP_DEBUG' => 'true',
|
||||
'DB_CONNECTION' => $dbConnection,
|
||||
'DB_HOST' => $dbHost,
|
||||
'DB_PORT' => $dbPort,
|
||||
'DB_DATABASE' => $dbDatabase,
|
||||
'DB_USERNAME' => $dbUsername,
|
||||
'DB_PASSWORD' => $dbPassword,
|
||||
];
|
||||
|
||||
foreach ($replacements as $key => $value) {
|
||||
$env = preg_replace(
|
||||
"/^{$key}=.*/m",
|
||||
"{$key}={$value}",
|
||||
$env
|
||||
);
|
||||
}
|
||||
|
||||
file_put_contents($envFile, $env);
|
||||
|
||||
$this->info('Konfigurasi .env berhasil diperbarui.');
|
||||
|
||||
$this->newLine();
|
||||
|
||||
$this->table(
|
||||
['Key', 'Value'],
|
||||
[
|
||||
['DB_CONNECTION', $dbConnection],
|
||||
['DB_HOST', $dbHost],
|
||||
['DB_PORT', $dbPort],
|
||||
['DB_DATABASE', $dbDatabase],
|
||||
['DB_USERNAME', $dbUsername],
|
||||
]
|
||||
);
|
||||
|
||||
$this->newLine();
|
||||
|
||||
if ($this->confirm('Jalankan php artisan key:generate?', true)) {
|
||||
Artisan::call('key:generate');
|
||||
$this->line(Artisan::output());
|
||||
}
|
||||
|
||||
// if ($this->confirm('Jalankan php artisan migrate?', false)) {
|
||||
// Artisan::call('migrate', ['--force' => true]);
|
||||
// $this->line(Artisan::output());
|
||||
// }
|
||||
|
||||
if ($this->confirm('Jalankan php artisan config:clear?', true)) {
|
||||
Artisan::call('config:clear');
|
||||
$this->line(Artisan::output());
|
||||
}
|
||||
|
||||
if ($this->confirm('Jalankan php artisan cache:clear?', true)) {
|
||||
Artisan::call('cache:clear');
|
||||
$this->line(Artisan::output());
|
||||
}
|
||||
|
||||
$this->info('Setup selesai.');
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\V1;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DisplayContentController extends Controller
|
||||
{
|
||||
public function index() {
|
||||
// $path = 'assets/content/display_content/image/';
|
||||
|
||||
// return response()->json([
|
||||
// "id" => 1,
|
||||
// "type" => 'image',
|
||||
// 'content' => [
|
||||
// url($path . '1.jpg'),
|
||||
// url($path . '2.jpg'),
|
||||
// url($path . '3.jpg'),
|
||||
// url($path . '4.jpg'),
|
||||
// url($path . '5.jpg'),
|
||||
// ]
|
||||
// ]);
|
||||
|
||||
$path = 'assets/content/display_content/video/';
|
||||
|
||||
return response()->json([
|
||||
"id" => 1,
|
||||
"type" => 'video',
|
||||
'content' => [
|
||||
// "display_1" => url($path . '1.mp4'),
|
||||
// "display_2" => url($path . '2.mp4'),
|
||||
// "display_3" => url($path . '3.mp4'),
|
||||
// url($path . '1.mp4'),
|
||||
url($path . 'video_2bak.mp4'),
|
||||
url($path . 'video_3bak.mp4'),
|
||||
// url($path . 'new_3.mp4'),
|
||||
// url($path . 'new_4.mp4'),
|
||||
// url($path . 'new_5.mp4'),
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user