Запросить список значений определенного столбца в Laravel - PullRequest
0 голосов
/ 15 октября 2018

Я пытаюсь запросить список в виде массива непосредственно из таблицы моей базы данных без необходимости создавать еще один цикл foreach и создавать его самостоятельно.


Я пытаюсь

return Response::json(Skill::select('name')->get());

Я получаю

[{"name":"Vagrant"},{"name":"Docker"},{"name":"Gulp"},{"name":"Heroku"},{"name":"RequireJS"},{"name":"AngularJS"},{"name":"Composer "},{"name":"NPM"},{"name":"MySQL"},{"name":"Sublime Text"},{"name":"Laravel"},{"name":"PyCharm"},{"name":"Mac OS X"},{"name":"Windows"},{"name":"Ubuntu"},{"name":"Cent OS"},{"name":"Photoshop"},{"name":"Illustrator"},{"name":"MobaXTerm"},{"name":"Terminal"},{"name":"iMovie"},{"name":"Final Cut"},{"name":"GitHub"},{"name":"BitBucket"},{"name":"Selenium"},{"name":"Python"},{"name":"Bower"},{"name":"Sass"},{"name":"Digital Ocean"},{"name":"Linode"},{"name":"Siteground"},{"name":"Go Daddy"},{"name":"Shopify"},{"name":"Facebook"},{"name":"Twitter"},{"name":"Salesforce"},{"name":"OAuth 2.0"},{"name":"SAML 2.0"},{"name":"OpenID Connect"},{"name":"PostgreSQL"},{"name":"Bash"},{"name":"PHP"},{"name":"Google Map"},{"name":"Google Translation"},{"name":"Instagram"},{"name":"LESS"},{"name":"Geolocation API"},{"name":"Xcode"},{"name":"Atom"},{"name":"Webpack"},{"name":"AWS Console"},{"name":"Secure Shell"},{"name":"Node"},{"name":"Yarn"},{"name":"Pod"},{"name":"EC2"},{"name":"Amazon ECS"},{"name":"S3"},{"name":"Amazon RDS"},{"name":"Camtasia"},{"name":"Core Data"},{"name":"Realm"},{"name":"VS Code"},{"name":"TextMate"},{"name":"TextWrangler"},{"name":"Laravel Elixir"},{"name":"Virtual Machine"},{"name":"Open  Stack"},{"name":"Redis"},{"name":"Local Storage"},{"name":"Protractor"},{"name":"Jest"},{"name":"Mocha"},{"name":"Chai"},{"name":"SinonJS"},{"name":"AWS"},{"name":"HTML"},{"name":"CSS"},{"name":"Javascript"},{"name":"Sketch"},{"name":"iOS"},{"name":"Express"},{"name":"Angular"},{"name":"React Native"},{"name":"jQuery"},{"name":"Nginx"},{"name":"Apache"},{"name":"PayPal"},{"name":"Square "},{"name":"Disqus"},{"name":"YouTube"},{"name":"Swagger"},{"name":"GitLab"},{"name":"Amazon ECR "},{"name":"Jira"},{"name":"Trello "},{"name":"Evernote "},{"name":"Confluence "},{"name":"Word"},{"name":"CodeBox"},{"name":"Markdown"},{"name":"Noteability"},{"name":"Kamar"},{"name":"Jasmine"},{"name":"Swift"},{"name":"Coda"},{"name":"Postman"},{"name":"Wireshark"},{"name":"Transmit"},{"name":"WinSCP"},{"name":"Navicat Premium"},{"name":"Kaleidoscope"},{"name":"Mind Note "},{"name":"Divvy"},{"name":"Duet"},{"name":"Draw.io"},{"name":"Google Draw"},{"name":"VMWare Fusion "},{"name":"Virtualbox"},{"name":"QuickBooks"},{"name":"Chat.io"},{"name":"FusionCharts"},{"name":"Google Chart"},{"name":"J Player"},{"name":"CKEditor"}]

Я пытался получить эти

