Skip to content

Commit

Permalink
Merge pull request #77 from crynobone/workbench
Browse files Browse the repository at this point in the history
Workbench Integration
  • Loading branch information
simonhamp committed Sep 1, 2023
2 parents d09beeb + dd92fdf commit 8d5a72c
Show file tree
Hide file tree
Showing 8 changed files with 329 additions and 2 deletions.
23 changes: 21 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,37 @@
"maatwebsite/excel": "^3.1"
},
"require-dev": {
"laravel/pint": "^1.6"
"laravel/pint": "^1.6",
"nova-kit/nova-devtool": "^1.2.1"
},
"autoload": {
"psr-4": {
"SimonHamp\\LaravelNovaCsvImport\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Workbench\\App\\": "workbench/app/",
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
}
},
"scripts": {
"post-autoload-dump": [
"@clear",
"@prepare"
],
"lint": "@pint",
"lint:test": "@pint --test",
"lint:dirty": "@pint --dirty",
"pint": "vendor/bin/pint"
"pint": "vendor/bin/pint",
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": "@php vendor/bin/testbench workbench:build --ansi",
"serve": [
"@build",
"@php vendor/bin/testbench serve"
]
},
"extra": {
"laravel": {
Expand Down
25 changes: 25 additions & 0 deletions testbench.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
providers:
- Laravel\Nova\NovaCoreServiceProvider
- SimonHamp\LaravelNovaCsvImport\ToolServiceProvider
- Workbench\App\Providers\NovaServiceProvider

migrations: true

seeders:
- Workbench\Database\Seeders\DatabaseSeeder

workbench:
start: /nova
build:
- asset-publish
- create-sqlite-db
- db:wipe
- migrate:refresh
assets:
- nova-assets
sync: []

purge:
directories:
- lang/*
- public/vendor/*
59 changes: 59 additions & 0 deletions workbench/app/Nova/Resource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Workbench\App\Nova;

use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Resource as NovaResource;

abstract class Resource extends NovaResource
{
/**
* Build an "index" query for the given resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public static function indexQuery(NovaRequest $request, $query)
{
return $query;
}

/**
* Build a Scout search query for the given resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @param \Laravel\Scout\Builder $query
* @return \Laravel\Scout\Builder
*/
public static function scoutQuery(NovaRequest $request, $query)
{
return $query;
}

/**
* Build a "detail" query for the given resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public static function detailQuery(NovaRequest $request, $query)
{
return parent::detailQuery($request, $query);
}

/**
* Build a "relatable" query for the given resource.
*
* This query determines which instances of the model may be attached to other resources.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public static function relatableQuery(NovaRequest $request, $query)
{
return parent::relatableQuery($request, $query);
}
}
103 changes: 103 additions & 0 deletions workbench/app/Nova/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace Workbench\App\Nova;

use Illuminate\Http\Request;
use Illuminate\Validation\Rules;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Password;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Http\Requests\NovaRequest;

class User extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = \Illuminate\Foundation\Auth\User::class;

/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'name';

/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'id', 'name', 'email',
];

/**
* Get the fields displayed by the resource.
*
* @return array
*/
public function fields(NovaRequest $request)
{
return [
ID::make()->sortable(),

Text::make('Name')
->sortable()
->rules('required', 'max:255'),

Text::make('Email')
->sortable()
->rules('required', 'email', 'max:254')
->creationRules('unique:users,email')
->updateRules('unique:users,email,{{resourceId}}'),

Password::make('Password')
->onlyOnForms()
->creationRules('required', Rules\Password::defaults())
->updateRules('nullable', Rules\Password::defaults()),
];
}

/**
* Get the cards available for the request.
*
* @return array
*/
public function cards(NovaRequest $request)
{
return [];
}

/**
* Get the filters available for the resource.
*
* @return array
*/
public function filters(NovaRequest $request)
{
return [];
}

/**
* Get the lenses available for the resource.
*
* @return array
*/
public function lenses(NovaRequest $request)
{
return [];
}

/**
* Get the actions available for the resource.
*
* @return array
*/
public function actions(NovaRequest $request)
{
return [];
}
}
92 changes: 92 additions & 0 deletions workbench/app/Providers/NovaServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace Workbench\App\Providers;

use Illuminate\Support\Facades\Gate;
use NovaKit\NovaDevTool\Nova;
use Laravel\Nova\NovaApplicationServiceProvider;
use Orchestra\Workbench\Workbench;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
parent::boot();
}

/**
* Register the Nova routes.
*
* @return void
*/
protected function routes()
{
Nova::routes()
->withAuthenticationRoutes()
->withPasswordResetRoutes()
->register();
}

/**
* Register the Nova gate.
*
* This gate determines who can access Nova in non-local environments.
*
* @return void
*/
protected function gate()
{
Gate::define('viewNova', function ($user) {
return true;
});
}

/**
* Get the dashboards that should be listed in the Nova sidebar.
*
* @return array
*/
protected function dashboards()
{
return [
new \Laravel\Nova\Dashboards\Main(),
];
}

/**
* Get the tools that should be listed in the Nova sidebar.
*
* @return array
*/
public function tools()
{
return [
new \SimonHamp\LaravelNovaCsvImport\LaravelNovaCsvImport(),
];
}

/**
* Register the application's Nova resources.
*
* @return void
*/
protected function resources()
{
Nova::resourcesIn(Workbench::path('app/Nova'));
}

/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
}
Empty file.
Empty file.
29 changes: 29 additions & 0 deletions workbench/database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Workbench\Database\Seeders;

use Illuminate\Database\Seeder;
use Orchestra\Testbench\Factories\UserFactory;

class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$password = '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi'; // password

UserFactory::new()->create([
'name' => 'Laravel Nova',
'email' => '[email protected]',
'password' => $password,
]);

UserFactory::new()->times(9)->create([
'password' => $password,
]);
}
}

0 comments on commit 8d5a72c

Please sign in to comment.