Skip to content

Commit 97ddeba

Browse files
authored
Supports Laravel Nova 5 (#41)
* wip Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> * Supports Laravel Nova 5 Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> * wip Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com> --------- Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
1 parent c4e006b commit 97ddeba

File tree

18 files changed

+512
-23
lines changed

18 files changed

+512
-23
lines changed

composer.json

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@
88
],
99
"license": "MIT",
1010
"require": {
11-
"php": "^7.2|^8.0",
12-
"laravel/nova": "^4.13",
13-
"nova-kit/nova-packages-tool": "^1.2",
11+
"php": "^8.1",
12+
"laravel/nova": "^5.0",
1413
"spatie/opening-hours": "^2.0|^3.0"
1514
},
15+
"require-dev": {
16+
"laravel/nova-devtool": "^1.1.4"
17+
},
1618
"autoload": {
1719
"psr-4": {
1820
"SadekD\\NovaOpeningHoursField\\": "src/"
1921
}
2022
},
23+
"autoload-dev": {
24+
"psr-4": {
25+
"Workbench\\App\\": "workbench/app/",
26+
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
27+
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
28+
}
29+
},
2130
"extra": {
2231
"laravel": {
2332
"providers": [
@@ -30,5 +39,19 @@
3039
"type": "composer",
3140
"url": "https://nova.laravel.com"
3241
}
33-
]
42+
],
43+
"scripts": {
44+
"post-autoload-dump": [
45+
"@clear",
46+
"@prepare"
47+
],
48+
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
49+
"prepare": "@php vendor/bin/testbench package:discover --ansi",
50+
"build": "@php vendor/bin/testbench workbench:build --ansi",
51+
"serve": [
52+
"Composer\\Config::disableProcessTimeout",
53+
"@build",
54+
"@php vendor/bin/testbench serve --ansi"
55+
]
56+
}
3457
}

dist/js/field.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,15 @@
88
"prod": "mix --production"
99
},
1010
"devDependencies": {
11-
"@inertiajs/inertia": "^0.11.0",
1211
"@vue/babel-plugin-jsx": "^1.1.1",
13-
"form-backend-validation": "^2.4.0",
14-
"laravel-mix": "^6.0.43",
15-
"laravel-nova-ui": "^0.4.10",
12+
"laravel-nova-devtool": "file:vendor/laravel/nova-devtool",
1613
"lodash": "^4.17.21",
17-
"postcss": "^8.4.12",
1814
"resolve-url-loader": "^4.0.0",
1915
"sass": "^1.49.11",
2016
"sass-loader": "^12.6.0",
21-
"vue-loader": "^17.0.0",
22-
"vue-template-compiler": "^2.6.14",
2317
"vuex": "^4.0.2"
2418
},
2519
"dependencies": {
26-
"vue": "^3.2.31"
20+
"vue": "^3.5.13"
2721
}
2822
}

resources/js/components/Nova/IndexField.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<template>
22
<div :class="`text-${field.textAlign}`">
3-
<icon-boolean v-for="day in normalizedWeek" :key="day.day" :value="Object.values(day.intervals).length"/>
3+
<IconBoolean
4+
v-for="day in normalizedWeek"
5+
:key="day.day"
6+
:value="Object.values(day.intervals).length > 0"
7+
/>
48
</div>
59
</template>
610

