https://github.com/meedeley/deep_talk_about_relationship
learn laravel about relationship
https://github.com/meedeley/deep_talk_about_relationship
intermediate-projects laravel pivot-tables
Last synced: about 1 year ago
JSON representation
learn laravel about relationship
- Host: GitHub
- URL: https://github.com/meedeley/deep_talk_about_relationship
- Owner: meedeley
- Created: 2025-01-19T16:58:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-04T18:28:54.000Z (over 1 year ago)
- Last Synced: 2025-02-04T19:35:45.042Z (over 1 year ago)
- Topics: intermediate-projects, laravel, pivot-tables
- Language: PHP
- Homepage:
- Size: 96.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ngulik Laravel
1. With - Digunakan untuk eager loading relasi sebelum query dijalankan, cocok jika relasi sudah pasti diperlukan sejak awal untuk mencegah N+1 query dan meningkatkan efisiensi.
2. Load - Digunakan untuk eager loading relasi setelah query dijalankan, berguna jika kebutuhan meload relasi baru diputuskan setelah data utama diambil.
3. Pluck - Mengambil semua nilai dari satu kolom dalam tabel.
4. Find - Mencari Id Table
5. Cookie - Data Simpan Disisi Client
6. Session - Data Disimpan Disisi Server
7. toJson - Mengubah data menjadi format JSON string.
8. toArray - Mengubah data menjadi format array PHP.
9. json_encode - Mengubah data PHP (array atau objek) menjadi string JSON.
10. json_decode - Mengubah string JSON menjadi data PHP (array atau objek).
## Mempelajari Relasi One To One
```
- Migrations Sellers
Schema::create('sellers', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
```
```
- Migration Cities
Schema::create('cities', function (Blueprint $table) {
$table->id();
$table->foreignId('seller_id')->unique()->constrained();
$table->string('name');
$table->timestamps();
});
```
```
- Relasi Model Seller
Class Seller extends Model {
...
public function city(): HasOne
{
return $this->hasOne(City::class, 'seller_id', 'id');
}
}
```
```
- Relasi Model City
Class City extends Models {
...
public function seller(): BelongsTo
{
return $this->belongsTo(Seller::class, 'seller_id', 'id');
}
}
```
## Mempelajari Relasi One To Many
## Mempelajari Relasi Many To Many
### Intermediate Table
### Pivot Table
### Attach
### Detach
### Sync
### UpdateExistingPivot