["Vagrant","Docker","Gulp","Heroku","RequireJS","AngularJS","Composer ","NPM","MySQL","Sublime Text","Laravel","PyCharm","Mac OS X","Windows","Ubuntu","Cent OS","Photoshop","Illustrator","MobaXTerm","Terminal","iMovie","Final Cut","GitHub","BitBucket","Selenium","Python","Bower","Sass","Digital Ocean","Linode","Siteground","Go Daddy","Shopify","Facebook","Twitter","Salesforce","OAuth 2.0","SAML 2.0","OpenID Connect","PostgreSQL","Bash","PHP","Google Map","Google Translation","Instagram","LESS","Geolocation API","Xcode","Atom","Webpack","AWS Console","Secure Shell","Node","Yarn","Pod","EC2","Amazon ECS","S3","Amazon RDS","Camtasia","Core Data","Realm","VS Code","TextMate","TextWrangler","Laravel Elixir","Virtual Machine","Open  Stack","Redis","LocalStorage","Protractor","Jest","Mocha","Chai","SinonJS","AWS","HTML","CSS","Javascript","Sketch","iOS","Express","Angular","React Native","jQuery","Nginx","Apache","PayPal","Square ","Disqus","YouTube","Swagger","GitLab","Amazon ECR ","Jira","Trello ","Evernote ","Confluence ","Word","CodeBox","Markdown","Noteability","Kamar","Jasmine","Swift","Coda","Postman","Wireshark","Transmit","WinSCP","Navicat Premium","Kaleidoscope","Mind Note ","Divvy","Duet","Draw.io","Google Draw","VMWare Fusion ","Virtualbox","QuickBooks","Chat.io","FusionCharts","Google Chart","J Player","CKEditor"]

Как можно было бы отладить это дальше?

1 Ответ

0 голосов
/ 15 октября 2018

Понял ..

return Skill::all()->pluck('name');

, кажется, возвращает то, что я ищу.

[
    "Vagrant",
    "Docker",
    "Gulp",
    "Heroku",
    "RequireJS",
    "AngularJS",
    "Composer ",
    "NPM",
    "MySQL",
    "Sublime Text",
    "Laravel",
    "PyCharm",
    "Mac OS X",
    "Windows",
    "Ubuntu",
    "Cent OS",
    "Photoshop",
    "Illustrator",
    "MobaXTerm",
    "Terminal",
    "iMovie",
    "Final Cut",
    "GitHub",
    "BitBucket",
    "Selenium",
    "Python",
    "Bower",
    "Sass",
    "Digital Ocean",
    "Linode",
    "Siteground",
    "Go Daddy",
    "Shopify",
    "Facebook",
    "Twitter",
    "Salesforce",
    "OAuth 2.0",
    "SAML 2.0",
    "OpenID Connect",
    "PostgreSQL",
    "Bash",
    "PHP",
    "Google Map",
    "Google Translation",
    "Instagram",
    "LESS",
    "Geolocation API",
    "Xcode",
    "Atom",
    "Webpack",
    "AWS Console",
    "Secure Shell",
    "Node",
    "Yarn",
    "Pod",
    "EC2",
    "Amazon ECS",
    "S3",
    "Amazon RDS",
    "Camtasia",
    "Core Data",
    "Realm",
    "VS Code",
    "TextMate",
    "TextWrangler",
    "Laravel Elixir",
    "Virtual Machine",
    "Open  Stack",
    "Redis",
    "Local Storage",
    "Protractor",
    "Jest",
    "Mocha",
    "Chai",
    "SinonJS",
    "AWS",
    "HTML",
    "CSS",
    "Javascript",
    "Sketch",
    "iOS",
    "Express",
    "Angular",
    "React Native",
    "jQuery",
    "Nginx",
    "Apache",
    "PayPal",
    "Square ",
    "Disqus",
    "YouTube",
    "Swagger",
    "GitLab",
    "Amazon ECR ",
    "Jira",
    "Trello ",
    "Evernote ",
    "Confluence ",
    "Word",
    "CodeBox",
    "Markdown",
    "Noteability",
    "Kamar",
    "Jasmine",
    "Swift",
    "Coda",
    "Postman",
    "Wireshark",
    "Transmit",
    "WinSCP",
    "Navicat Premium",
    "Kaleidoscope",
    "Mind Note ",
    "Divvy",
    "Duet",
    "Draw.io",
    "Google Draw",
    "VMWare Fusion ",
    "Virtualbox",
    "QuickBooks",
    "Chat.io",
    "FusionCharts",
    "Google Chart",
    "J Player",
    "CKEditor"
]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...