https://github.com/atiqurcode/eloquent-one-to-one
A short crud application On API.
https://github.com/atiqurcode/eloquent-one-to-one
crud-api crud-application eloquent laravel laravel-8 one-to-one
Last synced: 3 months ago
JSON representation
A short crud application On API.
- Host: GitHub
- URL: https://github.com/atiqurcode/eloquent-one-to-one
- Owner: AtiqurCode
- Created: 2022-04-05T05:09:04.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-06-22T08:42:32.000Z (almost 3 years ago)
- Last Synced: 2023-03-05T18:21:38.743Z (about 2 years ago)
- Topics: crud-api, crud-application, eloquent, laravel, laravel-8, one-to-one
- Language: PHP
- Homepage:
- Size: 355 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Read One-to-One basics & try with this code as you want
Go throw **laravel documentation** & many more blog
first you need to clone this and save **.env.example as .env** and setup your environment or just change the database configure
```sh
- DB_CONNECTION=mysql
- DB_HOST=127.0.0.1
- DB_PORT=3306
- DB_DATABASE=your-database-name
- DB_USERNAME=your-database-user-name
- DB_PASSWORD=your-database-password(if have)
```Now just run some command on terminal
```sh
composer install
php artisan migrate
php artisan serve
```As I have said this is One to One relationship. //Imagine part
- Example1: A User can have one profile data but can't be multiple
- Example2: Student can have one ID information
- Example3: Office can have one employee profileSo I have just created Two model
- **User**
- **Profile**User Model are relation with hasOne
```sh
public function profile(){
return $this->hasOne(Profile::class);
}
```Profile Model are relation with belongsTo
```sh
public function user()
{
return $this->belongsTo(User::class);
}// You can save return $this->belongsTo(User::class, 'user_id');
relation column name if you didn't follow the convention
```And controller code are depend's on condition what I need. So you can got throw the controller method.
if you have **Postman**/any software like that please import One-to-One.postman_collection.json file either call
```sh
- {url-of-your-app}/api/users --method : get // get all user list with profile
- {url-of-your-app}/api/users/{user} --method : get // get one user by id with profile
- {url-of-your-app}/api/users --method : post // insert user and profile details
- {url-of-your-app}/api/users/{user} --method : put // update user details
- {url-of-your-app}/api/users/{user} --method : delete // delete user and profile details
- {url-of-your-app}/api/profile/{profile} --method : get // get one profile details by id
- {url-of-your-app}/api/profile/{profile} --method : put // update profile details
```