Edit app\Providers\AppServiceProvider.php
use Illuminate\Support\Facades\Schema; public function boot() { Schema::defaultStringLength(191); }
filament install : https://filamentphp.com/docs/2.x/admin/installation#requirements
composer require filament/filament:"^2.0"
แก้ไขไฟล์ composer.json เพิ่มบรรทัดนี้
"post-update-cmd": [ // ... "@php artisan filament:upgrade" ],
CMD สั่ง migrate ตารางข้อมูล
php artisan migrate
CMD สั่ง สร้าง user
php artisan make:filament-user admin admin@admin.com admin12345
php artisan serve
ทดสอบ Login
http://127.0.0.1:8000/admin
File Storage – https://laravel.com/docs/10.x/filesystem#main-content
php artisan storage:link
สร้าง Model และ migration file – Category และ Post
**ใช้เอกพจน์ และ -m เพื่อสร้าง migration file โดยชื่อตารางจากถูกแปลงเป็นพหุพจน์ให้อัตโนมัติ
php artisan make:model Category -m php artisan make:model Post -m
สร้าง Model และ migration file – CategoryPost ใช้สำหรับเชื่อม Category และ Post
สำหรับความสัมพันธ์ แบบ many to many
** ใช้เอกพจน์ และเรียงตามลำดับอักษร
php artisan make:model CategoryPost -m
php artisan migrate
Many To Many Relationships
เราไม่สามารถ ใส่ category_id ลงใน ตาราง posts ได้ เพราะจะหมายถึง 1 category สามารถ มีได้แค่ 1 user
ดังนั้น ต้องต้องมีตาราง และ model CategoryPost และตารางนี้จะอยู่ในรูปของ เอกพจน์