Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Expansions/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,26 @@ public function or()
};
}

/**
* Alias of inputArray() for extensions that haven't moved to the new name yet.
*
* @deprecated use inputArray(); on Laravel 11+ the native Request::array() wins over this macro
*/
public function array()
{
return $this->inputArray();
}

/**
* Converts a specified request parameter into an array by splitting it by commas.
*
* @return \Closure returns a closure that splits a string parameter into an array,
* or directly returns the array parameter
*
* Not named `array`: Laravel 11+ ships a native Request::array(), and native methods
* win over macros, so a macro of that name silently stops running.
*/
public function array()
public function inputArray()
{
return function (string $param) {
/** @var \Illuminate\Http\Request $this */
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/Api/v1/ChatChannelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function create(CreateChatChannelRequest $request)
{
// get request input
$name = $request->input('name');
$participants = $request->array('participants');
$participants = $request->inputArray('participants');

// create the chat channel
$chatChannel = ChatChannel::create([
Expand Down Expand Up @@ -273,7 +273,7 @@ public function sendMessage($id, Request $request)

// Get the message contents and attachment file id
$content = $request->input('content');
$attachments = $request->array('files');
$attachments = $request->inputArray('files');

// Create chat message
$chatMessage = ChatMessage::create([
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Internal/v1/ChatChannelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function createRecord(Request $request)
try {
$name = $request->input('chatChannel.name');
$meta = $request->input('chatChannel.meta', []);
$participants = $request->array('chatChannel.participants');
$participants = $request->inputArray('chatChannel.participants');

$chatChannel = ChatChannel::create([
'company_uuid' => session('company'),
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Internal/v1/ChatMessageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function createRecord(Request $request)
{
try {
$record = $this->model->createRecordFromRequest($request, null, function (&$request, &$chatMessage) {
$attachmentFiles = $request->array('chatMessage.attachment_files');
$attachmentFiles = $request->inputArray('chatMessage.attachment_files');

// If has attachment files create the attachments
foreach ($attachmentFiles as $attachmentFileId) {
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Controllers/Internal/v1/CompanyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function getTwoFactorSettings()
*/
public function saveTwoFactorSettings(Request $request)
{
$twoFaSettings = $request->array('twoFaSettings');
$twoFaSettings = $request->inputArray('twoFaSettings');
$company = Auth::getCompany();

if (!$company) {
Expand Down Expand Up @@ -269,7 +269,7 @@ public function users(string $id, Request $request)
$searchQuery = $request->searchQuery();
$limit = $request->input(['limit', 'nestedLimit'], 20);
$paginate = $request->boolean('paginate');
$exclude = $request->array('exclude');
$exclude = $request->inputArray('exclude');

// Start user query
$usersQuery = CompanyUser::where('company_uuid', $company->uuid)
Expand Down Expand Up @@ -580,7 +580,7 @@ public function removeAdminUser(string $id, string $userId, AdminRequest $reques
public function export(ExportRequest $request)
{
$format = $request->input('format', 'xlsx');
$selections = $request->array('selections');
$selections = $request->inputArray('selections');
$fileName = trim(Str::slug('company-' . date('Y-m-d-H:i')) . '.' . $format);

return Excel::download(new CompanyExport($selections), $fileName);
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Controllers/Internal/v1/LookupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ public function countries(Request $request)
{
$query = strtolower($request->input('query', null));
$simple = $request->boolean('simple');
$columns = $request->array('columns');
$only = array_map(fn ($s) => strtolower($s), $request->array('only'));
$except = array_map(fn ($s) => strtolower($s), $request->array('except'));
$columns = $request->inputArray('columns');
$only = array_map(fn ($s) => strtolower($s), $request->inputArray('only'));
$except = array_map(fn ($s) => strtolower($s), $request->inputArray('except'));

$countries = Country::search($query);

Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/Internal/v1/PolicyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function createRecord(Request $request)
try {
$record = $this->model->createRecordFromRequest($request, null, function ($request, &$policy) {
if ($request->isArray('policy.permissions')) {
$permissions = Permission::whereIn('id', $request->array('policy.permissions'))->get();
$permissions = Permission::whereIn('id', $request->inputArray('policy.permissions'))->get();
$policy->syncPermissions($permissions);
}
});
Expand All @@ -59,7 +59,7 @@ public function updateRecord(Request $request, string $id)
try {
$record = $this->model->updateRecordFromRequest($request, $id, function ($request, &$policy) {
if ($request->isArray('policy.permissions')) {
$permissions = Permission::whereIn('id', $request->array('policy.permissions'))->get();
$permissions = Permission::whereIn('id', $request->inputArray('policy.permissions'))->get();
$policy->syncPermissions($permissions);
}
});
Expand Down
8 changes: 4 additions & 4 deletions src/Http/Controllers/Internal/v1/RoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public function createRecord(Request $request)
$record = $this->model->createRecordFromRequest($request, null, function ($request, &$role) {
// Sync Permissions
if ($request->isArray('role.permissions')) {
$permissions = Permission::whereIn('id', $request->array('role.permissions'))->get();
$permissions = Permission::whereIn('id', $request->inputArray('role.permissions'))->get();
$role->syncPermissions($permissions);
}

// Sync Policies
if ($request->isArray('role.policies')) {
$policies = $this->getAssignablePolicies($request->array('role.policies'));
$policies = $this->getAssignablePolicies($request->inputArray('role.policies'));
$role->syncPolicies($policies);
}
});
Expand All @@ -75,13 +75,13 @@ public function updateRecord(Request $request, string $id)
$record = $this->model->updateRecordFromRequest($request, $id, function ($request, &$role) {
// Sync Permissions
if ($request->isArray('role.permissions')) {
$permissions = Permission::whereIn('id', $request->array('role.permissions'))->get();
$permissions = Permission::whereIn('id', $request->inputArray('role.permissions'))->get();
$role->syncPermissions($permissions);
}

// Sync Policies
if ($request->isArray('role.policies')) {
$policies = $this->getAssignablePolicies($request->array('role.policies'));
$policies = $this->getAssignablePolicies($request->inputArray('role.policies'));
$role->syncPolicies($policies);
}
});
Expand Down
32 changes: 16 additions & 16 deletions src/Http/Controllers/Internal/v1/SettingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,13 @@ public function getMailConfig(AdminRequest $request)
public function saveMailConfig(AdminRequest $request)
{
$mailer = $request->input('mailer', 'smtp');
$from = $request->array('from', []);
$smtp = $request->array('smtp');
$mailgun = $request->array('mailgun');
$postmark = $request->array('postmark');
$sendgrid = $request->array('sendgrid');
$resend = $request->array('resend');
$microsoftGraph = $request->array('microsoftGraph');
$from = $request->inputArray('from', []);
$smtp = $request->inputArray('smtp');
$mailgun = $request->inputArray('mailgun');
$postmark = $request->inputArray('postmark');
$sendgrid = $request->inputArray('sendgrid');
$resend = $request->inputArray('resend');
$microsoftGraph = $request->inputArray('microsoftGraph');

Setting::configureSystem('mail.mailer', $mailer);
Setting::configureSystem('mail.from', $from);
Expand Down Expand Up @@ -372,11 +372,11 @@ public function testMailConfig(AdminRequest $request)
]
);
$smtp = $request->input('smtp', []);
$microsoftGraph = $request->array('microsoftGraph');
$mailgun = $request->array('mailgun');
$postmark = $request->array('postmark');
$sendgrid = $request->array('sendgrid');
$resend = $request->array('resend');
$microsoftGraph = $request->inputArray('microsoftGraph');
$mailgun = $request->inputArray('mailgun');
$postmark = $request->inputArray('postmark');
$sendgrid = $request->inputArray('sendgrid');
$resend = $request->inputArray('resend');
$user = $request->user();
$message = 'Mail configuration is successful, check your inbox for the test email to confirm.';
$status = 'success';
Expand Down Expand Up @@ -646,8 +646,8 @@ public function getNotificationChannelsConfig(AdminRequest $request)
*/
public function saveNotificationChannelsConfig(AdminRequest $request)
{
$apn = array_merge(config('broadcasting.connections.apn', []), $request->array('apn', []));
$firebase = array_merge(config('firebase.projects.app', []), $request->array('firebase', []));
$apn = array_merge(config('broadcasting.connections.apn', []), $request->inputArray('apn', []));
$firebase = array_merge(config('firebase.projects.app', []), $request->inputArray('firebase', []));

// Get the APN key file and it's contents and store to config
$apn = static::_setupApnConfigUsingFileId($apn);
Expand Down Expand Up @@ -675,8 +675,8 @@ public function testNotificationChannelsConfig(AdminRequest $request)
$message = $request->input('message', 'This is a test push notification!');
$apnToken = $request->input('apnToken');
$fcmToken = $request->input('fcmToken');
$apn = $request->array('apn', config('broadcasting.connections.apn'));
$firebase = $request->array('firebase', config('firebase.projects.app'));
$apn = $request->inputArray('apn', config('broadcasting.connections.apn'));
$firebase = $request->inputArray('firebase', config('firebase.projects.app'));

// Get the APN key file and it's contents and store to config
$apn = static::_setupApnConfigUsingFileId($apn);
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Internal/v1/TwoFaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __construct()
*/
public function saveSystemConfig(Request $request)
{
$twoFaSettings = $request->array('twoFaSettings');
$twoFaSettings = $request->inputArray('twoFaSettings');
if (isset($twoFaSettings['enabled']) && $twoFaSettings['enabled'] === false) {
$twoFaSettings['enforced'] = false;
}
Expand Down
16 changes: 8 additions & 8 deletions src/Http/Controllers/Internal/v1/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ public function createRecord(Request $request)

// Sync Permissions
if ($request->isArray('user.permissions')) {
$permissions = Permission::whereIn('id', $request->array('user.permissions'))->get();
$permissions = Permission::whereIn('id', $request->inputArray('user.permissions'))->get();
$user->syncPermissions($permissions);
}

// Sync Policies
if ($request->isArray('user.policies')) {
$policies = $this->getAssignablePolicies($request->array('user.policies'));
$policies = $this->getAssignablePolicies($request->inputArray('user.policies'));
$user->syncPolicies($policies);
}
});
Expand Down Expand Up @@ -306,13 +306,13 @@ public function updateRecord(Request $request, string $id)

// Sync Permissions
if ($request->isArray('user.permissions')) {
$permissions = Permission::whereIn('id', $request->array('user.permissions'))->get();
$permissions = Permission::whereIn('id', $request->inputArray('user.permissions'))->get();
$record->syncPermissions($permissions);
}

// Sync Policies
if ($request->isArray('user.policies')) {
$policies = $this->getAssignablePolicies($request->array('user.policies'));
$policies = $this->getAssignablePolicies($request->inputArray('user.policies'));
$record->syncPolicies($policies);
}

Expand Down Expand Up @@ -705,7 +705,7 @@ public function getTwoFactorSettings(Request $request)
#[SkipAuthorizationCheck]
public function saveTwoFactorSettings(Request $request)
{
$twoFaSettings = $request->array('twoFaSettings');
$twoFaSettings = $request->inputArray('twoFaSettings');
$user = $request->user();

if (!$user) {
Expand Down Expand Up @@ -933,11 +933,11 @@ private function promoteManagedAccount(User $user, Request $request, Role $role)
$user->assignSingleRole($role);

if ($request->isArray('user.permissions')) {
$user->syncPermissions(Permission::whereIn('id', $request->array('user.permissions'))->get());
$user->syncPermissions(Permission::whereIn('id', $request->inputArray('user.permissions'))->get());
}

if ($request->isArray('user.policies')) {
$user->syncPolicies($this->getAssignablePolicies($request->array('user.policies')));
$user->syncPolicies($this->getAssignablePolicies($request->inputArray('user.policies')));
}

if ($user->email && !Invite::isAlreadySentToJoinCompany($user, $company)) {
Expand Down Expand Up @@ -1528,7 +1528,7 @@ public function searchRecords(Request $request)
public function export(ExportRequest $request)
{
$format = $request->input('format', 'xlsx');
$selections = $request->array('selections');
$selections = $request->inputArray('selections');
$fileName = trim(Str::slug('users-' . date('Y-m-d-H:i')) . '.' . $format);

return Excel::download(new UserExport($selections), $fileName);
Expand Down
2 changes: 1 addition & 1 deletion src/Models/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ public static function storageExtensionForUpload(UploadedFile $file): string
*/
public static function fromRequest(Request $request, string $param = 'files'): Collection
{
$ids = $request->array($param);
$ids = $request->inputArray($param);

return static::whereIn('uuid', $ids)->get();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Traits/HasApiModelBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ function ($model) use ($request) {
}

$with = RequestRelations::eagerLoads($result, $request->or(['with', 'expand'], []));
$without = array_filter($request->array('without'), 'is_string');
$without = array_filter($request->inputArray('without'), 'is_string');

if ($with) {
$result->load($with);
Expand Down Expand Up @@ -629,7 +629,7 @@ public function fillSessionAttributes(?array $target = [], array $except = [], a
public function withRelationships(Request $request, $builder)
{
$with = $request->or(['with', 'expand']);
$without = $request->array('without', []);
$without = $request->inputArray('without', []);

if (!$with && !$without) {
return $builder;
Expand Down Expand Up @@ -682,7 +682,7 @@ public function withCounts($request, $builder)
public function applySorts($request, $builder)
{
// Grab the raw sort input
$sorts = (array) $request->array('sort');
$sorts = (array) $request->inputArray('sort');

// Nothing to sort by
if (empty($sorts)) {
Expand Down Expand Up @@ -923,7 +923,7 @@ public function applyCustomFilters(Request $request, $builder)

// handle with/without here
$with = $request->or(['with', 'expand'], []);
$without = $request->array('without');
$without = $request->inputArray('without');
$withoutRelations = $request->boolean('without_relations');

// apply only the requested names that are relations of this model
Expand Down
7 changes: 4 additions & 3 deletions tests/Unit/Expansions/CoreExpansionContractsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ function core_expansion_builder_database(): Capsule

$expansion = new RequestExpansion();
HttpRequest::macro('or', $expansion->or());
HttpRequest::macro('array', $expansion->array());
HttpRequest::macro('inputArray', $expansion->inputArray());

app('db')->connection('mysql')->table('companies')->insert([
'uuid' => 'company-1',
Expand Down Expand Up @@ -378,9 +378,10 @@ function core_expansion_builder_database(): Capsule
])
->and($expansion->or()->call($request, ['missing', 'status'], 'fallback'))->toBe('active')
->and($expansion->or()->call($request, ['missing'], 'fallback'))->toBe('fallback')
->and($expansion->inputArray()->call($request, 'ids'))->toBe(['one', 'two', 'three'])
->and($expansion->array()->call($request, 'ids'))->toBe(['one', 'two', 'three'])
->and($expansion->array()->call($request, 'tags'))->toBe(['fragile', 'cold'])
->and($expansion->array()->call($request, 'missing'))->toBe([])
->and($expansion->inputArray()->call($request, 'tags'))->toBe(['fragile', 'cold'])
->and($expansion->inputArray()->call($request, 'missing'))->toBe([])
->and($expansion->isString()->call($request, 'status'))->toBeTrue()
->and($expansion->isUuid()->call($request, 'uuid'))->toBeTrue()
->and($expansion->isArray()->call($request, 'tags'))->toBeTrue()
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Http/ChatChannelControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ function chat_channel_controller_database(): Capsule
SupportStr::macro('humanize', $strExpansion->humanize());
}

if (!Request::hasMacro('array')) {
Request::macro('array', function (string $key, array $default = []): array {
if (!Request::hasMacro('inputArray')) {
Request::macro('inputArray', function (string $key, array $default = []): array {
$value = $this->input($key, $default);

return is_array($value) ? $value : $default;
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Http/CommentControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ function comment_controller_database(): Capsule
SupportStr::macro('humanize', $strExpansion->humanize());
}

if (!Request::hasMacro('array')) {
Request::macro('array', function (string $key, array $default = []): array {
if (!Request::hasMacro('inputArray')) {
Request::macro('inputArray', function (string $key, array $default = []): array {
$value = $this->input($key, $default);

return is_array($value) ? $value : $default;
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Http/CompanyControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,8 @@ function company_controller_fixtures(): Capsule
});
}

if (!Request::hasMacro('array')) {
Request::macro('array', function (string $key, array $default = []): array {
if (!Request::hasMacro('inputArray')) {
Request::macro('inputArray', function (string $key, array $default = []): array {
$value = $this->input($key, $default);

if (is_string($value) && str_contains($value, ',')) {
Expand Down
Loading
Loading