PHP code example of guanguans / laravel-soar
1. Go to this page and download the library: Download guanguans/laravel-soar library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
guanguans / laravel-soar example snippets
namespace App\Admin\Controllers;
use App\Http\Controllers\Controller;
use App\User;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
class SoarController extends Controller
{
public function sqlScores()
{
// 创建表
DB::select(
<<<SQL
CREATE TABLE `users` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`email` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`email_verified_at` timestamp NULL DEFAULT NULL,
`password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `users_email_unique` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
SQL
);
// 插入数据
User::query()->insert([
'name' => 'soar',
'email' => '[email protected] ',
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
'remember_token' => Str::random(10),
]);
// 更新数据
User::query()->update([
'name' => 'name',
'password' => 'password',
]);
// 查询数据
User::query()->where('name', 'soar')->groupBy('name')->having('created_at', '>', now())->get();
// 删除数据
User::query()->where('name', 'soar')->delete();
// 删除表
DB::select('DROP table `users`;');
// return response()->json(['message' => 'ok']); // JSON 响应
return response('ok'); // HTML 响应
}
}
declare(strict_types=1);
namespace Guanguans\LaravelSoar\Contracts;
use Illuminate\Support\Collection;
interface Output
{
/**
* @param \Illuminate\Console\Events\CommandFinished|\Symfony\Component\HttpFoundation\Response $dispatcher
*/
public function shouldOutput($dispatcher): bool;
/**
* @param \Illuminate\Console\Events\CommandFinished|\Symfony\Component\HttpFoundation\Response $dispatcher
*/
public function output(Collection $scores, $dispatcher);
}
return [
...
'output' => [
...
Guanguans\LaravelSoar\Outputs\LogOutput::class => ['channel' => 'daily', 'level' => 'warning'],
...
],
...
];
app('soar'); // 获取 Soar 实例
/**
* Soar 门面.
*
* @method static \Guanguans\LaravelSoar\Soar create(array $options = [], null|string $soarBinary = null)
* @method static string help()
* @method static string version()
* @method static \Guanguans\LaravelSoar\Soar clone()
* @method static array arrayScores(array|string $sqls, int $depth = 512, int $options = 0)
* @method static string jsonScores(array|string $sqls)
* @method static string htmlScores(array|string $sqls)
* @method static string markdownScores(array|string $sqls)
* @method static string scores(array|string $sqls)
* @method static \Guanguans\LaravelSoar\Soar addOptions(array $options)
* @method static \Guanguans\LaravelSoar\Soar addOption(string $key, void $value)
* @method static \Guanguans\LaravelSoar\Soar removeOptions(array $keys)
* @method static \Guanguans\LaravelSoar\Soar removeOption(string $key)
* @method static \Guanguans\LaravelSoar\Soar onlyOptions(array $keys = ['-test-dsn','-online-dsn'])
* @method static \Guanguans\LaravelSoar\Soar onlyOption(string $key)
* @method static \Guanguans\LaravelSoar\Soar setOptions(array $options)
* @method static \Guanguans\LaravelSoar\Soar setOption(string $key, void $value)
* @method static \Guanguans\LaravelSoar\Soar mergeOptions(array $options)
* @method static \Guanguans\LaravelSoar\Soar mergeOption(string $key, void $value)
* @method static array getOptions()
* @method static void getOption(string $key, void $default = null)
* @method static string getSerializedNormalizedOptions()
* @method static array getNormalizedOptions()
* @method static string getSoarBinary()
* @method static \Guanguans\LaravelSoar\Soar setSoarBinary(string $soarBinary)
* @method static void dd(void ...$args)
* @method static \Guanguans\LaravelSoar\Soar dump(void ...$args)
* @method static string run(array|string $withOptions = [], null|callable $processTapper = null, null|callable $callback = null)
* @method static \Guanguans\LaravelSoar\Soar|\Illuminate\Support\HigherOrderTapProxy tap(null|callable $callback = null)
*
* @see \Guanguans\LaravelSoar\Soar
*/
class Soar{}
namespace Illuminate\Database\Eloquent {
/**
* @method string toRawSql()
* @method void dumpRawSql()
* @method void ddRawSql()
* @method array toSoarArrayScores(int $depth = 512, int $options = 0)
* @method void dumpSoarArrayScores(int $depth = 512, int $options = 0)
* @method void ddSoarArrayScores(int $depth = 512, int $options = 0)
* @method string toSoarJsonScores()
* @method void dumpSoarJsonScores()
* @method void ddSoarJsonScores()
* @method string toSoarHtmlScores()
* @method void echoSoarHtmlScores()
* @method void exitSoarHtmlScores()
*
* @mixin \Illuminate\Database\Query\Builder
*
* @see \Guanguans\LaravelSoar\Macros\QueryBuilderMacro
* @see \Illuminate\Database\Eloquent\Builder
*/
class Builder
{
}
}
shell
$ php artisan vendor:publish --provider="Guanguans\\LaravelSoar\\SoarServiceProvider"