railroad / railcontent
Very simple and flexible CMS system for developers.
Installs: 99 620
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 2
Open Issues: 4
Requires
- php: ^8.2
- ext-pdo: *
- aws/aws-sdk-php: ^3.0.0
- doctrine/dbal: ^3.0
- elasticsearch/elasticsearch: ~7.0
- google/apiclient: ^2.2
- guzzlehttp/guzzle: ^7.2
- iksaku/laravel-mass-update: ^1.0
- laravel/framework: ^11.9
- league/flysystem: ^3.0
- league/flysystem-aws-s3-v3: ^3.0
- predis/predis: ^2.1
- railroad/mailora: ^4.0
- railroad/response: ^3.0
- ramsey/uuid: ^4.3
- symfony/http-foundation: ^7.0
- vimeo/vimeo-api: ^3.0
Requires (Dev)
- orchestra/testbench: ^9.2
- phpunit/php-code-coverage: ^11.0.1
- phpunit/phpunit: ^11.0.1
- dev-main
- 5.6.x-dev
- v3.0.x-dev
- v3.0.9
- v3.0.8
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.1
- v3.0.0
- v2.1.x-dev
- v2.1.97
- v2.1.96
- v2.1.95
- v2.1.94
- v2.1.93
- v2.1.92
- v2.1.91
- v2.1.90
- v2.1.89
- v2.1.88
- v2.1.87
- v2.1.86
- v2.1.85
- v2.1.84
- v2.1.83
- v2.1.82
- v2.1.81
- v2.1.80
- v2.1.79
- v2.1.78
- v2.1.77
- v2.1.76
- v2.1.75
- v2.1.74
- v2.1.73
- v2.1.72
- v2.1.71
- v2.1.70
- v2.1.69
- v2.1.68
- v2.1.67
- v2.1.66
- v2.1.65
- v2.1.64
- v2.1.63
- v2.1.62
- v2.1.61
- v2.1.60
- v2.1.59
- v2.1.58
- v2.1.57
- v2.1.56
- v2.1.55
- v2.1.54
- v2.1.53
- v2.1.52
- v2.1.51
- v2.1.50
- v2.1.49
- v2.1.48
- v2.1.47
- v2.1.46
- v2.1.45
- v2.1.44
- v2.1.43
- v2.1.42
- v2.1.41
- v2.1.40
- v2.1.39
- v2.1.38
- v2.1.37
- v2.1.36
- v2.1.35
- v2.1.34
- v2.1.33
- v2.1.32
- v2.1.31
- v2.1.30
- v2.1.29
- v2.1.28
- v2.1.27
- v2.1.26
- v2.1.25
- v2.1.24
- v2.1.23
- v2.1.21
- v2.1.20
- v2.1.19
- v2.1.18
- v2.1.17
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.0.79
- v2.0.78
- v2.0.77
- v2.0.76
- v2.0.75
- v2.0.74
- v2.0.73
- v2.0.72
- v2.0.71
- v2.0.70
- v2.0.69
- v2.0.68
- v2.0.67
- v2.0.66
- v2.0.65
- v2.0.64
- v2.0.63
- v2.0.62
- v2.0.61
- v2.0.60
- v2.0.59
- v2.0.58
- v2.0.57
- v2.0.56
- 2.0.55
- 2.0.54
- 2.0.53
- 2.0.52
- 2.0.51
- 2.0.50
- v2.0.47
- v2.0.46
- v2.0.45
- 2.0.44
- 2.0.43
- 2.0.42
- 2.0.41
- v2.0.40
- 2.0.39
- 2.0.38
- 2.0.37
- v2.0.36
- v2.0.35
- v2.0.34
- v2.0.33
- v2.0.32
- v2.0.31
- v2.0.30
- v2.0.29
- 2.0.28
- 2.0.27
- v2.0.26
- v2.0.25
- v2.0.24
- v2.0.23
- v2.0.22
- v2.0.21
- v2.0.20
- v2.0.19
- v2.0.18
- v2.0.17
- v2.0.16
- v2.0.15
- v2.0.14
- v2.0.13
- v2.0.12
- v2.0.11
- v2.0.10
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v0.5.191
- v0.5.190
- v0.5.189
- v0.5.188
- v0.5.187
- v0.5.186
- v0.5.185
- v0.5.184
- v0.5.183
- v0.5.182
- v0.5.181
- v0.5.180
- v0.5.179
- v0.5.178
- v0.5.177
- v0.5.176
- v0.5.175
- v0.5.174
- v0.5.173
- v0.5.172
- v0.5.171
- v0.5.170
- v0.5.169
- v0.5.168
- v0.5.167
- v0.5.166
- v0.5.165
- v0.5.164
- v0.5.163
- v0.5.162
- v0.5.161
- v0.5.160
- v0.5.159
- v0.5.158
- v0.5.157
- v0.5.156
- v0.5.155
- v0.5.154
- v0.5.153
- v0.5.152
- v0.5.151
- v0.5.150
- v0.5.149
- v0.5.148
- v0.5.147
- v0.5.146
- v0.5.145
- v0.5.144
- v0.5.143
- v0.5.142
- v0.5.141
- v0.5.140
- v0.5.139
- v0.5.138
- v0.5.137
- v0.5.136
- v0.5.135
- v0.5.134
- v0.5.133
- v0.5.132
- v0.5.131
- v0.5.130
- v0.5.129
- v0.5.128
- v0.5.127
- v0.5.126
- v0.5.125
- v0.5.124
- v0.5.123
- v0.5.122
- v0.5.121
- v0.5.120
- v0.5.119
- v0.5.118
- v0.5.117
- v0.5.116
- v0.5.115
- v0.5.114
- v0.5.113
- v0.5.112
- v0.5.111
- v0.5.110
- v0.5.109
- v0.5.108
- v0.5.107
- v0.5.106
- v0.5.105
- v0.5.104
- v0.5.103
- v0.5.102
- v0.5.101
- v0.5.100
- v0.5.99
- v0.5.98
- v0.5.97
- v0.5.96
- v0.5.95
- v0.5.94
- v0.5.93
- v0.5.92
- v0.5.91
- v0.5.90
- v0.5.89
- v0.5.88
- v0.5.87
- v0.5.86
- v0.5.85
- v0.5.84
- v0.5.83
- v0.5.82
- v0.5.81
- v0.5.80
- v0.5.79
- v0.5.78
- v0.5.77
- v0.5.76
- v0.5.75
- v0.5.74
- v0.5.73
- v0.5.72
- v0.5.71
- v0.5.70
- v0.5.69
- v0.5.68
- v0.5.67
- v0.5.66
- v0.5.65
- v0.5.64
- v0.5.63
- v0.5.62
- v0.5.61
- v0.5.59
- v0.5.58
- v0.5.57
- v0.5.56
- v0.5.55
- v0.5.54
- v0.5.53
- v0.5.52
- v0.5.51
- v0.5.50
- v0.5.49
- v0.5.48
- v0.5.47
- v0.5.46
- v0.5.45
- v0.5.44
- v0.5.43
- v0.5.42
- v0.5.41
- v0.5.40
- v0.5.39
- v0.5.38
- v0.5.37
- v0.5.36
- v0.5.35
- v0.5.34
- v0.5.33
- v0.5.32
- v0.5.31
- v0.5.30
- v0.5.29
- v0.5.28
- v0.5.27
- v0.5.26
- v0.5.25
- v0.5.24
- v0.5.23
- v0.5.22
- v0.5.21
- v0.5.20
- v0.5.19
- v0.5.18
- v0.5.17
- v0.5.16
- v0.5.15
- v0.5.14
- v0.5.13
- v0.5.12
- v0.5.11
- v0.5.10
- v0.5.9
- v0.5.8
- v0.5.7
- v0.5.6
- v0.5.5
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.24
- v0.4.23
- v0.4.22
- v0.4.21
- v0.4.20
- v0.4.19
- v0.4.18
- v0.4.17
- v0.4.16
- v0.4.15
- v0.4.14
- v0.4.13
- v0.4.12
- v0.4.11
- v0.4.10
- v0.4.09
- v0.4.08
- v0.4.07
- v0.4.06
- v0.4.05
- v0.4.04
- v0.4.03
- v0.4.02
- v0.4.01
- v0.4.0
- v0.3.02
- v0.3.01
- v0.2.27
- v0.2.26
- v0.2.25
- v0.2.24
- v0.2.23
- v0.2.22
- v0.2.21
- v0.2.20
- v0.2.17
- v0.2.16
- v0.2.15
- v0.2.14
- v0.2.13
- v0.2.12
- v0.2.11
- v0.2.10
- v0.2.05
- v0.2.04
- v0.2.03
- v0.2.02
- v0.2.01
- v0.2.00
- v0.1.37
- v0.1.36
- v0.1.35
- v0.1.34
- v0.1.33
- v0.1.32
- v0.1.26
- v0.1.25
- v0.1.24
- v0.1.23
- v0.1.22
- v0.1.21
- v0.1.20
- v0.1.19
- v0.1.18
- v0.1.17
- v0.1.16
- v0.1.15
- v0.1.14
- v0.1.13
- v0.1.12
- v0.1.11
- v0.1.1
- v0.1.0
- v0.0.99
- v0.0.98
- v0.0.97
- v0.0.96
- v0.0.95
- v0.0.94
- v0.0.93
- v0.0.92
- v0.0.91
- v0.0.90
- v0.0.89
- v0.0.88
- v0.0.87
- v0.0.86
- v0.0.85
- v0.0.84
- v0.0.83
- v0.0.82
- v0.0.81
- v0.0.80
- v0.0.79
- v0.0.78
- v0.0.77
- v0.0.76
- v0.0.75
- v0.0.74
- v0.0.73
- v0.0.72
- v0.0.71
- v0.0.70
- v0.0.61
- v0.0.60
- v0.0.53
- v0.0.52
- v0.0.51
- v0.0.50
- v0.0.41
- v0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-0.5-mwp-open-beta-launch
- dev-feature/amcneill20241008__fix_urls
- dev-feature/amcneill20241001_pull_challenge_data_TCH-29
- dev-defaultLimit
- dev-feature/amcneill20240918__rec_pagination
- dev-feature/amcneill20240828_mpw_schedule_changes_BE-300
- dev-dev/amcneill20240909_add_subscribed_coaches_endpoint
- dev-fix/amcneill20250909_add_missing_route
- dev-dev/amcneill20240905_recommended_content
- dev-feature/amcneill20240904_video_endpoints
- dev-feature/amcneill20240829_mc_schedule_changes_BE-300
- dev-feature/amcenill2050828_BE-300_schedule_changes_musora
- dev-v2.1-sanity-feature-cms
- dev-feature/amcneill20240621_BE-230_carousel_updates
- dev-feature/amcneill20240731_incorrect_urls_BE-251
- dev-feature/amcneill20240827_schedule_changes_BE-300
- dev-dev/amcneill20240731_BE-251_handle_null_case
- dev-feature/amcneill20240723__allow_admin_locked_content
- dev-feature/amcneill20240723__content_controller_null_fix
- dev-feature/amcneill20240624__licensing_changes
- dev-feature/amcneill20240719_delist_content_TS-49
- dev-0.5-TP-44-unlisted-status
- dev-TP-44-unlisted-status
- dev-TP-44
- dev-TP-45
- dev-feat/BE-227-fetch-module-sorce
- dev-BE-187
- dev-feature/amcneill20240523_BE-178_snowflake_migration
- dev-feature/amcneill20240614_BE-206_user_content_liked_endpoint
- dev-feature/amcneill20240523_BE-185_lock_timeout
- dev-BE-78
- dev-BE-34
- dev-fix/amcneill20240510_update_recsys_caching_logic
- dev-feature/amcneill20240508__log_cache
- dev-fix/BE-43-trigger-started-completed-events
- dev-feature/amcneill20240503__update_cache_time
- dev-feature/amcneill20240503__update_cache
- dev-feature/amcneill20240503__update_cache2
- dev-BE-76-Recommendation-System-Hide-Song-Pill
- dev-BE-15-MWP
- dev-BE-15
- dev-2.0-
- dev-dev/amcneill20240408_recsys_use_all_section
- dev-MT-727
- dev-FSU-212-MC
- dev-FSU-212
- dev-dev/amcneill20240403_huggingface_timeout
- dev-dev/amcneill20240202_RECSYS_V1_2
- dev-FSU-214
- dev-FSU-213
- dev-dev/rwillems2024_02_05_comment_mod_tool
- dev-hotfix-FSU-187
- dev-hotfix-FSU-158
- dev-dev/alesevero20240305-fix-content-started-event-trigger
- dev-filter-v2
- dev-dev/amcneill20240222_MT-866_CMS_linking
- dev-dev/amcneill20240223_MT-866_CMS_linking_2
- dev-feature-pack-updates
- dev-dev/amcneill20240131_rec_sys_internal
- dev-dev/amcneill20240124_mt805_recsys_v1.1
- dev-dev/amcneill20240102_MT805_recommender_implementation
- dev-hotfix-guitar-system-to-playlist
- dev-2.0-workouts-sort-fix-rwillems20231222
- dev-2.0-workouts
- dev-2.0-enrollment-dates-optimizations
- dev-2.0-workouts-filters
- dev-srr-148-CMS
- dev-2.0-included-fields-fix
- dev-catalogue-filters-v2
- dev-2.0-connection-mask-public
- dev-dummy-action-pack-started-event-BR-884
- dev-0.5-mwp-open-beta-launch-song-duration
- dev-2.0-playlists-v15
- dev-2.0-fix-paused-members-page-MT-532
- dev-2.0-update-neighbour-siblings-query
- dev-2.0-playlists
- dev-2.0-filters-updates
- dev-playlists-progress
- dev-2.0-cohort-optimizations
- dev-feature-block-user
- dev-2.0-playlists-code-review
- dev-2.0-store-reported-comments
- dev-v2.0-fix-content-list-bug-BR-458
- dev-beta-testing-BR334-BR458
- dev-v2.0-previous-next-button-bug-BR-334
- dev-2.0-external_video_id
- dev-0.5-mwp-open-beta-launch-user-progress-optimizations
- dev-2.0-video-progress-optimizations
- dev-v0.5-mwp-open-beta-launch-instrumentless-column-US-27
- dev-v2.0-add-instrumentless-column
- dev-v2.0-request-song
- dev-v2.0-dont-show-scheduled-content-from-past
- dev-test-mircea
- dev-feature-youtube-command-port-rwillems20221124
- dev-fix-vimeo-rwillems20221011
- dev-2.0-fixing-content-permissions
- dev-v2.0-fix-play-along-favorites
- dev-v2.0-content-optimisations
- dev-v2.0-optimisations-compiled-column
- dev-v2.0-content-optimisations-current-live-by-brand
- dev-v2.0-content-optimisations-tables-timestamps
- dev-0.5-
- dev-0.5-php-mysql-8-migration
- dev-2.0-php-mysql-8-migration
- dev-1.0-
- dev-1.0-laravel9
- dev-0.5-higer-key-progress-updates
- dev-0.5-query-optimisations-1
- dev-0.5-content-follow
- dev-0.5-slug-unique
- dev-0.5-sort-by-progress
- dev-migration-fix
- dev-1.0-style
- dev-1.0-elasticsearch
- dev-0.5-user-permission-start-date
- dev-0.5-comment-assignment
- dev-0.5-drumeo-method
- dev-revert_test
- dev-0.5-new-database-structure
- dev-0.6-
- dev-0.5-response-changes
- dev-0.4-
This package is auto-updated.
Last update: 2024-11-06 10:04:41 UTC
README
Data first simple CMS.
- Railcontent
- Progress-Bubbling
- Validation
Progress-Bubbling
When a content has its progress saved, a UserContentProgressSaved
event is fired. This event triggers the bubbleProgress
method of UserContentProgressService
. If the content saved—that triggered the event—has a parent, the type of that parent will be evaluated against config values defined in you're application's copy of /config/railcontent.php.
This is useful when you have a kind of content (like "course" for Drumeo) that should be marked as started when a child is started. However, if you have a kind of content that you don't want marked as started (say perhaps because it has it's own system, like Learning-Paths for Drumeo), you don't want the parent started when the child is. Keep in mind that children can have multiple parents, thus if a lesson is started we may want that to cause one parent to be started, but another to remain unstarted.
You can restrict which content parent types should be marked as started or completed when their children are started by omitting them from the allowed_types lists.
'allowed_types_for_bubble_progress' => [ 'started' => [ 'foo','bar', 'baz' ], 'completed' => [ 'foo','bar', 'qux' ] ];
You can have a value in both list if it has no restrictions, or just one, or neither.
Note that this only applies for progress bubbling. This does not effect the startContent
, completeContent
, or saveContentProgress
methods of UserContentProgressService
.
Example
Say you have a parent of a type for which bubbling of started progress event is not allowed.
If that parent is itself not yet started, it will not have progress record written or updated when one of it's children is. If it's in the "completed" allowed-types list, it can be marked as completed if all it's children are, but unless exactly that happens, it will not have it's progress_percent saved. That is unless it is already started of it's own accord. If the parent is already started, then when a child is updated, the progress_percent value of the parent will be edited as per any other content of a type allowed as per the allowed-for-started config settings.
Validation
Non-technical Introduction
This is business rules validation that helps ensure content requiring specific information|components is protected from not meeting said requirements. For example, you may have a state like "published", which you want only assigned to content this is ready for viewing by your customers. You don't want to accidentally launch content that is missing significant components and would reflect poorly on the brand. Thus, rules can be set within the Content Management System (CMS) to help ensure content meets set criteria.
Without validation, all edits are persisted "unchecked" - even if nonsensical*. This can produce a site with incomplete content, and thus a poor user experience. To prevent this, rules can be configured by technical administrators. Edits to content will - as they're submitted - be "checked" against these set rules. That is, they will be "validated".
When initially creating a piece of content, we need to assume a period where it will fail all validation - as all the fields will empty! Thus, "states" such as "draft", "scheduled", and "published" can be set on content. The Validation rules are then set to only apply to certain "protected" states - typically "scheduled", and "published".
Knowing this, we can now look at the two situations which trigger validation:
- Request to change a content's state to a "protected" state.
- A content has a "protected" state, any details changes will trigger validation.
In each of the above cases, a validation failure will result (respectively) in:
- the requested change to a protected state will not be executed - the state will remain unchanged. Note that if the current|previous state was a protected or unprotected state is irrelevant. All that happens is the requested state change is not persisted.
- the requested change will not be made. To do so would result in having content that breaks the business rules for its type.
* except for Musora CMS, for Musora Media, 2018, where currently video IDs, and exercise IDs are first validated by another system that will not enable setting a nonsensical value, regardless of content state.
Technical Introduction
This is "business rules" validation. This does not validate that the content is suitable for the the database. That is handled by rules hard-coded into a "rules" method in entity-and-action-specific Request
classes (extension of Railroad\Railcontent\Requests\FormRequest
, all in /src/Requests). Rather, this "business rules" validation
is used when content unique to your application requires specific infomation according to it's intended use within your domain. For example, for consumable consumer education and entertainment, you may have states like "public" or "published", which you want only assigned to content that has all components required to meet your requirements for quality and completeness.
In your application's config/ directory, you should have a railcontent.php file. In there under 'validation', you can list the brands for which you want validation. If a brand is not present, validation will not run.
The rules are organized thusly:
brand -> content type -> protected states -> rules*
* see "About Defining Rules" section below
About Defining Rules
The key for each content-type must be the same as the string representing content-type used in the application. Each content-type's rules has two required components, and can have an additional optional component:
- fields
- data
- number_of_children (optional)
If a content-type exists in these rules, then validation will run as described above. If the content-type is not represented in the rules, the validation rules will not protect that content type according to the rules.
(There is not currently a way to provide custom "restrictions" for a select content-type. See the "todo.md" file for notes about how to change this package to make that possible.)
Note about field or datum that reference another piece of content
When a content has a field or datum that is itself a reference to another piece of content, the id of that referenced content is what is evaluated.
Thus, your rule must accommodate|use this.
For example: A video has a field with the id of a video... and that video is a piece of content itself. The rule might look like this:
'video' => [ 'rules' => [ Rule::exists($connectionMaskPrefix . 'content', 'id')->where( function ($query) { $query->where('type', 'vimeo-video'); } ), 'required' ] ],
This is done using the following logic within the "validateContent" method of the "\Railroad\Railcontent\Requests\CustomFormRequest" class:
if (($contentProperty['type'] ?? null) === 'content' && isset($inputToValidate['id'])) { $inputToValidate = $inputToValidate['id']; }
You can see that if the ($contentProperty['type']
is "content" and the
Important Note about the "numeric" rule
If you don't include the "numeric" rule here, this doesn't work. I don't know why and it
doesn't make sense. Laravel' validator should - for the min, max, and size rules according to the
documentation - evaluate the evaluated value in regards to these rules based on the data-type
of the value under evaluation. If it's a string, it will evaluate the length. Thus, if min:5,
the string must have at least 5 characters. If the value is an integer min:5 will pass only if
the value of the integer is 5 or higher. If an array it evaluates the count. You get the idea.
But here it's failing to do that. Even if casting the value to an int just to be sure, and then
debugging to make sure it's not changed into a string somehow (because that would break it of
course because the string "6" would only pass for "min:1" and would fail for "min:2" and upwards
but the integer 6 would pass for "min:2" to "min:6". Maybe something about the "numeric" rule
is casting it to an int somewhere I didn't see. Anyways this is smelly af because that "numeric"
condition is just there as a hack to circumvent failure of the system to act as expected. But
it works, so fuck.
(^ Crudely written note copied here from comment in code)
Specifying rules
You can "...specify the validation rules as an array instead of using the | character to delimit them" (from "Specifying A Custom Column Name" section here).
For example; both bar
and bax
here would have the same effect:
foo => [ 'bar' => ['max:2|required'], 'bax' => [ 'max:2', 'required' ] ]
Details of options available for each brand
fields
(required)
Array of rules keyed by the field they apply to. Each keyed value in this "fields" array represents one field. The value for each can be either a string or array representing the rules available in the Laravel version used. For details about Laravel rules, see their documentation.
data
(required)
Same as fields, except data.
number_of_children
(optional)
See "Important Note about the "numeric" rule" note above.
Provide this in cases where a content type requires a set number of children before it can be set to a "restricted" state (perhaps "published" or "scheduled").
Can be defined either of the two ways:
'number_of_children' => 'min:3', 'number_of_children' => ['rules' => 'min:3'],
Unlike the rest of the rules, this doesn't need to be an item called "rules" in an array. It can be, or not. Either way will work.
Configuration Example
'validation' => [ 'brand' => [ 'content-type' => [ 'content-status|content-status|...' => [ 'number_of_children' => 'min:3', 'fields' => [ 'key' => [ rules => ['validation-rule', 'validation-rule', ...], 'can_have_multiple' => true/false], ], 'key' => [ rules => 'validation-rule|validation-rule|...', 'can_have_multiple' => true/false], ], ], 'data' => [ 'key' => [ rules => ['validation-rule', 'validation-rule', ...], 'can_have_multiple' => true/false], ], 'key' => [ rules => 'validation-rule|validation-rule|...', 'can_have_multiple' => true/false], ], ] ] ], ] ]
MultipleColumnExistsValidator
NOTE: This actually doesn't work properly right now, so if the above may not quuuuite be accurate.
Is ^ this still accurate? (Jonathan, July 2018)
You may not be able to use the Rule::Exists()
feature of the Laravel's validator where you specify your validation
rules. Perhaps you specify your rules in configuration files that are cache calling a method statically like that breaks
them for some reason.
To overcome this, there exists a custom rule in this package called (Railroad\Railcontent\Validators) "MultipleColumnExistsValidator". Also, there is a test for it: (Tests\Feature) "MultipleColumnExistsRuleTest".
Look at the class to understand fully how it works, if need be. If you only need a quick look, this is what it does:
$exists = $this->databaseManager->connection($connection) ->table($table) ->where($row, $value) ->exists();
You pass these arguments via your rules:
$connection = $parameterParts[0]; $table = $parameterParts[1]; $row = $parameterParts[2]; $value = isset($parameterParts[3]) ? $parameterParts[3] : $value;
A configured rule looks like this:
'video' => 'exists_multiple_columns:mysql,railcontent_content,id&mysql,railcontent_content,type,vimeo-video'
unpacked we get this:
exists_multiple_columns:
mysql,railcontent_content,id
&
mysql,railcontent_content,type,vimeo-video
Breaking down each line:
exists_multiple_columns
is the name of the custom rule
mysql,railcontent_content,id
is a set or rules for a single "where exists" clause to the database validation that will
run.
&
(ampersand) is our delimiter - since the pipe, or vertical bar (|
) is already used by laravel to delimit
rules.
mysql,railcontent_content,type,vimeo-video
is another *"where exists" clause added to the database validation that
will run when all clauses are compiled.
For the validation to pass in this case, both "where exists" validations must pass.
Within each "where exists" validation, values are delimited by commas (,
).
So, the first set has THREE (3) values
mysql
railcontent_content
id
And the second set has FOUR (4) values:
mysql
railcontent_content
type
vimeo-video
The first THREE (3) parameters are required, the FOURTH (4th)) is optional.
As you may have guessed by the code snippet above, the parameters are as such:
- connection (required)
- table (required)
- $row (required)
- $value (optional)
If the FOURTH (4th) parameter is not passed, the value used for the "where exists" evaluation will be the value which the whole rule is validating.
Reviewing the example, we see that we're validating the value submitted to the video
input against the rule
'exists_multiple_columns:mysql,railcontent_content,id&mysql,railcontent_content,type,vimeo-video'
to ensure that
the value matches the two clauses mysql,railcontent_content,id
and mysql,railcontent_content,type,vimeo-video
.
The first ensures that by the connection "mysql", in the table "railcontent_content", the value under validation matches
a value in the "id" column. The second does the same, but the value isn't the values passed in, but rather the value
hard-coded in rule as the FOURTH parameter - "vimeo-video". Thus, it ensures that there exists a record where the value
passes in matches something in the "id" column and at least one records matching that also has value or "vimeo-video"
in it's "type" column.
WHERE AND
The above example describes a "WHERE ... AND ... " query. This is standard behaviour - everything must be present in at least one row for the validation to pass.
WHERE OR
This describes a "WHERE ... OR ... " query.
You can prepend your "clause rule string" (remember these are demarcated from each other with ampersands(&)) with or:
,
so that for the examples above, the second one instead of looking like this:
mysql,railcontent_content,type,vimeo-video
would look like this
or:mysql,railcontent_content,type,vimeo-video
This works with the preceding rule and when there exists an or:
"between" them, they're connected is an or statement.
Note that because you can have more than two "clause rule strings" in a rule, you can combine ORs and ANDs thusly:
exists_multiple_columns:
mysql,railcontent_content,id
&
or:mysql,railcontent_content,foo_id
&
mysql,railcontent_content,type,vimeo-video
&
or:mysql,railcontent_content,slug,'bar baz'
Means that one of the first two "clause rule strings" must match with one of the two last "clause rule strings".
(
mysql,railcontent_content,id
OR
mysql,railcontent_content,foo_id
)
AND
(
mysql,railcontent_content,type,vimeo-video
OR
mysql,railcontent_content,slug,'bar baz'
)