Skip to content

Instantly share code, notes, and snippets.

@n1215
Created February 9, 2019 02:06
Show Gist options
  • Save n1215/ca09e95b61577b5444519f79fe376483 to your computer and use it in GitHub Desktop.
Save n1215/ca09e95b61577b5444519f79fe376483 to your computer and use it in GitHub Desktop.
simple Laravel play ground
#!/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');
@n1215
Copy link
Author

n1215 commented Feb 9, 2019

PhpStormから

run_on_phpstorm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment