|
1 | | -# laravel-web-tinker |
| 1 | +# laravel-code-runner |
2 | 2 |
|
3 | | -[简体中文](README-zh_CN.md) | [ENGLISH](README.md) |
| 3 | +[ENGLISH](README.md) | [简体中文](README-zh_CN.md) |
4 | 4 |
|
5 | | -> A PHP package template repository. - 一个 PHP 软件包模板存储库。 |
| 5 | +> Run the code in the browser. - 在浏览器中运行代码。 |
6 | 6 |
|
7 | | -[](https://github.com/guanguans/laravel-web-tinker/actions) |
8 | | -[](https://github.com/guanguans/laravel-web-tinker/actions) |
9 | | -[](https://codecov.io/gh/guanguans/laravel-web-tinker) |
10 | | -[](//packagist.org/packages/guanguans/laravel-web-tinker) |
11 | | -[](//packagist.org/packages/guanguans/laravel-web-tinker) |
12 | | -[](//packagist.org/packages/guanguans/laravel-web-tinker) |
13 | | - |
14 | | - |
15 | | - |
16 | | -## Features |
17 | | - |
18 | | -* Feature |
| 7 | +[](https://github.com/guanguans/laravel-code-runner/actions) |
| 8 | +[](https://github.com/guanguans/laravel-code-runner/actions) |
| 9 | +[](https://codecov.io/gh/guanguans/laravel-code-runner) |
| 10 | +[](//packagist.org/packages/guanguans/laravel-code-runner) |
| 11 | +[](//packagist.org/packages/guanguans/laravel-code-runner) |
| 12 | +[](//packagist.org/packages/guanguans/laravel-code-runner) |
| 13 | + |
| 14 | + |
19 | 15 |
|
20 | 16 | ## Requirement |
21 | 17 |
|
22 | 18 | * PHP >= 7.4 |
| 19 | +* Laravel >= 7.0 |
23 | 20 |
|
24 | 21 | ## Installation |
25 | 22 |
|
| 23 | +You can install the package via composer. |
| 24 | + |
| 25 | +```bash |
| 26 | +$ composer require guanguans/laravel-code-runner --prefer-dist -vvv |
| 27 | +``` |
| 28 | + |
| 29 | +Next, you must publish the assets from this package by running this command. |
| 30 | + |
| 31 | +```bash |
| 32 | +$ php artisan code-runner:install |
| 33 | +``` |
| 34 | + |
| 35 | +Optionally, you can publish the config file of the package. |
| 36 | + |
26 | 37 | ```bash |
27 | | -$ composer require guanguans/laravel-web-tinker --prefer-dist -vvv |
| 38 | +$ php artisan vendor:publish --provider="Guanguans\LaravelCodeRunner\WebTinkerServiceProvider" --tag="code-runner-config" |
28 | 39 | ``` |
29 | 40 |
|
30 | 41 | ## Usage |
31 | 42 |
|
| 43 | + |
| 44 | + |
| 45 | +By default this package will only run in a local environment. |
| 46 | + |
| 47 | +Visit `/code-runner` in your app to view page. |
| 48 | + |
| 49 | +### Authorization |
| 50 | + |
| 51 | +Should you want to run this in another environment (we do not recommend this), there are two steps you must perform. |
| 52 | + |
| 53 | +1. You must set the `enabled` variable in the `code-runner` config file to `true`. |
| 54 | + |
| 55 | +2. You must register a `view-code-runner` ability. A good place to do this is in the `AuthServiceProvider` that ships with Laravel. |
| 56 | + |
| 57 | +```php |
| 58 | +use Illuminate\Contracts\Auth\Authenticatable; |
| 59 | + |
| 60 | +public function boot() |
| 61 | +{ |
| 62 | + $this->registerPolicies(); |
| 63 | + |
| 64 | + Gate::define('view-code-runner', function (?Authenticatable $user = null) { |
| 65 | + // Return true if access to web tinker is allowed. Here's an example: |
| 66 | + return $user && in_array($user->email, [ |
| 67 | + 'admin@example.com', |
| 68 | + ]); |
| 69 | + }); |
| 70 | +} |
| 71 | +``` |
| 72 | + |
32 | 73 | ## Testing |
33 | 74 |
|
34 | 75 | ```bash |
|
0 commit comments