를 사용하는 것이 가능하다 시험에서이 작업을 수행 한 이후
\Illuminate\Support\Facades\Artisan::call('migrate');
\Illuminate\Support\Facades\Artisan::call('db:seed');
( 그래서 여기에 주위를 재생 후 최종 솔루션은 테스트하지 않습니다.
내 컨트롤러 :
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Storage;
class TestController extends Controller
{
public function index() {
// Values I want to insert
$data = [
'APP_KEY' => str_random(32),
'DB_HOST' => 'localhost',
'DB_DATABASE' => 'lara_test',
'DB_USERNAME' => 'root',
'DB_PASSWORD' => ''
];
// default values of .env.example that I want to change
$defaults = ['SomeRandomString', '127.0.0.1', 'homestead', 'homestead', 'secret'];
// get contents of .env.example file
$content = file_get_contents(base_path() . '/.env.example');
// replace default values with new ones
$i = 0;
foreach ($data as $key => $value) {
$content = str_replace($key.'='.$defaults[$i], $key.'='.$value, $content);
$i++;
}
// Create new .env file
Storage::disk('root')->put('.env', $content);
// run all migrations
Artisan::call('migrate');
// run all db seeds
Artisan::call('db:seed');
dd('done');
}
}
새 디스크 드라이버 :
프로젝트 루트에 새 파일을 만들려면, 나는 새로운 디스크 드라이버를 작성했다. 내 config/app.php
파일에 다음 코드를 추가 :
'disks' => [
.....
'root' => [
'driver' => 'local',
'root' => base_path(),
],
],
이것은 사용하여 루트에 새 파일을 만들 날을 사용할 수 :
이
Storage::disk('root')->put('filename', $content);
요약 :
그래서 기본적으로 내가 무엇입니까 내용을 .env.example 파일로 변경하고 원하는 상수 값을 변경 한 다음 새 .env 파일을 만듭니다. 그 후 나는 모든 이주와 종자를 쫓아 갔다.
참고 : 나는 수동 때문에 No supported encrypter found. The cipher and/or key length are invalid. 나는 코드 안에 모든 일을하려고하기 때문에
하지 명령을 통해 바보 같은 오류로 APP_KEY
을 설정했다 - 나는 Artisan::call('key:generate');
를 사용하여 시도하지만 어떤 이상한 이유로 그 문제를 해결하기 위해 작동하지 않았으므로 수동으로 32 비트 길이의 임의의 문자열을 수동으로 만들어야하고 APP_KEY
으로 설정해야합니다.
다른 사람에게 도움이되기를 바랍니다. :) @rypskar에게 도움을 주신 데 감사드립니다.
도움 주셔서 감사합니다. – Jazzbot