├── .gitignore
├── .github
├── FUNDING.yml
└── stale.yml
├── resources
└── images
│ └── avatar.png
├── src
├── Traits
│ ├── CreatedByAdminUserTrait.php
│ ├── UpdatedByAdminUserTrait.php
│ └── PublishableTrait.php
├── Console
│ └── Commands
│ │ ├── CraftableTestDBConnection.php
│ │ ├── CraftableInitializeEnv.php
│ │ └── CraftableInstall.php
└── CraftableServiceProvider.php
├── LICENSE
├── CONTRIBUTING.md
├── composer.json
├── CODE_OF_CONDUCT.md
├── README.md
└── install-stubs
└── database
└── migrations
└── fill_default_admin_user_and_permissions.php
/.gitignore:
--------------------------------------------------------------------------------
1 | /vendor
2 | composer.lock
3 | .idea/
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: [BRACKETS-by-TRIAD]
4 |
--------------------------------------------------------------------------------
/resources/images/avatar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BRACKETS-by-TRIAD/craftable/HEAD/resources/images/avatar.png
--------------------------------------------------------------------------------
/src/Traits/CreatedByAdminUserTrait.php:
--------------------------------------------------------------------------------
1 | belongsTo(AdminUser::class, 'created_by_admin_user_id');
16 | }
17 | }
--------------------------------------------------------------------------------
/src/Traits/UpdatedByAdminUserTrait.php:
--------------------------------------------------------------------------------
1 | belongsTo(AdminUser::class, 'updated_by_admin_user_id');
16 | }
17 | }
--------------------------------------------------------------------------------
/.github/stale.yml:
--------------------------------------------------------------------------------
1 | # Number of days of inactivity before an issue becomes stale
2 | daysUntilStale: 90
3 | # Number of days of inactivity before a stale issue is closed
4 | daysUntilClose: 30
5 | # Issues with these labels will never be considered stale
6 | exemptLabels:
7 | - pinned
8 | - enhancement
9 | - security
10 | - bug
11 | # Label to use when marking an issue as stale
12 | staleLabel: stale
13 | # Comment to post when marking an issue as stale. Set to `false` to disable
14 | markComment: >
15 | This issue has been automatically marked as stale because it has not had
16 | recent activity. It will be closed if no further activity occurs. Thank you
17 | for your contributions.
18 | # Comment to post when closing a stale issue. Set to `false` to disable
19 | closeComment: false
20 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 BRACKETS by TRIAD s.r.o.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/Console/Commands/CraftableTestDBConnection.php:
--------------------------------------------------------------------------------
1 | info('Testing the database connection...');
32 |
33 | try {
34 | DB::connection()->getPdo();
35 | } catch (\Exception $e) {
36 | $this->error("Could not connect to the database. Please check your configuration. Error: " . $e->getMessage());
37 | return 1;
38 | }
39 |
40 | $this->info('...connection OK');
41 | return 0;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/CraftableServiceProvider.php:
--------------------------------------------------------------------------------
1 | commands([
20 | CraftableInitializeEnv::class,
21 | CraftableInstall::class,
22 | CraftableTestDBConnection::class,
23 | ]);
24 |
25 | if ($this->app->runningInConsole()) {
26 | if (!class_exists('FillDefaultAdminUserAndPermissions')) {
27 | $timestamp = date('Y_m_d_His', time() + 5);
28 |
29 | $this->publishes([
30 | __DIR__ . '/../install-stubs/database/migrations/fill_default_admin_user_and_permissions.php' => database_path('migrations') . '/' . $timestamp . '_fill_default_admin_user_and_permissions.php',
31 | ], 'migrations');
32 | }
33 |
34 | if (!file_exists(storage_path() . '/images/avatar.png')) {
35 | $this->publishes([
36 | __DIR__ . '/../resources/images/avatar.png' => storage_path() . '/images/avatar.png',
37 | ], 'images');
38 | }
39 | }
40 | }
41 |
42 | /**
43 | * Register any application services.
44 | *
45 | * @return void
46 | */
47 | public function register()
48 | {
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to contribute
2 |
3 | Craftable consits of many packages, each of them having its own repository. You can take a closer look into each of them bellow:
4 | - [Admin UI](https://github.com/BRACKETS-by-TRIAD/admin-ui) - admin template (CoreUI assets, blades, Vue)
5 | - [Admin Generator](https://github.com/BRACKETS-by-TRIAD/admin-generator) - CRUD generator for Eloquent models
6 | - [Admin Auth](https://github.com/BRACKETS-by-TRIAD/admin-auth) - ability to authenticate into Admin area
7 | - [Translatable](https://github.com/BRACKETS-by-TRIAD/translatable) - ability to have translatable content (extending Laravel's default Localization)
8 | - [Admin Listing](https://github.com/BRACKETS-by-TRIAD/admin-listing) - ability to quickly build a query for administration listing for your Eloquent models
9 | - [Media Library](https://github.com/BRACKETS-by-TRIAD/media) - ability to attach media to eloquent models
10 | - [Admin Translations](https://github.com/BRACKETS-by-TRIAD/admin-translations) - translation manager (with UI)
11 |
12 | ## Issues
13 |
14 | Mostly all of the issues are centralized in this repository.
15 | There are always some long running [issues](https://github.com/BRACKETS-by-TRIAD/craftable/issues) with bugs or some enchancements. If issue doesn't have a linked repository, feel free to ask for help! If there is nothing interesting for you, feel free to create a new issue.
16 |
17 | During [Hacktoberfest](https://hacktoberfest.com/), there are also curated issues easy to take on marked as `hacktoberfest`.
18 |
19 | ## Workflow
20 |
21 | 1. Fork the selected repository you want to contribute to
22 | 2. Preferably create a new branch
23 | 3. Make your changes
24 | 4. Submit pull request
25 | 5. Wait for our review
26 | 6. ???
27 | 7. Profit!
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "brackets/craftable",
3 | "description": "Administration toolkit for Laravel 8 - starting point for developing administration interface",
4 | "keywords": [
5 | "craftable",
6 | "crud",
7 | "brackets",
8 | "admin",
9 | "administration",
10 | "toolkit",
11 | "framework",
12 | "cms",
13 | "laravel"
14 | ],
15 | "abandoned": "Craftable PRO (get at www.craftable.pro)",
16 | "license": "MIT",
17 | "type": "project",
18 | "authors": [
19 | {
20 | "name": "Pavol Perdík",
21 | "email": "pavol.perdik@brackets.sk",
22 | "homepage": "https://www.brackets.sk",
23 | "role": "Developer"
24 | },
25 | {
26 | "name": "David Běhal",
27 | "email": "david.behal@brackets.sk",
28 | "homepage": "https://www.brackets.sk",
29 | "role": "Developer"
30 | },
31 | {
32 | "name": "Richard Dominik",
33 | "email": "richard.dominik@brackets.sk",
34 | "homepage": "https://www.brackets.sk",
35 | "role": "Developer"
36 | }
37 | ],
38 | "require": {
39 | "php": "^8.0.2",
40 | "brackets/admin-auth": "^7.0",
41 | "brackets/admin-listing": "^3.0",
42 | "brackets/admin-translations": "^4.0",
43 | "brackets/admin-ui": "^4.0",
44 | "brackets/advanced-logger": "^3.0",
45 | "brackets/media": "^7.0",
46 | "brackets/translatable": "^2.0",
47 | "illuminate/support": "^9.0|^10.0",
48 | "laravel/legacy-factories": "^1.1",
49 | "spatie/laravel-permission": "^3.0|^4.0|^5.0",
50 | "spatie/laravel-backup": "^6.0|^7.0|^8.0",
51 | "maatwebsite/excel": "^3.1"
52 | },
53 | "autoload": {
54 | "classmap": [],
55 | "psr-4": {
56 | "Brackets\\Craftable\\": "src/"
57 | }
58 | },
59 | "extra": {
60 | "laravel": {
61 | "providers": [
62 | "Brackets\\Craftable\\CraftableServiceProvider"
63 | ]
64 | },
65 | "branch-alias": {
66 | "dev-master": "8.1-dev"
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/Traits/PublishableTrait.php:
--------------------------------------------------------------------------------
1 | dates, true);
16 | }
17 |
18 | /**
19 | * Scope a query to only include published models.
20 | *
21 | * @param Builder $query
22 | * @return Builder
23 | */
24 | public function scopePublished(Builder $query): Builder
25 | {
26 | return $query
27 | ->where('published_at', '<=', Carbon::now())
28 | ->whereNotNull('published_at')
29 | ->when($this->hasPublishedTo(), static function ($query) {
30 | return $query->where(static function ($query2) {
31 | $query2->where('published_to', '>=', Carbon::now())
32 | ->orWhereNull('published_to');
33 | });
34 | });
35 | }
36 |
37 | /**
38 | * Scope a query to only include unpublished models.
39 | *
40 | * @param Builder $query
41 | * @return Builder
42 | */
43 | public function scopeUnpublished(Builder $query): Builder
44 | {
45 | return $query->where('published_at', '>', Carbon::now())->orWhereNull('published_at')
46 | ->when($this->hasPublishedTo(), static function ($query) {
47 | $query->orWhere('published_to', '<', Carbon::now());
48 | });
49 | }
50 |
51 | /**
52 | * @return bool
53 | */
54 | public function isPublished(): bool
55 | {
56 | if ($this->published_at === null) {
57 | return false;
58 | }
59 |
60 | return $this->published_at->lte(Carbon::now()) && ($this->hasPublishedTo() ? ($this->published_to->gte(Carbon::now()) || $this->published_to === null) : true);
61 | }
62 |
63 | /**
64 | * @return bool
65 | */
66 | public function isUnpublished(): bool
67 | {
68 | return !$this->isPublished();
69 | }
70 |
71 | /**
72 | * @return bool
73 | */
74 | public function publish(): bool
75 | {
76 | $data = ['published_at' => Carbon::now()->toDateTimeString()];
77 |
78 | if ($this->hasPublishedTo() && $this->published_to->lte(Carbon::now())) {
79 | $data['published_to'] = null;
80 | }
81 |
82 | return $this->update($data);
83 | }
84 |
85 | /**
86 | * @return bool
87 | */
88 | public function unpublish(): bool
89 | {
90 | return $this->update([
91 | 'published_at' => null,
92 | ]);
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/src/Console/Commands/CraftableInitializeEnv.php:
--------------------------------------------------------------------------------
1 | info('Initializing database environment variables...');
32 |
33 | $this->getDbSettings();
34 |
35 | $this->info('Database environment variables initialized.');
36 |
37 | $this->setApplicationName();
38 | }
39 |
40 | /**
41 | * Update .env setting
42 | *
43 | * @param string $key
44 | * @param string $value
45 | * @param string $fileName
46 | * @return int|bool
47 | */
48 | private function updateEnv($key, $value, $fileName = '.env')
49 | {
50 | $fileName = base_path($fileName);
51 | $content = File::get($fileName);
52 | return File::put($fileName, preg_replace('/' . $key . '=.*/', $key . '=' . $value, $content));
53 | }
54 |
55 | /**
56 | * If default database values in .env are present and interaction mode is on,
57 | * asks for database settings. Values not provided will not be overwritten.
58 | *
59 | * @return void
60 | */
61 | private function getDbSettings(): void
62 | {
63 | if ($this->isDefaultDatabaseEnv() && $this->input->isInteractive()) {
64 | $dbConnection = $this->choice('What database driver do you use?', ['mysql', 'pgsql'], 0);
65 | if (!empty($dbConnection)) {
66 | $this->updateEnv('DB_CONNECTION', $dbConnection);
67 | }
68 |
69 | $dbHost = $this->anticipate('What is your database host?', ['localhost', '127.0.0.1'], '127.0.0.1');
70 | if (!empty($dbHost)) {
71 | $this->updateEnv('DB_HOST', $dbHost);
72 | }
73 |
74 | $dbPort = $this->anticipate(
75 | 'What is your database port?',
76 | ['3306', '5432'],
77 | env('DB_CONNECTION') === 'mysql' ? '3306' : '5432'
78 | );
79 | if (!empty($dbPort)) {
80 | $this->updateEnv('DB_PORT', $dbPort);
81 | }
82 |
83 | $dbDatabase = $this->anticipate('What is your database name?',
84 | ['laravel', 'homestead'],
85 | 'laravel'
86 | );
87 | if (!empty($dbDatabase)) {
88 | $this->updateEnv('DB_DATABASE', $dbDatabase);
89 | }
90 |
91 | $dbUsername = $this->anticipate('What is your database user name?',
92 | ['root', 'homestead'],
93 | 'root'
94 | );
95 | if (!empty($dbUsername)) {
96 | $this->updateEnv('DB_USERNAME', $dbUsername);
97 | }
98 |
99 | $dbPassword = $this->secret('What is your database user password?', 'secret');
100 | if (!empty($dbPassword)) {
101 | $this->updateEnv('DB_PASSWORD', $dbPassword);
102 | }
103 | }
104 | }
105 |
106 | /**
107 | * Change default application name from Laravel to Craftable
108 | *
109 | * @return void
110 | */
111 | private function setApplicationName(): void
112 | {
113 | if (env('APP_NAME') === 'Laravel') {
114 | $this->updateEnv('APP_NAME', 'Craftable');
115 | $this->updateEnv('APP_NAME', 'Craftable', '.env.example');
116 | }
117 | }
118 |
119 | /**
120 | * Determines if the .env file has default database settings
121 | *
122 | * @return boolean
123 | */
124 | private function isDefaultDatabaseEnv(): bool
125 | {
126 | if (
127 | version_compare(app()::VERSION, '5.8.35', '<') &&
128 | (env('DB_DATABASE') === 'homestead' &&
129 | env('DB_USERNAME') === 'homestead') ||
130 | version_compare(app()::VERSION, '5.8.35', '>=') &&
131 | (env('DB_DATABASE') === 'laravel' &&
132 | env('DB_USERNAME') === 'root')
133 | ) {
134 | return true;
135 | }
136 |
137 | return false;
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | We as members, contributors, and leaders pledge to make participation in our
6 | community a harassment-free experience for everyone, regardless of age, body
7 | size, visible or invisible disability, ethnicity, sex characteristics, gender
8 | identity and expression, level of experience, education, socio-economic status,
9 | nationality, personal appearance, race, religion, or sexual identity
10 | and orientation.
11 |
12 | We pledge to act and interact in ways that contribute to an open, welcoming,
13 | diverse, inclusive, and healthy community.
14 |
15 | ## Our Standards
16 |
17 | Examples of behavior that contributes to a positive environment for our
18 | community include:
19 |
20 | * Demonstrating empathy and kindness toward other people
21 | * Being respectful of differing opinions, viewpoints, and experiences
22 | * Giving and gracefully accepting constructive feedback
23 | * Accepting responsibility and apologizing to those affected by our mistakes,
24 | and learning from the experience
25 | * Focusing on what is best not just for us as individuals, but for the
26 | overall community
27 |
28 | Examples of unacceptable behavior include:
29 |
30 | * The use of sexualized language or imagery, and sexual attention or
31 | advances of any kind
32 | * Trolling, insulting or derogatory comments, and personal or political attacks
33 | * Public or private harassment
34 | * Publishing others' private information, such as a physical or email
35 | address, without their explicit permission
36 | * Other conduct which could reasonably be considered inappropriate in a
37 | professional setting
38 |
39 | ## Enforcement Responsibilities
40 |
41 | Community leaders are responsible for clarifying and enforcing our standards of
42 | acceptable behavior and will take appropriate and fair corrective action in
43 | response to any behavior that they deem inappropriate, threatening, offensive,
44 | or harmful.
45 |
46 | Community leaders have the right and responsibility to remove, edit, or reject
47 | comments, commits, code, wiki edits, issues, and other contributions that are
48 | not aligned to this Code of Conduct, and will communicate reasons for moderation
49 | decisions when appropriate.
50 |
51 | ## Scope
52 |
53 | This Code of Conduct applies within all community spaces, and also applies when
54 | an individual is officially representing the community in public spaces.
55 | Examples of representing our community include using an official e-mail address,
56 | posting via an official social media account, or acting as an appointed
57 | representative at an online or offline event.
58 |
59 | ## Enforcement
60 |
61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
62 | reported to the community leaders responsible for enforcement at
63 | .
64 | All complaints will be reviewed and investigated promptly and fairly.
65 |
66 | All community leaders are obligated to respect the privacy and security of the
67 | reporter of any incident.
68 |
69 | ## Enforcement Guidelines
70 |
71 | Community leaders will follow these Community Impact Guidelines in determining
72 | the consequences for any action they deem in violation of this Code of Conduct:
73 |
74 | ### 1. Correction
75 |
76 | **Community Impact**: Use of inappropriate language or other behavior deemed
77 | unprofessional or unwelcome in the community.
78 |
79 | **Consequence**: A private, written warning from community leaders, providing
80 | clarity around the nature of the violation and an explanation of why the
81 | behavior was inappropriate. A public apology may be requested.
82 |
83 | ### 2. Warning
84 |
85 | **Community Impact**: A violation through a single incident or series
86 | of actions.
87 |
88 | **Consequence**: A warning with consequences for continued behavior. No
89 | interaction with the people involved, including unsolicited interaction with
90 | those enforcing the Code of Conduct, for a specified period of time. This
91 | includes avoiding interactions in community spaces as well as external channels
92 | like social media. Violating these terms may lead to a temporary or
93 | permanent ban.
94 |
95 | ### 3. Temporary Ban
96 |
97 | **Community Impact**: A serious violation of community standards, including
98 | sustained inappropriate behavior.
99 |
100 | **Consequence**: A temporary ban from any sort of interaction or public
101 | communication with the community for a specified period of time. No public or
102 | private interaction with the people involved, including unsolicited interaction
103 | with those enforcing the Code of Conduct, is allowed during this period.
104 | Violating these terms may lead to a permanent ban.
105 |
106 | ### 4. Permanent Ban
107 |
108 | **Community Impact**: Demonstrating a pattern of violation of community
109 | standards, including sustained inappropriate behavior, harassment of an
110 | individual, or aggression toward or disparagement of classes of individuals.
111 |
112 | **Consequence**: A permanent ban from any sort of public interaction within
113 | the community.
114 |
115 | ## Attribution
116 |
117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118 | version 2.0, available at
119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120 |
121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct
122 | enforcement ladder](https://github.com/mozilla/diversity).
123 |
124 | [homepage]: https://www.contributor-covenant.org
125 |
126 | For answers to common questions about this code of conduct, see the FAQ at
127 | https://www.contributor-covenant.org/faq. Translations are available at
128 | https://www.contributor-covenant.org/translations.
129 |
--------------------------------------------------------------------------------
/src/Console/Commands/CraftableInstall.php:
--------------------------------------------------------------------------------
1 | info('Installing Craftable...');
42 |
43 | $this->publishAllVendors();
44 |
45 | $this->addHashToLogging();
46 |
47 | $this->call('admin-ui:install');
48 |
49 | $this->call('admin-auth:install', ['--dont-install-admin-ui' => true]);
50 |
51 | $this->generateUserStuff($files);
52 |
53 | $this->call('admin-translations:install', ['--dont-install-admin-ui' => true]);
54 |
55 | $this->scanAndSaveTranslations();
56 |
57 | $this->call('admin-listing:install');
58 |
59 | if ($this->password) {
60 | $this->comment('Admin password is: ' . $this->password);
61 | }
62 |
63 | $this->info('Craftable installed.');
64 | }
65 |
66 | /**
67 | * Replace string in file
68 | *
69 | * @param string $fileName
70 | * @param string $find
71 | * @param string $replaceWith
72 | * @return int|bool
73 | */
74 | private function strReplaceInFile($fileName, $find, $replaceWith)
75 | {
76 | $content = File::get($fileName);
77 | return File::put($fileName, str_replace($find, $replaceWith, $content));
78 | }
79 |
80 | /**
81 | * Publishing all publishable files from all craftable packages
82 | *
83 | * @return void
84 | */
85 | private function publishAllVendors(): void
86 | {
87 | //Spatie Permission
88 | $this->call('vendor:publish', [
89 | '--provider' => 'Spatie\\Permission\\PermissionServiceProvider',
90 | '--tag' => 'permission-migrations'
91 | ]);
92 | $this->call('vendor:publish', [
93 | '--provider' => 'Spatie\\Permission\\PermissionServiceProvider',
94 | '--tag' => 'config'
95 | ]);
96 |
97 | //Spatie Backup
98 | $this->call('vendor:publish', [
99 | '--provider' => "Spatie\\Backup\\BackupServiceProvider",
100 | ]);
101 |
102 | $this->publishSpatieMediaLibrary();
103 |
104 | $this->call('vendor:publish', [
105 | '--provider' => "Brackets\\Media\\MediaServiceProvider",
106 | ]);
107 |
108 | //Advanced logger
109 | $this->call('vendor:publish', [
110 | '--provider' => "Brackets\\AdvancedLogger\\AdvancedLoggerServiceProvider",
111 | ]);
112 |
113 | $this->publishCraftable();
114 | }
115 |
116 | private function publishCraftable()
117 | {
118 | $alreadyMigrated = false;
119 | $files = File::allFiles(database_path('migrations'));
120 | foreach ($files as $file) {
121 | if (strpos($file->getFilename(), 'fill_default_admin_user_and_permissions.php') !== false) {
122 | $alreadyMigrated = true;
123 | break;
124 | }
125 | }
126 | if (!$alreadyMigrated) {
127 | $this->call('vendor:publish', [
128 | '--provider' => "Brackets\\Craftable\\CraftableServiceProvider",
129 | ]);
130 |
131 | $this->generatePasswordAndUpdateMigration();
132 | }
133 | }
134 |
135 | private function publishSpatieMediaLibrary()
136 | {
137 | $alreadyMigrated = false;
138 | $files = File::allFiles(database_path('migrations'));
139 | foreach ($files as $file) {
140 | if (strpos($file->getFilename(), 'create_media_table.php') !== false) {
141 | $alreadyMigrated = true;
142 | break;
143 | }
144 | }
145 | if (!$alreadyMigrated) {
146 | $this->call('vendor:publish', [
147 | '--provider' => 'Spatie\\MediaLibrary\\MediaLibraryServiceProvider',
148 | '--tag' => 'migrations'
149 | ]);
150 | }
151 | }
152 |
153 | /**
154 | * Generate new password and change default password in igration to use new password
155 | *
156 | * @return void
157 | */
158 | private function generatePasswordAndUpdateMigration(): void
159 | {
160 | $this->password = Str::random(10);
161 |
162 | $files = File::allFiles(database_path('migrations'));
163 | foreach ($files as $file) {
164 | if (strpos($file->getFilename(), 'fill_default_admin_user_and_permissions.php') !== false) {
165 | //change database/migrations/*fill_default_user_and_permissions.php to use new password
166 | $this->strReplaceInFile(
167 | database_path('migrations/' . $file->getFilename()),
168 | 'best package ever',
169 | '' . $this->password . '');
170 | break;
171 | }
172 | }
173 | }
174 |
175 | /**
176 | * Generate user administration and profile
177 | *
178 | * @param Filesystem $files
179 | * @return void
180 | */
181 | private function generateUserStuff(Filesystem $files): void
182 | {
183 | // TODO this is probably redundant?
184 | // Migrate
185 | $this->call('migrate');
186 |
187 | // Generate User CRUD (with new model)
188 | $this->call('admin:generate:admin-user', [
189 | '--force' => true,
190 | ]);
191 |
192 | // Generate user profile
193 | $this->call('admin:generate:admin-user:profile');
194 | }
195 |
196 | /**
197 | * Prepare translations config and rescan
198 | *
199 | * @return void
200 | */
201 | private function scanAndSaveTranslations(): void
202 | {
203 | // Scan translations
204 | $this->info('Scanning codebase and storing all translations');
205 |
206 | $this->strReplaceInFile(
207 | config_path('admin-translations.php'),
208 | '// here you can add your own directories',
209 | '// here you can add your own directories
210 | // base_path(\'routes\'), // uncomment if you have translations in your routes i.e. you have localized URLs
211 | base_path(\'vendor/brackets/admin-auth/src\'),
212 | base_path(\'vendor/brackets/admin-auth/resources\'),
213 | base_path(\'vendor/brackets/admin-ui/resources\'),
214 | base_path(\'vendor/brackets/admin-translations/resources\'),'
215 | );
216 |
217 | $this->call('admin-translations:scan-and-save', [
218 | 'paths' => array_merge(
219 | config('admin-translations.scanned_directories'),
220 | ['vendor/brackets/admin-auth/src', 'vendor/brackets/admin-auth/resources']
221 | ),
222 | ]);
223 | }
224 |
225 | /**
226 | * Change logging to add hash to logs
227 | *
228 | * @return void
229 | */
230 | private function addHashToLogging(): void
231 | {
232 | if (version_compare(app()->version(), '5.6.0', '>=')) {
233 | $this->strReplaceInFile(
234 | config_path('logging.php'),
235 | '\'days\' => 14,',
236 | '\'days\' => 90,
237 | \'tap\' => [Brackets\AdvancedLogger\LogCustomizers\HashLogCustomizer::class],'
238 | );
239 | }
240 | }
241 | }
242 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 🔥 BIG NEWS 🔥
2 |
3 | We have just released [Craftable PRO](https://craftable.pro) - the premium version of this popular open-source laravel admin panel builder. Pro version comes with fresh UI built on top of Tailwind, it uses latest Laravel and InertiaJS and ships with lot of [new features](https://craftable.pro/#features).
4 |
5 | ---
6 |
7 | # Craftable - build admin panels with Laravel #
8 |
9 | - [About](#about)
10 | - [Demo](#demo)
11 | - [Packages used](#made-of-components)
12 | - [Requirements](#requirements)
13 | - [Installation](#installation)
14 | - [New project](#new-craftable-project)
15 | - [Add to existing project](#add-craftable-to-existing-project)
16 | - [Basics](#basics)
17 | - [Documentation](#documentation)
18 | - [Where to go next?](#where-to-go-next)
19 |
20 | ## About ##
21 |
22 | Hi Crafter, welcome to the official documentation for Craftable 6 - a Laravel-based open-source toolkit for building administration interfaces. It's an administration area minimalistic template. A starting point for developing back-office systems, intranets or a CMS systems.
23 |
24 | 
25 |
26 | You could call it CMS, but it's a very slim one, with as little content to manage as possible. It has:
27 | - UI - nice admin template based on CoreUI (http://coreui.io/)
28 | - CRUD generator
29 | - Authorization, My profile & Users CRUD
30 | - Translations manager
31 | - other helpers to quickly bootstrap your new administration area (Media Library, Admin Listing, etc.)
32 |
33 | ### Demo ###
34 |
35 | We have created a demo for you to play around at https://demo.getcraftable.com.
36 |
37 | Use these credentials to sign-in:
38 | - email: `demo@getcraftable.com`
39 | - password: `demo123`
40 |
41 | You can see an administration of:
42 | - [Posts](https://demo.getcraftable.com/admin/posts) - this is the standard CRUD generated with `admin-generator` package
43 | - [Translatable Articles](https://demo.getcraftable.com/admin/translatable-articles) - this is the showcase for `translatable`eloquent models
44 | - [Manage access](https://demo.getcraftable.com/admin/users) - is a extended CRUD for the User (your existing eloquent model) management
45 | - [Translations](https://demo.getcraftable.com/admin/translations) - where you can manage the translations stored in the database
46 |
47 | ### Made of components ###
48 |
49 | Our intent was to split all the stuff into several packages with as least dependencies as possible. This is what we're coming with at the moment:
50 | - [Admin UI](https://getcraftable.com/docs/5.0/user-interface) - admin template (CoreUI assets, blades, Vue)
51 | - [Admin Generator](https://getcraftable.com/docs/5.0/explore-generator) - CRUD generator for Eloquent models
52 | - [Admin Authentication](https://getcraftable.com/docs/5.0/auth) - ability to authenticate into Admin area
53 | - [Translatable](https://getcraftable.com/docs/5.0/translatable) - ability to have translatable content (extending Laravel's default Localization)
54 | - [Admin Listing](https://getcraftable.com/docs/5.0/listing) - ability to quickly build a query for administration listing for your Eloquent models
55 | - [Media Library](https://getcraftable.com/docs/5.0/media) - ability to attach media to eloquent models
56 | - [Admin Translations](https://getcraftable.com/docs/5.0/translations) - translation manager (with UI)
57 |
58 | Craftable uses all the packages above. It also uses some other 3rd party packages (like Spatie's `spatie/laravel-permission`) and provides some basic default configuration to speed up a development of a typical administration interface.
59 |
60 | ## Requirements ##
61 |
62 | Craftable requires:
63 | - PHP 7.4+
64 | - Supported databases:
65 | - MySQL 5.7+
66 | - PostgreSQL 9.5+
67 | - npm 5.3+
68 | - node 8.4+
69 |
70 | Craftable uses Laravel so you should check out its requirements too. It is compatible with Laravel 8:
71 | - https://laravel.com/docs/8.x/installation#server-requirements
72 |
73 | ## Installation ##
74 |
75 | ### New Craftable project ###
76 |
77 | If you want to start on fresh Laravel, you can use our `brackets/craftable-installer` that do all the tricks for you. Let's install it globally:
78 | ```bash
79 | composer global require "brackets/craftable-installer"
80 | ```
81 |
82 | Create an empty database of your choice (PostgreSQL or MySQL).
83 |
84 | Now you can create a new Craftable project:
85 | ```bash
86 | craftable new my_project
87 | ```
88 |
89 | This will install Craftable using latest Laravel version (currently 6). If you prefer tu use latest LTS Laravel version (currently also 6), use `--lts` flag:
90 | ```bash
91 | craftable new --lts my_project
92 | ```
93 |
94 | The commands is going to ask for a database settings and then it will setup everything (install all dependencies, publish all important vendor configs, migrate, setup some configs, webpack config and run migrations).
95 |
96 |
97 | Command is going to generate and **print the password for the default administrator** account. Save this password to your clipboard, we are going to need it soon.
98 |
99 | ### Add Craftable to existing project ###
100 |
101 | Or alternatively, you can use your existing Laravel application. Start with requiring these two main packages:
102 |
103 | ```bash
104 | composer require brackets/craftable
105 | composer require --dev brackets/admin-generator
106 | ```
107 |
108 | To install this package use:
109 | ```bash
110 | php artisan craftable:install
111 | ```
112 |
113 | This is going to install all dependencies, publish all important vendor configs, migrate, setup some configs, webpack config and run migrations.
114 |
115 | Command is going to generate and **print the password for the default administrator** account. Save this password to your clipboard, we are going to need it soon.
116 |
117 | ## Basics ##
118 |
119 | Once installed, navigate your browser to `/admin/login`. You should be able to see a login screen.
120 |
121 | 
122 |
123 | Use these credentials to log in:
124 | - E-mail: `administrator@brackets.sk`
125 | - Password: use password from you clipboard (it was printed in the end of the `craftable:install` command)
126 |
127 | After authorization you should be able to see a default homepage and two menu items:
128 | - Manage access
129 | - Translations
130 |
131 | 
132 |
133 | ## Documentation ##
134 |
135 | You can find full documentation of this package and other our packages Craftable uses at https://docs.getcraftable.com/#/craftable.
136 |
137 | ## Where to go next? ##
138 |
139 | At this point you are ready to start building your administration area. You probably want to start building a typical CRUD interface for your eloquent models. You should definitely check our [Admin Generator](https://getcraftable.com/docs/5.0/explore-generator) documentation.
140 |
141 | In case you rather want to create some atypical custom made administration, then you probably want to head over to [Admin UI](https://getcraftable.com/docs/5.0/user-interface) package.
142 |
143 | Have fun & craft something awesome!
144 |
145 | ## How to contribute:
146 |
147 | - Drop a :star: on the Github repository (optional)
148 |
149 | - Before Contribute Please read [CONTRIBUTING.md](https://github.com/BRACKETS-by-TRIAD/craftable/blob/master/CONTRIBUTING.md) and [CODE_OF_CONDUCT.md](https://github.com/BRACKETS-by-TRIAD/craftable/blob/master/CODE_OF_CONDUCT.md).
150 |
151 | - Create an issue of the project or a feature you would like to add in the project and get the task assigned for youself.(Issue can be any bug fixes or any feature you want to add in this project).
152 |
153 | - Fork the repo to your Github.
154 |
155 | - Clone the Repo by going to your local Git Client in a particular local folder in your local machine by using this command with your forked repository link in place of below given link:
156 | `git clone https://github.com/BRACKETS-by-TRIAD/craftable`
157 | - Create a branch using below command.
158 | `git branch `
159 | - Checkout to your branch.
160 | `git checkout `
161 | - Add your code in your local machine folder.
162 | `git add . `
163 | - Commit your changes.
164 | `git commit -m""`
165 | - Push your changes.
166 | `git push --set-upstream origin `
167 |
168 | - Make a pull request! (compare your branch with the owner main branch)
169 |
170 | ## Contributors🌟
171 |
172 |
173 | Kudos to these amazing people
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 | ## Licence
183 | MIT Licence. Refer to the [LICENSE](https://github.com/BRACKETS-by-TRIAD/craftable/blob/master/LICENSE) file to get more info.
184 |
--------------------------------------------------------------------------------
/install-stubs/database/migrations/fill_default_admin_user_and_permissions.php:
--------------------------------------------------------------------------------
1 | guardName = config('admin-auth.defaults.guard');
52 | $providerName = config('auth.guards.' . $this->guardName . '.provider');
53 | $provider = config('auth.providers.' . $providerName);
54 | if ($provider['driver'] === 'eloquent') {
55 | $this->userClassName = $provider['model'];
56 | }
57 | $this->userTable = (new $this->userClassName)->getTable();
58 |
59 | $defaultPermissions = collect([
60 | // view admin as a whole
61 | 'admin',
62 |
63 | // manage translations
64 | 'admin.translation.index',
65 | 'admin.translation.edit',
66 | 'admin.translation.rescan',
67 |
68 | // manage users (access)
69 | 'admin.admin-user.index',
70 | 'admin.admin-user.create',
71 | 'admin.admin-user.edit',
72 | 'admin.admin-user.delete',
73 |
74 | // ability to upload
75 | 'admin.upload',
76 |
77 | //ability to impersonal login
78 | 'admin.admin-user.impersonal-login'
79 | ]);
80 |
81 | //Add new permissions
82 | $this->permissions = $defaultPermissions->map(function ($permission) {
83 | return [
84 | 'name' => $permission,
85 | 'guard_name' => $this->guardName,
86 | 'created_at' => Carbon::now(),
87 | 'updated_at' => Carbon::now(),
88 | ];
89 | })->toArray();
90 |
91 | //Add new roles
92 | $this->roles = [
93 | [
94 | 'name' => 'Administrator',
95 | 'guard_name' => $this->guardName,
96 | 'created_at' => Carbon::now(),
97 | 'updated_at' => Carbon::now(),
98 | 'permissions' => $defaultPermissions->reject(function ($permission) {
99 | return $permission === 'admin.admin-user.impersonal-login';
100 | }),
101 | ],
102 | ];
103 |
104 | //Add new users
105 | $this->users = [
106 | [
107 | 'first_name' => 'Administrator',
108 | 'last_name' => 'Administrator',
109 | 'email' => 'administrator@brackets.sk',
110 | 'password' => Hash::make($this->password),
111 | 'remember_token' => null,
112 | 'created_at' => Carbon::now(),
113 | 'updated_at' => Carbon::now(),
114 | 'activated' => true,
115 | 'roles' => [
116 | [
117 | 'name' => 'Administrator',
118 | 'guard_name' => $this->guardName,
119 | ],
120 | ],
121 | 'permissions' => [
122 | //
123 | ],
124 | ],
125 | ];
126 | }
127 |
128 | /**
129 | * Run the migrations.
130 | *
131 | * @throws Exception
132 | * @return void
133 | */
134 | public function up(): void
135 | {
136 | if ($this->userClassName === null) {
137 | throw new RuntimeException('Admin user model not defined');
138 | }
139 | DB::transaction(function () {
140 | foreach ($this->permissions as $permission) {
141 | $permissionItem = DB::table('permissions')->where([
142 | 'name' => $permission['name'],
143 | 'guard_name' => $permission['guard_name']
144 | ])->first();
145 | if ($permissionItem === null) {
146 | DB::table('permissions')->insert($permission);
147 | }
148 | }
149 |
150 | foreach ($this->roles as $role) {
151 | $permissions = $role['permissions'];
152 | unset($role['permissions']);
153 |
154 | $roleItem = DB::table('roles')->where([
155 | 'name' => $role['name'],
156 | 'guard_name' => $role['guard_name']
157 | ])->first();
158 | if ($roleItem === null) {
159 | $roleId = DB::table('roles')->insertGetId($role);
160 | } else {
161 | $roleId = $roleItem->id;
162 | }
163 |
164 | $permissionItems = DB::table('permissions')
165 | ->whereIn('name', $permissions)
166 | ->where(
167 | 'guard_name',
168 | $role['guard_name']
169 | )->get();
170 | foreach ($permissionItems as $permissionItem) {
171 | $roleHasPermissionData = [
172 | 'permission_id' => $permissionItem->id,
173 | 'role_id' => $roleId
174 | ];
175 | $roleHasPermissionItem = DB::table('role_has_permissions')->where($roleHasPermissionData)->first();
176 | if ($roleHasPermissionItem === null) {
177 | DB::table('role_has_permissions')->insert($roleHasPermissionData);
178 | }
179 | }
180 | }
181 |
182 | foreach ($this->users as $user) {
183 | $roles = $user['roles'];
184 | unset($user['roles']);
185 |
186 | $permissions = $user['permissions'];
187 | unset($user['permissions']);
188 |
189 | $userItem = DB::table($this->userTable)->where([
190 | 'email' => $user['email'],
191 | ])->first();
192 |
193 | if ($userItem === null) {
194 | $userId = DB::table($this->userTable)->insertGetId($user);
195 |
196 | AdminUser::find($userId)->addMedia(storage_path() . '/images/avatar.png')
197 | ->preservingOriginal()
198 | ->toMediaCollection('avatar', 'media');
199 |
200 | foreach ($roles as $role) {
201 | $roleItem = DB::table('roles')->where([
202 | 'name' => $role['name'],
203 | 'guard_name' => $role['guard_name']
204 | ])->first();
205 |
206 | $modelHasRoleData = [
207 | 'role_id' => $roleItem->id,
208 | 'model_id' => $userId,
209 | 'model_type' => $this->userClassName
210 | ];
211 | $modelHasRoleItem = DB::table('model_has_roles')->where($modelHasRoleData)->first();
212 | if ($modelHasRoleItem === null) {
213 | DB::table('model_has_roles')->insert($modelHasRoleData);
214 | }
215 | }
216 |
217 | foreach ($permissions as $permission) {
218 | $permissionItem = DB::table('permissions')->where([
219 | 'name' => $permission['name'],
220 | 'guard_name' => $permission['guard_name']
221 | ])->first();
222 |
223 | $modelHasPermissionData = [
224 | 'permission_id' => $permissionItem->id,
225 | 'model_id' => $userId,
226 | 'model_type' => $this->userClassName
227 | ];
228 | $modelHasPermissionItem = DB::table('model_has_permissions')->where($modelHasPermissionData)->first();
229 | if ($modelHasPermissionItem === null) {
230 | DB::table('model_has_permissions')->insert($modelHasPermissionData);
231 | }
232 | }
233 | }
234 | }
235 | });
236 | app()['cache']->forget(config('permission.cache.key'));
237 | }
238 |
239 | /**
240 | * Reverse the migrations.
241 | *
242 | * @throws Exception
243 | * @return void
244 | */
245 | public function down(): void
246 | {
247 | if ($this->userClassName === null) {
248 | throw new RuntimeException('Admin user model not defined');
249 | }
250 | DB::transaction(function () {
251 | foreach ($this->users as $user) {
252 | $userItem = DB::table($this->userTable)->where('email', $user['email'])->first();
253 | if ($userItem !== null) {
254 | AdminUser::find($userItem->id)->media()->delete();
255 | DB::table($this->userTable)->where('id', $userItem->id)->delete();
256 | DB::table('model_has_permissions')->where([
257 | 'model_id' => $userItem->id,
258 | 'model_type' => $this->userClassName
259 | ])->delete();
260 | DB::table('model_has_roles')->where([
261 | 'model_id' => $userItem->id,
262 | 'model_type' => $this->userClassName
263 | ])->delete();
264 | }
265 | }
266 |
267 | foreach ($this->roles as $role) {
268 | $roleItem = DB::table('roles')->where([
269 | 'name' => $role['name'],
270 | 'guard_name' => $role['guard_name']
271 | ])->first();
272 | if ($roleItem !== null) {
273 | DB::table('roles')->where('id', $roleItem->id)->delete();
274 | DB::table('model_has_roles')->where('role_id', $roleItem->id)->delete();
275 | }
276 | }
277 |
278 | foreach ($this->permissions as $permission) {
279 | $permissionItem = DB::table('permissions')->where([
280 | 'name' => $permission['name'],
281 | 'guard_name' => $permission['guard_name']
282 | ])->first();
283 | if ($permissionItem !== null) {
284 | DB::table('permissions')->where('id', $permissionItem->id)->delete();
285 | DB::table('model_has_permissions')->where('permission_id', $permissionItem->id)->delete();
286 | }
287 | }
288 | });
289 | app()['cache']->forget(config('permission.cache.key'));
290 | }
291 | }
292 |
--------------------------------------------------------------------------------