Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Aug 5, 2024
1 parent c914a4d commit 59f911e
Show file tree
Hide file tree
Showing 13 changed files with 454 additions and 4 deletions.
40 changes: 36 additions & 4 deletions nova-components/ResourceTool/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"php": "^8.1"
},
"require-dev": {
"laravel/nova": "*"
"laravel/nova": "*",
"laravel/nova-devtool": "^1.0"
},
"autoload": {
"psr-4": {
Expand All @@ -28,8 +29,39 @@
"sort-packages": true
},
"repositories": [
{ "type": "path", "url": "../../nova" }
{
"type": "path",
"url": "../../nova"
},
{
"type": "vcs",
"url": "https://github.com/laravel/nova-devtool"
}
],
"minimum-stability": "dev",
"prefer-stable": true
}
"prefer-stable": true,
"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"
],
"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": [
"Composer\\Config::disableProcessTimeout",
"@build",
"@php vendor/bin/testbench serve"
],
"lint": [
"@php vendor/bin/phpstan analyse"
]
}
}
26 changes: 26 additions & 0 deletions nova-components/ResourceTool/testbench.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
providers:
- Laravel\Nova\NovaCoreServiceProvider
- Workbench\App\Providers\NovaServiceProvider

migrations: true

seeders:
- Workbench\Database\Seeders\DatabaseSeeder

workbench:
start: /nova
user: [email protected]
build:
- package-discover
- asset-publish
- create-sqlite-db
- db:wipe
- migrate:refresh
assets:
- nova-assets
sync: []

purge:
directories:
- lang/*
- public/vendor/*
45 changes: 45 additions & 0 deletions nova-components/ResourceTool/workbench/app/Models/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Workbench\App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
use HasFactory, Notifiable;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];

/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
45 changes: 45 additions & 0 deletions nova-components/ResourceTool/workbench/app/Nova/Resource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Workbench\App\Nova;

use Illuminate\Contracts\Database\Eloquent\Builder;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Resource as NovaResource;
use Laravel\Scout\Builder as ScoutBuilder;

abstract class Resource extends NovaResource
{
/**
* Build an "index" query for the given resource.
*/
public static function indexQuery(NovaRequest $request, Builder $query): Builder
{
return $query;
}

/**
* Build a Scout search query for the given resource.
*/
public static function scoutQuery(NovaRequest $request, ScoutBuilder $query): ScoutBuilder
{
return $query;
}

/**
* Build a "detail" query for the given resource.
*/
public static function detailQuery(NovaRequest $request, Builder $query): Builder
{
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.
*/
public static function relatableQuery(NovaRequest $request, Builder $query): Builder
{
return parent::relatableQuery($request, $query);
}
}
106 changes: 106 additions & 0 deletions nova-components/ResourceTool/workbench/app/Nova/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?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;
use Otwell\ResourceTool\ResourceTool;

class User extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = \Workbench\App\Models\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()),

ResourceTool::make(),
];
}

/**
* 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 [];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

namespace Workbench\App\Providers;

use Illuminate\Support\Facades\Gate;
use Laravel\Nova\DevTool\DevTool as 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 [];
}

/**
* 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()
{
//
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Workbench\App\Providers;

use Illuminate\Support\ServiceProvider;

class WorkbenchServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
//
}

/**
* Bootstrap services.
*/
public function boot(): void
{
//
}
}
Empty file.
Loading

0 comments on commit 59f911e

Please sign in to comment.