Skip to content

Commit 0751ead

Browse files
Merge pull request #57 from crynobone/workbench
Test the package directly using Workbench
2 parents 24d33ef + fa15302 commit 0751ead

File tree

10 files changed

+347
-3
lines changed

10 files changed

+347
-3
lines changed

.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
* text=auto
2+
3+
# Ignore following folder/file.
4+
/.github export-ignore
5+
/tests export-ignore
6+
/workbench export-ignore
7+
/.gitattributes export-ignore
8+
/.gitignore export-ignore
9+
/phpunit.xml export-ignore
10+
/testbench.yaml export-ignore

composer.json

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"spatie/valuestore": "^1.3"
2828
},
2929
"require-dev": {
30-
"orchestra/testbench": "^7.4",
30+
"orchestra/testbench": "^7.29|^8.9",
3131
"phpunit/phpunit": "^9.5"
3232
},
3333
"autoload": {
@@ -37,7 +37,9 @@
3737
},
3838
"autoload-dev": {
3939
"psr-4": {
40-
"Tests\\": "tests/"
40+
"Tests\\": "tests/",
41+
"Workbench\\App\\": "workbench/app/",
42+
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
4143
}
4244
},
4345
"extra": {
@@ -52,5 +54,19 @@
5254
"sort-packages": true
5355
},
5456
"minimum-stability": "dev",
55-
"prefer-stable": true
57+
"prefer-stable": true,
58+
"scripts": {
59+
"post-autoload-dump": [
60+
"@clear",
61+
"@prepare"
62+
],
63+
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
64+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
65+
"build": "@php vendor/bin/testbench workbench:build",
66+
"serve": [
67+
"@build",
68+
"@php vendor/bin/testbench serve"
69+
],
70+
"test": "@php vendor/bin/phpunit"
71+
}
5672
}

testbench.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
providers:
2+
- Workbench\App\Providers\NovaServiceProvider
3+
4+
migrations: true
5+
seeders:
6+
- Workbench\Database\Seeders\DatabaseSeeder
7+
8+
workbench:
9+
start: '/nova'
10+
user: nova@laravel.com
11+
build:
12+
- asset-publish
13+
- create-sqlite-db
14+
- migrate:refresh
15+
assets:
16+
- nova-settings-tool
17+
- nova-assets

workbench/app/Models/User.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Workbench\App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Foundation\Auth\User as Authenticatable;
7+
use Illuminate\Notifications\Notifiable;
8+
9+
class User extends Authenticatable
10+
{
11+
use HasFactory, Notifiable;
12+
13+
/**
14+
* The attributes that are mass assignable.
15+
*
16+
* @var array<int, string>
17+
*/
18+
protected $fillable = [
19+
'name',
20+
'email',
21+
'password',
22+
];
23+
24+
/**
25+
* The attributes that should be hidden for serialization.
26+
*
27+
* @var array<int, string>
28+
*/
29+
protected $hidden = [
30+
'password',
31+
'remember_token',
32+
];
33+
34+
/**
35+
* The attributes that should be cast.
36+
*
37+
* @var array<string, string>
38+
*/
39+
protected $casts = [
40+
'email_verified_at' => 'datetime',
41+
'password' => 'hashed',
42+
];
43+
}

workbench/app/Nova/User.php

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
3+
namespace Workbench\App\Nova;
4+
5+
use Illuminate\Http\Request;
6+
use Illuminate\Validation\Rules;
7+
use Laravel\Nova\Fields\ID;
8+
use Laravel\Nova\Fields\Password;
9+
use Laravel\Nova\Fields\Text;
10+
use Laravel\Nova\Http\Requests\NovaRequest;
11+
use Laravel\Nova\Resource;
12+
13+
class User extends Resource
14+
{
15+
/**
16+
* The model the resource corresponds to.
17+
*
18+
* @var string
19+
*/
20+
public static $model = \Workbench\App\Models\User::class;
21+
22+
/**
23+
* The single value that should be used to represent the resource when being displayed.
24+
*
25+
* @var string
26+
*/
27+
public static $title = 'name';
28+
29+
/**
30+
* The columns that should be searched.
31+
*
32+
* @var array
33+
*/
34+
public static $search = [
35+
'id', 'name', 'email',
36+
];
37+
38+
/**
39+
* Get the fields displayed by the resource.
40+
*
41+
* @return array
42+
*/
43+
public function fields(NovaRequest $request)
44+
{
45+
return [
46+
ID::make()->sortable(),
47+
48+
Text::make('Name')
49+
->sortable()
50+
->rules('required', 'max:255'),
51+
52+
Text::make('Email')
53+
->sortable()
54+
->rules('required', 'email', 'max:254')
55+
->creationRules('unique:users,email')
56+
->updateRules('unique:users,email,{{resourceId}}'),
57+
58+
Password::make('Password')
59+
->onlyOnForms()
60+
->creationRules('required', Rules\Password::defaults())
61+
->updateRules('nullable', Rules\Password::defaults()),
62+
];
63+
}
64+
65+
/**
66+
* Get the cards available for the request.
67+
*
68+
* @return array
69+
*/
70+
public function cards(NovaRequest $request)
71+
{
72+
return [];
73+
}
74+
75+
/**
76+
* Get the filters available for the resource.
77+
*
78+
* @return array
79+
*/
80+
public function filters(NovaRequest $request)
81+
{
82+
return [];
83+
}
84+
85+
/**
86+
* Get the lenses available for the resource.
87+
*
88+
* @return array
89+
*/
90+
public function lenses(NovaRequest $request)
91+
{
92+
return [];
93+
}
94+
95+
/**
96+
* Get the actions available for the resource.
97+
*
98+
* @return array
99+
*/
100+
public function actions(NovaRequest $request)
101+
{
102+
return [];
103+
}
104+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
namespace Workbench\App\Providers;
4+
5+
use Illuminate\Support\Facades\Gate;
6+
use Laravel\Nova\Nova;
7+
use Laravel\Nova\NovaApplicationServiceProvider;
8+
9+
class NovaServiceProvider extends NovaApplicationServiceProvider
10+
{
11+
/**
12+
* Bootstrap any application services.
13+
*
14+
* @return void
15+
*/
16+
public function boot()
17+
{
18+
parent::boot();
19+
20+
Nova::initialPath('/settings');
21+
}
22+
23+
/**
24+
* Register the Nova routes.
25+
*
26+
* @return void
27+
*/
28+
protected function routes()
29+
{
30+
Nova::routes()
31+
->withAuthenticationRoutes()
32+
->withPasswordResetRoutes()
33+
->register();
34+
}
35+
36+
/**
37+
* Register the Nova gate.
38+
*
39+
* This gate determines who can access Nova in non-local environments.
40+
*
41+
* @return void
42+
*/
43+
protected function gate()
44+
{
45+
Gate::define('viewNova', function ($user) {
46+
return true;
47+
});
48+
}
49+
50+
/**
51+
* Get the dashboards that should be listed in the Nova sidebar.
52+
*
53+
* @return array
54+
*/
55+
protected function dashboards()
56+
{
57+
return [];
58+
}
59+
60+
/**
61+
* Get the tools that should be listed in the Nova sidebar.
62+
*
63+
* @return array
64+
*/
65+
public function tools()
66+
{
67+
return [
68+
new \Bakerkretzmar\NovaSettingsTool\SettingsTool(),
69+
];
70+
}
71+
72+
/**
73+
* Register the application's Nova resources.
74+
*
75+
* @return void
76+
*/
77+
protected function resources()
78+
{
79+
Nova::resources([
80+
\Workbench\App\Nova\User::class,
81+
]);
82+
}
83+
84+
/**
85+
* Register any application services.
86+
*
87+
* @return void
88+
*/
89+
public function register()
90+
{
91+
//
92+
}
93+
}

workbench/database/factories/.gitkeep

Whitespace-only changes.

workbench/database/migrations/.gitkeep

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Workbench\Database\Seeders;
4+
5+
use Illuminate\Database\Seeder;
6+
7+
class DatabaseSeeder extends Seeder
8+
{
9+
/**
10+
* Seed the application's database.
11+
*
12+
* @return void
13+
*/
14+
public function run()
15+
{
16+
$this->call(UserTableSeeder::class);
17+
}
18+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Workbench\Database\Seeders;
4+
5+
use Illuminate\Database\Seeder;
6+
use Workbench\App\Models\User;
7+
8+
class UserTableSeeder extends Seeder
9+
{
10+
/**
11+
* Run the database seeds.
12+
*
13+
* @return void
14+
*/
15+
public function run()
16+
{
17+
$password = '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi'; // password
18+
19+
User::forceCreate([
20+
'name' => 'Taylor Otwell',
21+
'email' => 'taylor@laravel.com',
22+
'password' => $password,
23+
]);
24+
25+
User::forceCreate([
26+
'name' => 'James Brooks',
27+
'email' => 'james@laravel.com',
28+
'password' => $password,
29+
]);
30+
31+
User::forceCreate([
32+
'name' => 'David Hemphill',
33+
'email' => 'david@laravel.com',
34+
'password' => $password,
35+
]);
36+
37+
User::forceCreate([
38+
'name' => 'Laravel Nova',
39+
'email' => 'nova@laravel.com',
40+
'password' => $password,
41+
]);
42+
}
43+
}

0 commit comments

Comments
 (0)