Created
February 9, 2019 02:06
-
-
Save n1215/ca09e95b61577b5444519f79fe376483 to your computer and use it in GitHub Desktop.
simple Laravel play ground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
declare(strict_types=1); | |
namespace MyPlayGround; | |
use App\User; | |
use Illuminate\Support\Facades\Hash; | |
/** | |
* この関数内に試したい処理を書く | |
* @return void|int | |
*/ | |
function main() | |
{ | |
$user = new User([ | |
'name' => 'Alice', | |
'email' => '[email protected]', | |
'password' => Hash::make('password') | |
]); | |
$user->save(); | |
dump(User::query()->orderByDesc('id')->first()->toArray()); | |
throw new \RuntimeException('例外だよ'); | |
} | |
/** | |
* 以下はartisanの中身のコードを参考にした実行コード | |
*/ | |
require __DIR__.'/vendor/autoload.php'; | |
(function (callable $runner) { | |
bootstrap: { | |
define('LARAVEL_START', microtime(true)); | |
$app = require_once __DIR__ . '/bootstrap/app.php'; | |
/** @var \App\Console\Kernel $kernel */ | |
$kernel = $app->make(\Illuminate\Contracts\Console\Kernel::class); | |
$kernel->bootstrap(); | |
$input = new \Symfony\Component\Console\Input\ArgvInput; | |
$status = 0; | |
} | |
/** @var \Illuminate\Database\DatabaseManager $dbManager */ | |
$dbManager = $app->make('db'); | |
$dbManager->beginTransaction(); | |
try { | |
$status = (int) $runner(); | |
} finally { | |
$dbManager->rollBack(); | |
$kernel->terminate($input, $status); | |
} | |
exit($status); | |
})('\MyPlayGround\main'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PhpStormから