Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Hello,

I see different approaches.

1-JSON object as the var kept in the schema you show. It's the best way, IMHO, to save an array in a database column.

2-Pivot table, meaning there would be table "call_log_to_recepients" table. two columns, call_log_id and to_user_id. both columns would make a composite key on the schema. (to garantee uniqueness) means you would have something like:

# call_log_id # to_user_id #
# 1               #     4
# 1               #     5
# 2               #     4

1st log means went to user 4 and 5 2nd log went to user 4 .... i guess you can take it from here!

This way you can hit the database much easier than with the json object! ;)

Cheers

Last updated 9 years ago.
0

I have gave it more thought and I have come up with a new approach, why couldn't I just have two tables:

call_logs:

  • id
  • to
  • from
  • message_id(call_log_messages->id)
  • taken_by

call_log_messages

  • id
  • call_log_id (call_logs->id)
  • message_content

Then say a user takes a call, writes out a message, sends it to bill, mark, bob, the code will save the "message" 3 times with the same "message_id" but with different "to" each time then the message content gets saved in "call_log_messages".

Then if the user deletes there message, all they are really doing is removing their row from "call_logs"

If this will work, is this "supported" with frameworks like Laravel how would I do this in Laravel, or where would I go to find out.

Last updated 9 years ago.
0

So now my schema looks like:

	Schema::table('messages', function(Blueprint $table)
	{
		$table->integer('id')->primary();

		$table->integer('taken_by')->unsigned();
		$table->foreign('taken_by')->references('id')->on('users');

		$table->integer('to')->unsigned();
		$table->foreign('to')->references('id')->on('users');

		$table->integer('content_id')->unsigned();
		$table->foreign('content_id')->references('id')->on('message_contents');

		$table->string('title');
		$table->string('subject');
		
		$table->softDeletes();
		$table->timestamps();
	});
	Schema::table('message_contents', function(Blueprint $table)
	{
		$table->integer('id')->primary();

		$table->text('content', 2000);
	});
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.