From 31de047b4b0eafe4eeee6187c2b5ffd01b192fc6 Mon Sep 17 00:00:00 2001 From: val Date: Tue, 21 Jan 2025 13:58:04 +0100 Subject: [PATCH 1/2] bug(#12)!: use `helium-core` as default name for files and folders --- README.md | 70 +------------------ composer.json | 6 +- config/{helium.php => helium-core.php} | 31 +++++--- database/factories/ModelFactory.php | 19 ----- ...01_01_000000_helium_create_users_table.php | 4 +- ...01_000002_helium_create_settings_table.php | 4 +- docs/installation.md | 38 ++++++---- .../views/components/layout/auth.blade.php | 7 +- .../views/components/layout/main.blade.php | 20 +++--- .../views/components/menu/index.blade.php | 14 ++-- resources/views/livewire/user-table.blade.php | 2 +- resources/views/pages/login.blade.php | 24 +++---- resources/views/pages/setting/index.blade.php | 10 +-- resources/views/pages/user/index.blade.php | 17 +++-- routes/_helium.php | 4 +- routes/helium.php | 4 +- src/Facades/Helium.php | 2 + src/Helium.php | 13 +++- src/HeliumServiceProvider.php | 35 +++++----- src/Http/Controllers/AuthController.php | 4 +- src/Http/Controllers/SettingController.php | 2 +- src/Http/Controllers/UserController.php | 15 ++-- src/Http/Middleware/Authenticate.php | 5 +- .../Middleware/RedirectIfAuthenticated.php | 3 +- src/Livewire/UserTable.php | 2 +- src/Models/Setting.php | 2 +- src/Models/User.php | 2 +- 27 files changed, 146 insertions(+), 213 deletions(-) rename config/{helium.php => helium-core.php} (58%) delete mode 100644 database/factories/ModelFactory.php diff --git a/README.md b/README.md index 17e38ef..7ab8a43 100644 --- a/README.md +++ b/README.md @@ -9,75 +9,7 @@ Laravel Admin made with Helium UI ## Installation -You can install the package via composer: - -```bash -composer require webup/helium-core -``` - -You should publish config and components -```bash -sail artisan vendor:publish -``` - -You can publish features as you go with: - -```bash -php artisan helium:publish -``` - -Publishing a feature will copy paste every file associated with it. -This includes: -- config, controllers, models -- migrations, routes -- js, css -- x-components, livewire components, blade views - -## :warning: Configuration :warning: - -Make sure to configure this package to suit your preferences before starting to publish anything. - -## Features - -### Admin User management - -This feature packs an AdminUser model along with its migration, -a default `{email: 'admin', password: 'password'}` entry, -and CRUD routes + pages. - -```bash -php artisan helium:publish -> User -``` - -Don't forget to add the guard and provider to `config/auth.php`: -```php - [ - ... - 'admin' => [ - 'driver' => 'session', - 'provider' => 'admin_users', - ], - ], - - 'providers' => [ - ... - 'admin_users' => [ - 'driver' => 'eloquent', - 'model' => App\Models\Admin\AdminUser::class, - ], - ], -]; -``` - -### Datatable - -[doc](docs/datatable.md) - +See [installation instructions](./docs/installation.md). ## Testing ```bash diff --git a/composer.json b/composer.json index a976381..d92a40c 100644 --- a/composer.json +++ b/composer.json @@ -29,8 +29,7 @@ }, "autoload": { "psr-4": { - "Webup\\Helium\\": "src/", - "Webup\\Helium\\Database\\Factories\\": "database/factories/" + "Webup\\Helium\\": "src/" } }, "autoload-dev": { @@ -57,7 +56,8 @@ "Webup\\Helium\\HeliumServiceProvider" ], "aliases": { - "Helium": "Webup\\Helium\\Facades\\Helium" + "Helium": "Webup\\Helium\\Facades\\Helium", + "Setting": "Webup\\Helium\\Facades\\Setting" } } }, diff --git a/config/helium.php b/config/helium-core.php similarity index 58% rename from config/helium.php rename to config/helium-core.php index a0d64c9..b9454fe 100644 --- a/config/helium.php +++ b/config/helium-core.php @@ -1,16 +1,29 @@ [ + /* + |-------------------------------------------------------------------------- + | route.prefix + |-------------------------------------------------------------------------- + | + | The URL prefix for all helium routes. + | + */ + + 'prefix' => 'helium', - 'route-prefix' => 'helium', + /* + |-------------------------------------------------------------------------- + | route.as + |-------------------------------------------------------------------------- + | + | The alias for all helium routes. + | + */ + + 'as' => 'helium::', + ], /* |-------------------------------------------------------------------------- diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php deleted file mode 100644 index c3da805..0000000 --- a/database/factories/ModelFactory.php +++ /dev/null @@ -1,19 +0,0 @@ -id(); $table->timestamps(); $table->rememberToken(); @@ -21,6 +21,6 @@ public function up() public function down() { - Schema::dropIfExists(config('helium.database.users-table')); + Schema::dropIfExists(config('helium-core.database.users-table')); } }; diff --git a/database/migrations/0001_01_01_000002_helium_create_settings_table.php b/database/migrations/0001_01_01_000002_helium_create_settings_table.php index a2e4b60..68a7f77 100644 --- a/database/migrations/0001_01_01_000002_helium_create_settings_table.php +++ b/database/migrations/0001_01_01_000002_helium_create_settings_table.php @@ -8,7 +8,7 @@ { public function up() { - Schema::create(config('helium.database.settings-table'), function (Blueprint $table) { + Schema::create(config('helium-core.database.settings-table'), function (Blueprint $table) { $table->id(); $table->string('key')->unique(); $table->string('value')->nullable(); @@ -18,6 +18,6 @@ public function up() public function down() { - Schema::dropIfExists(config('helium.database.settings-table')); + Schema::dropIfExists(config('helium-core.database.settings-table')); } }; diff --git a/docs/installation.md b/docs/installation.md index 8a868b9..5a9e836 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -24,9 +24,27 @@ since it's the default for any new Laravel project.* composer require webup/helium-core # or, if you live on the edge: composer require webup/helium-core:@dev +``` + +### Publishing and customizing the default configuration + +`config/helium-core.php` is published along with all the other assets. + +You should check to see if the default values suit your requirements. +Most likely, the `user` keyword is already used as your main authentication label. + +Helium allows you to change the database table names, along with the name +of the guard and auth provider that will be automatically declared + +```sh +# publish the configuration first +artisan vendor:publish --tag=helium-core-config + +# /!\ now is the time to configure the package /!\ +nano config/helium-core.php # publish all needed files -artisan vendor:publish --tag=helium +artisan vendor:publish --tag=helium-core ``` ### Setting up the frontend assets build @@ -35,8 +53,8 @@ In order to unlock the full power of tailwind and helium's customizability, the package publishes its frontend assets to your application. The frontend assets are published to: -- `resources/js/vendor/helium/` -- `resources/css/vendor/helium/` +- `resources/js/vendor/helium-core/` +- `resources/css/vendor/helium-core/` You can now update your `vite.config.js` to build the new js/css files: ```js @@ -48,8 +66,8 @@ export default defineConfig({ 'resources/js/app.js', // add the helium assets to the build - 'resources/css/vendor/helium/app.css', - 'resources/js/vendor/helium/app.js', + 'resources/css/vendor/helium-core/app.css', + 'resources/js/vendor/helium-core/app.js', ], refresh: true, }), @@ -57,16 +75,6 @@ export default defineConfig({ }); ``` -### Checking the default configuration - -`config/helium.php` is published along with all the other assets. - -You should check to see if the default values suit your requirements. -Most likely, the `user` keyword is already used as your main authentication label. - -Helium allows you to change the database table names, along with the name -of the guard and provider that will be automatically declared. - ### Running the migrations The default helium user has the following credentials: `user@helium.dev; password`. diff --git a/resources/views/components/layout/auth.blade.php b/resources/views/components/layout/auth.blade.php index 2ad3116..fc99aa1 100644 --- a/resources/views/components/layout/auth.blade.php +++ b/resources/views/components/layout/auth.blade.php @@ -6,14 +6,13 @@ {{ $title }} - - @vite('resources/css/vendor/helium/app.css') + + @vite('resources/css/vendor/helium-core/app.css') {{ $slot }} - @vite('resources/js/vendor/helium/app.js') + @vite('resources/js/vendor/helium-core/app.js') diff --git a/resources/views/components/layout/main.blade.php b/resources/views/components/layout/main.blade.php index 7f2cdb1..6bc505f 100644 --- a/resources/views/components/layout/main.blade.php +++ b/resources/views/components/layout/main.blade.php @@ -12,13 +12,11 @@ - - + + @livewireStyles - @vite('resources/css/vendor/helium/app.css') + @vite('resources/css/vendor/helium-core/app.css') {{ $css }} {{ $cssStack }} @@ -29,11 +27,11 @@
- - + +
- +
@@ -44,14 +42,12 @@
-
+ @csrf
@livewireScripts - @vite('resources/js/vendor/helium/app.js') + @vite('resources/js/vendor/helium-core/app.js') {{ $js }} {{ $jsStack }} diff --git a/resources/views/components/menu/index.blade.php b/resources/views/components/menu/index.blade.php index 925d7da..563d877 100644 --- a/resources/views/components/menu/index.blade.php +++ b/resources/views/components/menu/index.blade.php @@ -1,15 +1,11 @@
- + Helium Users - Users - Roles + Users + Roles - + - Settings + Settings
diff --git a/resources/views/livewire/user-table.blade.php b/resources/views/livewire/user-table.blade.php index eee6de2..64563a1 100644 --- a/resources/views/livewire/user-table.blade.php +++ b/resources/views/livewire/user-table.blade.php @@ -9,7 +9,7 @@ @foreach ($this->users as $user) - + {{ $user->id }} {{ $user->name }} {{ $user->email }} diff --git a/resources/views/pages/login.blade.php b/resources/views/pages/login.blade.php index fb3e6f6..1401713 100644 --- a/resources/views/pages/login.blade.php +++ b/resources/views/pages/login.blade.php @@ -1,19 +1,11 @@ - -
+ + @csrf - - + + - - - + + + -
+ diff --git a/resources/views/pages/setting/index.blade.php b/resources/views/pages/setting/index.blade.php index 96db2d9..d65e7f2 100644 --- a/resources/views/pages/setting/index.blade.php +++ b/resources/views/pages/setting/index.blade.php @@ -1,8 +1,8 @@ - + - + - + @@ -20,5 +20,5 @@ @endforeach
-
-
+ + diff --git a/resources/views/pages/user/index.blade.php b/resources/views/pages/user/index.blade.php index 939d27e..43b3451 100644 --- a/resources/views/pages/user/index.blade.php +++ b/resources/views/pages/user/index.blade.php @@ -1,14 +1,13 @@ - + - + - + - + - - - - + + + + diff --git a/routes/_helium.php b/routes/_helium.php index 6d7fc71..7c95b16 100644 --- a/routes/_helium.php +++ b/routes/_helium.php @@ -2,8 +2,8 @@ use Illuminate\Support\Facades\Route; -Route::as('helium::') - ->prefix(config('helium.route-prefix')) +Route::as(config('helium-core.route.as')) + ->prefix(config('helium-core.route.prefix')) ->middleware('web') ->group(function () { // perf(val): this serializes correctly with `artisan route:cache` diff --git a/routes/helium.php b/routes/helium.php index a711b7e..c95522a 100644 --- a/routes/helium.php +++ b/routes/helium.php @@ -7,7 +7,7 @@ use Webup\Helium\Http\Middleware\Authenticate; use Webup\Helium\Http\Middleware\RedirectIfAuthenticated; -Route::middleware(RedirectIfAuthenticated::using(config('helium.auth.guard-name')))->group(function () { +Route::middleware(RedirectIfAuthenticated::using(config('helium-core.auth.guard-name')))->group(function () { Route::get('/login', [AuthController::class, 'showLoginForm']) ->name('login'); @@ -15,7 +15,7 @@ ->name('postLogin'); }); -Route::middleware(Authenticate::using(config('helium.auth.guard-name')))->group(function () { +Route::middleware(Authenticate::using(config('helium-core.auth.guard-name')))->group(function () { Route::post('/logout', [AuthController::class, 'logout'])->name('logout'); Route::get('/', function () { diff --git a/src/Facades/Helium.php b/src/Facades/Helium.php index 704f20a..7887660 100644 --- a/src/Facades/Helium.php +++ b/src/Facades/Helium.php @@ -11,6 +11,8 @@ * * @method static Closure getDefaultStubProcessor() * @method static ?User user() + * @method static string route(string $name, mixed $parameters = [], bool $absolute = true) + * @method static bool isRoute(string $pattern) */ class Helium extends Facade { diff --git a/src/Helium.php b/src/Helium.php index b75e6b0..e7c1dea 100755 --- a/src/Helium.php +++ b/src/Helium.php @@ -2,6 +2,7 @@ namespace Webup\Helium; +use Illuminate\Support\Facades\Route; use Webup\Helium\Models\User; class Helium @@ -9,8 +10,18 @@ class Helium public function user(): ?User { /** @var User */ - $user = auth(config('helium.auth_guard'))->user(); + $user = auth(config('helium-core.auth.guard-name'))->user(); return $user; } + + public function route(string $name, mixed $parameters = [], bool $absolute = true): string + { + return route(config('helium-core.route.as').$name, $parameters, $absolute); + } + + public function isRoute(string $pattern): bool + { + return Route::is(config('helium-core.route.as').$pattern); + } } diff --git a/src/HeliumServiceProvider.php b/src/HeliumServiceProvider.php index 4d8ba20..6dc847e 100644 --- a/src/HeliumServiceProvider.php +++ b/src/HeliumServiceProvider.php @@ -17,16 +17,20 @@ class HeliumServiceProvider extends ServiceProvider |-------------------------------------------------------------------------- */ + public const VENDOR_TAG = 'helium-core'; + + public const PACKAGE_VERSION = '0.3.0'; + public function boot() { AboutCommand::add('webup/helium', fn () => [ - 'Version' => '0.1.0', + 'Version' => self::PACKAGE_VERSION, ]); $this->bootConfig(); $this->bootMigrations(); $this->bootAssets(); - Livewire::component('helium::user-table', UserTable::class); + Livewire::component('helium-core::user-table', UserTable::class); $this->bootRoutes(); @@ -35,8 +39,6 @@ public function boot() public function register() { - $this->app->bind('helium', fn () => new Helium); - $this->app->bind('setting', fn () => new SettingManager); } /* @@ -48,49 +50,48 @@ public function register() protected function bootConfig() { $this->publishes([ - __DIR__.'/../config/helium.php' => config_path('helium.php'), - ], 'helium'); - - $this->mergeConfigFrom(__DIR__.'/../config/helium.php', 'helium'); + __DIR__.'/../config/helium-core.php' => config_path('helium-core.php'), + ], self::VENDOR_TAG.'-config'); + $this->mergeConfigFrom(__DIR__.'/../config/helium-core.php', 'helium-core'); } protected function bootMigrations() { $this->publishesMigrations([ __DIR__.'/../database/migrations' => database_path('migrations'), - ], 'helium'); + ], self::VENDOR_TAG); } protected function bootAssets() { - $this->loadViewsFrom(__DIR__.'/../resources/views', 'helium'); + $this->loadViewsFrom(__DIR__.'/../resources/views', 'helium-core'); $this->publishes([ - __DIR__.'/../resources/js' => resource_path('js/vendor/helium'), - __DIR__.'/../resources/css' => resource_path('css/vendor/helium'), - __DIR__.'/../resources/views' => resource_path('views/vendor/helium'), - ], 'helium'); + __DIR__.'/../resources/js' => resource_path('js/vendor/helium-core'), + __DIR__.'/../resources/css' => resource_path('css/vendor/helium-core'), + __DIR__.'/../resources/views' => resource_path('views/vendor/helium-core'), + ], self::VENDOR_TAG); } protected function bootRoutes() { $this->publishes([ __DIR__.'/../routes/helium.php' => base_path('routes/helium.php'), - ], 'helium'); + ], self::VENDOR_TAG); $this->loadRoutesFrom(__DIR__.'/../routes/_helium.php'); } protected function bootAuth() { - $provider = Config::get('helium.auth.provider-name'); + $provider = Config::get('helium-core.auth.provider-name'); Config::set("auth.providers.$provider", [ 'driver' => 'eloquent', 'model' => User::class, ]); - $guard = Config::get('helium.auth.guard-name'); + $guard = Config::get('helium-core.auth.guard-name'); Config::set("auth.guards.$guard", [ 'driver' => 'session', 'provider' => $provider, diff --git a/src/Http/Controllers/AuthController.php b/src/Http/Controllers/AuthController.php index 5144069..754a316 100644 --- a/src/Http/Controllers/AuthController.php +++ b/src/Http/Controllers/AuthController.php @@ -12,12 +12,12 @@ class AuthController extends Controller protected function guard() { - return Auth::guard(config('helium.auth.guard-name')); + return Auth::guard(config('helium-core.auth.guard-name')); } public function showLoginForm() { - return view('helium::pages.login'); + return view('helium-core::pages.login'); } public function redirectPath() diff --git a/src/Http/Controllers/SettingController.php b/src/Http/Controllers/SettingController.php index d406559..125a806 100644 --- a/src/Http/Controllers/SettingController.php +++ b/src/Http/Controllers/SettingController.php @@ -9,7 +9,7 @@ class SettingController extends Controller { public function index() { - return view('helium::pages.setting.index', [ + return view('helium-core::pages.setting.index', [ 'settings' => Setting::all(), ]); } diff --git a/src/Http/Controllers/UserController.php b/src/Http/Controllers/UserController.php index c6a6b8a..b0cddca 100644 --- a/src/Http/Controllers/UserController.php +++ b/src/Http/Controllers/UserController.php @@ -7,34 +7,35 @@ use Illuminate\Support\Arr; use Illuminate\Validation\Rule; use Illuminate\Validation\Rules\Password; +use Webup\Helium\Facades\Helium; use Webup\Helium\Models\User; class UserController extends Controller { public function index() { - return view('helium::pages.user.index', [ + return view('helium-core::pages.user.index', [ 'users' => User::all(), ]); } public function create() { - return view('helium::pages.user.create'); + return view('helium-core::pages.user.create'); } public function edit($id) { $user = User::findOrFail($id); - return view('helium::pages.user.edit', compact('user')); + return view('helium-core::pages.user.edit', compact('user')); } public function store(Request $request) { $data = $request->validate([ 'name' => 'required|string|max:255', - 'email' => ['required', 'email', Rule::unique(config('helium.database.users-table'), 'email')], + 'email' => ['required', 'email', Rule::unique(config('helium-core.database.users-table'), 'email')], 'password' => [ 'required', Password::min(8) @@ -47,7 +48,7 @@ public function store(Request $request) User::create($data); - return redirect()->route('helium::user.index'); + return redirect()->route('helium-core::user.index'); } public function update(Request $request, $id) @@ -73,13 +74,13 @@ public function update(Request $request, $id) $user->fill($data); $user->save(); - return redirect()->route('helium::user.show', $user->id); + return redirect()->to(Helium::route('user.show', $user->id)); } public function destroy($id) { User::findOrFail($id)->delete(); - return redirect()->route('helium::user.index'); + return redirect()->to(Helium::route('user.index')); } } diff --git a/src/Http/Middleware/Authenticate.php b/src/Http/Middleware/Authenticate.php index b246efd..da58327 100644 --- a/src/Http/Middleware/Authenticate.php +++ b/src/Http/Middleware/Authenticate.php @@ -5,13 +5,14 @@ use Exception; use Illuminate\Auth\Middleware\Authenticate as MiddlewareAuthenticate; use Illuminate\Http\Request; +use Webup\Helium\Facades\Helium; class Authenticate extends MiddlewareAuthenticate { protected function redirectTo(Request $request) { - if ($request->routeIs('helium::*')) { - return route('helium::login'); + if (Helium::isRoute('*')) { + return Helium::route('login'); } throw new Exception('Unauthenticated call.'); diff --git a/src/Http/Middleware/RedirectIfAuthenticated.php b/src/Http/Middleware/RedirectIfAuthenticated.php index 53bc360..8f04b38 100644 --- a/src/Http/Middleware/RedirectIfAuthenticated.php +++ b/src/Http/Middleware/RedirectIfAuthenticated.php @@ -4,6 +4,7 @@ use Illuminate\Auth\Middleware\RedirectIfAuthenticated as GuestMiddleware; use Illuminate\Http\Request; +use Webup\Helium\Facades\Helium; class RedirectIfAuthenticated extends GuestMiddleware { @@ -14,6 +15,6 @@ public static function using($guard, ...$others) protected function redirectTo(Request $request): ?string { - return route('helium::dashboard'); + return Helium::route('dashboard'); } } diff --git a/src/Livewire/UserTable.php b/src/Livewire/UserTable.php index 4c03daa..52ac3d4 100644 --- a/src/Livewire/UserTable.php +++ b/src/Livewire/UserTable.php @@ -17,6 +17,6 @@ public function getUsersProperty() public function render() { - return view('helium::livewire.user-table'); + return view('helium-core::livewire.user-table'); } } diff --git a/src/Models/Setting.php b/src/Models/Setting.php index edf0997..7709e82 100644 --- a/src/Models/Setting.php +++ b/src/Models/Setting.php @@ -22,6 +22,6 @@ class Setting extends Model public function __construct(array $attributes = []) { parent::__construct($attributes); - $this->setTable(config('helium.database.settings-table')); + $this->setTable(config('helium-core.database.settings-table')); } } diff --git a/src/Models/User.php b/src/Models/User.php index ec3f852..1f3af62 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -28,7 +28,7 @@ class User extends Authenticatable public function __construct(array $attributes = []) { parent::__construct($attributes); - $this->setTable(config('helium.database.users-table')); + $this->setTable(config('helium-core.database.users-table')); } public function getInitialsAttribute(): string From 0056327b746ddb7534547e1e0eea00a253902d87 Mon Sep 17 00:00:00 2001 From: vorban <16322680+vorban@users.noreply.github.com> Date: Tue, 21 Jan 2025 12:58:29 +0000 Subject: [PATCH 2/2] Fix styling --- src/HeliumServiceProvider.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/HeliumServiceProvider.php b/src/HeliumServiceProvider.php index 6dc847e..b43e24d 100644 --- a/src/HeliumServiceProvider.php +++ b/src/HeliumServiceProvider.php @@ -37,9 +37,7 @@ public function boot() $this->bootAuth(); } - public function register() - { - } + public function register() {} /* |--------------------------------------------------------------------------