testbench.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
laravel: '@testbench'
2+
3+
providers:
4+
- Laravel\Nova\NovaServiceProvider
5+
- Laravel\Nova\NovaCoreServiceProvider
6+
- Workbench\App\Providers\NovaServiceProvider
7+
# - Workbench\App\Providers\WorkbenchServiceProvider
8+
9+
migrations:
10+
- workbench/database/migrations
11+
12+
seeders:
13+
- Workbench\Database\Seeders\DatabaseSeeder
14+
15+
workbench:
16+
start: /nova
17+
auth: true
18+
build:
19+
- package:discover
20+
- asset-publish
21+
- create-sqlite-db
22+
- db:wipe
23+
- migrate:refresh
24+
assets:
25+
- nova-assets
26+
sync: []
27+
28+
purge:
29+
directories:
30+
- lang/*
31+
- public/vendor/*

webpack.mix.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
let mix = require('laravel-mix')
22
let path = require('path')
33

4+
mix.extend('nova', new require('laravel-nova-devtool'))
5+
46
mix.setPublicPath('dist')
57
.js('resources/js/field.js', 'js')
68
.sass('resources/sass/field.scss', 'css')
79
.vue({ version: 3 })
8-
.webpackConfig({
9-
externals: {
10-
vue: 'Vue',
11-
'laravel-nova': 'LaravelNova'
12-
},
13-
output: {
14-
uniqueName: 'sadekd/nova-opening-hours-field',
15-
},
16-
})
10+
.nova('sadekd/nova-opening-hours-field')

workbench/app/Models/User.php

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

workbench/app/Nova/Resource.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Workbench\App\Nova;
4+
5+
use Illuminate\Contracts\Database\Eloquent\Builder;
6+
use Laravel\Nova\Http\Requests\NovaRequest;
7+
use Laravel\Nova\Resource as NovaResource;
8+
use Laravel\Scout\Builder as ScoutBuilder;
9+
10+
abstract class Resource extends NovaResource
11+
{
12+
/**
13+
* Build an "index" query for the given resource.
14+
*/
15+
public static function indexQuery(NovaRequest $request, Builder $query): Builder
16+
{
17+
return $query;
18+
}
19+
20+
/**
21+
* Build a Scout search query for the given resource.
22+
*/
23+
public static function scoutQuery(NovaRequest $request, ScoutBuilder $query): ScoutBuilder
24+
{
25+
return $query;
26+
}
27+
28+
/**
29+
* Build a "detail" query for the given resource.
30+
*/
31+
public static function detailQuery(NovaRequest $request, Builder $query): Builder
32+
{
33+
return parent::detailQuery($request, $query);
34+
}
35+
36+
/**
37+
* Build a "relatable" query for the given resource.
38+
*
39+
* This query determines which instances of the model may be attached to other resources.
40+
*/
41+
public static function relatableQuery(NovaRequest $request, Builder $query): Builder
42+
{
43+
return parent::relatableQuery($request, $query);
44+
}
45+
}

workbench/app/Nova/User.php

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
3+
namespace Workbench\App\Nova;
4+
5+
use Illuminate\Http\Request;
6+
use Laravel\Nova\Auth\PasswordValidationRules;
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 SadekD\NovaOpeningHoursField\NovaOpeningHoursField;
12+
13+
class User extends Resource
14+
{
15+
use PasswordValidationRules;
16+
17+
/**
18+
* The model the resource corresponds to.
19+
*
20+
* @var class-string<\Workbench\App\Models\User>
21+
*/
22+
public static $model = \Workbench\App\Models\User::class;
23+
24+
/**
25+
* The single value that should be used to represent the resource when being displayed.
26+
*
27+
* @var string
28+
*/
29+
public static $title = 'name';
30+
31+
/**
32+
* The columns that should be searched.
33+
*
34+
* @var array
35+
*/
36+
public static $search = [
37+
'id', 'name', 'email',
38+
];
39+
40+
/**
41+
* Get the fields displayed by the resource.
42+
*
43+
* @return array<int, \Laravel\Nova\Fields\Field|\Laravel\Nova\Panel|\Laravel\Nova\ResourceTool|\Illuminate\Http\Resources\MergeValue>
44+
*/
45+
public function fields(NovaRequest $request): array
46+
{
47+
return [
48+
ID::make()->sortable(),
49+
50+
Text::make('Name')
51+
->sortable()
52+
->rules('required', 'max:255'),
53+
54+
Text::make('Email')
55+
->sortable()
56+
->rules('required', 'email', 'max:254')
57+
->creationRules('unique:users,email')
58+
->updateRules('unique:users,email,{{resourceId}}'),
59+
60+
Password::make('Password')
61+
->onlyOnForms()
62+
->creationRules($this->passwordRules())
63+
->updateRules($this->optionalPasswordRules()),
64+
65+
NovaOpeningHoursField::make(__('Opening Hours'), 'opening_hours'),
66+
];
67+
}
68+
69+
/**
70+
* Get the cards available for the request.
71+
*
72+
* @return array<int, \Laravel\Nova\Card>
73+
*/
74+
public function cards(NovaRequest $request): array
75+
{
76+
return [];
77+
}
78+
79+
/**
80+
* Get the filters available for the resource.
81+
*
82+
* @return array<int, \Laravel\Nova\Filters\Filter>
83+
*/
84+
public function filters(NovaRequest $request): array
85+
{
86+
return [];
87+
}
88+
89+
/**
90+
* Get the lenses available for the resource.
91+
*
92+
* @return array<int, \Laravel\Nova\Lenses\Lens>
93+
*/
94+
public function lenses(NovaRequest $request): array
95+
{
96+
return [];
97+
}
98+
99+
/**
100+
* Get the actions available for the resource.
101+
*
102+
* @return array<int, \Laravel\Nova\Actions\Action>
103+
*/
104+
public function actions(NovaRequest $request): array
105+
{
106+
return [];
107+
}
108+
}

0 commit comments

Comments
 (0)