Hi people of laravel.io,
I would like a messaging system on the app I am developing but I am very new to the Laravel framework and MVC of any form ....
Here is the part of migration that I am building at the moment for "call_logs".
Basically the idea of "call logs" as you can imagine is a call logging part of the program, the user that takes the call will take information and then send that info to the appropriate people.
Schema::table('call_logs', 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->string('title');
$table->string('subject');
$table->text('content', 2000);
$table->softDeletes();
$table->timestamps();
});
So I need 'to' to be some sort of array of users to send to, how is this achieved, also I don't want to have to come across the n+1 issue with saving the same message for multiple users.....how do I get around this.
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
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:
call_log_messages
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.
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);
});
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community