{"id":25478829,"url":"https://github.com/atiqurcode/eloquent-one-to-many","last_synced_at":"2026-04-25T12:32:50.786Z","repository":{"id":113437895,"uuid":"478415345","full_name":"AtiqurCode/Eloquent-One-to-Many","owner":"AtiqurCode","description":"Eloquent One To Many relationship","archived":false,"fork":false,"pushed_at":"2022-04-12T05:55:06.000Z","size":89,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-18T06:07:23.021Z","etag":null,"topics":["eloquent","laravel","one-to-many","relationships"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AtiqurCode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-06T05:27:33.000Z","updated_at":"2022-04-06T08:03:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"0e47d085-7cc0-4415-b879-ac688a68409b","html_url":"https://github.com/AtiqurCode/Eloquent-One-to-Many","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AtiqurCode/Eloquent-One-to-Many","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AtiqurCode%2FEloquent-One-to-Many","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AtiqurCode%2FEloquent-One-to-Many/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AtiqurCode%2FEloquent-One-to-Many/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AtiqurCode%2FEloquent-One-to-Many/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AtiqurCode","download_url":"https://codeload.github.com/AtiqurCode/Eloquent-One-to-Many/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AtiqurCode%2FEloquent-One-to-Many/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32262801,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T09:15:33.318Z","status":"ssl_error","status_checked_at":"2026-04-25T09:15:31.997Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eloquent","laravel","one-to-many","relationships"],"created_at":"2025-02-18T14:53:46.687Z","updated_at":"2026-04-25T12:32:50.779Z","avatar_url":"https://github.com/AtiqurCode.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Read One-to-Many basics \u0026 try with this code as you want\n\nGo throw **laravel documentation** to read about it \u0026 many more blog\n\nFirst you need to clone this and save **.env.example as .env** and setup your environment or just change the database configure\n\n```sh\nDB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=your-database-name\nDB_USERNAME=your-database-user-name\nDB_PASSWORD=your-database-password(if have)\n```\n\nNow just run some command on terminal one by one\n\n```sh\ncomposer install\nphp artisan migrate\nphp artisan serve\n```\n\nAs I have said this is One to Many relationship. // Imagine part\n- Example1: A User can have many posts\n- Example2: Student can have many Books\n- Example3: Office can have many employees\n- Example3: Owner can have many cars\n\nSo I have just created Two model\n- **User**\n- **Post**\n\nUser Model are relation with hasOne\n\n```sh\n    public function posts()\n    {\n        return $this-\u003ehasMany(Post::class);\n    }\n```\n\nPosts Model are relation with belongsTo\n\n```sh\n    public function user()\n    {\n        return $this-\u003ebelongsTo(User::class);\n    }\n\n    // You can save return $this-\u003ebelongsTo(User::class, 'user_id'); relation column name if you didn't follow the naming convention \n```\n\nAnd controller code are depend's on condition what I need. So you can got throw the controllers method.\n\nif you have **Postman**/any software like that please import One-to-Many.postman_collection.json file either call\n```sh\n- {url-of-your-app}/api/users                 --method : get      // get all user list\n- {url-of-your-app}/api/users/{user}          --method : get      // get one user by id with her/his posts\n- {url-of-your-app}/api/users                 --method : post     // insert user details\n- {url-of-your-app}/api/users/{user}          --method : put      // update user details\n- {url-of-your-app}/api/users/{user}          --method : delete   // delete user and her/his posts \n- {url-of-your-app}/api/posts                 --method : get      // get all posts \n- {url-of-your-app}/api/posts/{post}          --method : get      // get one posts with user details by post_id/id\n- {url-of-your-app}/api/posts/                --method : post     // create post\n- {url-of-your-app}/api/posts/{post}          --method : put      // update post by post_id/id\n- {url-of-your-app}/api/posts/{post}          --method : delete   // delete post by post_id/id\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatiqurcode%2Feloquent-one-to-many","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatiqurcode%2Feloquent-one-to-many","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatiqurcode%2Feloquent-one-to-many/lists"}