dimanche 5 janvier 2020

How to create a Polymorphic Relationship for Notification? (laravel)

This is my first time to use Polymorphic Relationship. I plan to make a one to many relationship. So this is what I done so far.

I created three tables: User, Message, and Notification:

Heres the migration for the Notification:

Schema::create('notifications', function (Blueprint $table) {
    $table->bigIncrements('id');
    $table->char('title');
    $table->string('body', 10000)->nullable();
    $table->unsignedBigInteger('causer_id'); //creator for notification
    $table->char('causer');
    $table->unsignedBigInteger('subject_id'); //receiver for notification
    $table->char('subject');
    $table->timestamps();
});

I expect values something like this:

enter image description here


My problem is, I am really confuse how to make my model relationship, and how to create a model function for these things below:
  1. to create notifications
  2. to view notifications
  3. to edit a specific notification

Any ideas Sirs or suggestion to achieve these. Thanks in adv.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire