I am new to Laravel and on a time crunch for a project. Looking for any help on getting started with this project. I need to import this table from this url http://ftp.ebi.ac.uk/pub/databases/genenames/hgnc/json/locus_groups/protein-coding_gene.json into laravel. First question is where to put this in the file structure.
Then, I need to create a search that can access just 2 parts of this table (gene symbol and location) and display the results. What are some basic setup tips and/or code to help me access that data from my search bar?
Thank you so much!
I know this code will get me started:
public function index()
$results = file_get_contents("http://ftp.ebi.ac.uk/pub/databases/genenames/hgnc/json/locus_groups/protein-coding_gene.json");
$data = json_decode($results, true);
But not sure where to put that and where to go from there.
First question is where to put this in the file structure.
Up to you, also depends on if you're downloading it on the fly each time your code runs, or if you're uploading it to your Laravel app as a static asset.
If you're downloading on the fly, I'm not sure that you do need to store it on your filesystem really. If it's an asset which you need to manually update, upload it to public/assets or similar.
If you want to use it for searching, you'll probably need to store the file as an asset and load it into your app.
Then, I need to create a search that can access just 2 parts of this table (gene symbol and location) and display the results. What are some basic setup tips and/or code to help me access that data from my search bar?
I'd suggest using a JSON parser like https://jsonformatter.org/json-parser to format the file and explore its structure. Using your IDE's autoformatter is also fine.
$data
is just an associative array so you can access its contents as normal. For searching, you can load up your JSON file and loop through the array, check if the current object's name/location matches the search query according to your searching method (equality, startsWith, etc). It looks like your JSON file is pretty large though, and while looping probably won't take too long, loading that all into memory might not be nice. So you probably want to maintain some sort of cache, or parse the datafile into a local database, and write up an SQL query for it.
If you don't want to spin up a database etc, a more lightweight approach might be to process the JSON file once, create a new smaller JSON file which just contains the search criteria and an array index reference to where the object lies in the bigger JSON file.
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
https://laravel.com/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.