Skip to content

Instantly share code, notes, and snippets.

@jxlwqq
Last active March 4, 2019 11:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jxlwqq/65897e4120ecbc5d7b0e5aaf6f89b2fc to your computer and use it in GitHub Desktop.
Save jxlwqq/65897e4120ecbc5d7b0e5aaf6f89b2fc to your computer and use it in GitHub Desktop.
Best practice for API route
<?php
$form->select('user_id')->options(function ($id) {
$user = User::find($id);
if ($user) {
return [$user->id => $user->name];
}
})->ajax(admin_url('api/users')); # Best practice
# })->ajax('/admin/api/users'); # Strongly not recommended
@robinhoo1973
Copy link

admin_url() just do it as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment