我正在尝试在我的laravel应用程序中开发一个消息传递系统,我已经设法向用户发送消息并在我的刀片视图的收件箱部分中检索它们。所以我的疑问是,我将如何回复收件箱中的邮件?
这是我在mail.blade.php
中的方式<table class="table table-inbox table-hover">
@foreach($messages as $meso => $message)
<tbody>
<tr class="unread">
<td class="inbox-small-cells">
<input type="checkbox" class="mail-checkbox">
</td>
<td class="inbox-small-cells"><i class="fa fa-star"></i></td>
<td class="view-message dont-show">{{ $message->sent_to_id }}</td>
<td class="view-message dont-show">{{ $message->name }}</td>
<td class="view-message dont-show">{{ $message->subject }}</td>
<td class="view-message view-message"><p>{{ $message->body }}</p></td>
<td class="view-message inbox-small-cells"><i class="fa fa-paperclip"></i></td>
<td class="view-message text-right">{{ $message->created_at }}</td>
<td class="view-message dont-show"><button data-toggle="modal" data-target="#squarespaceModal" class="btn btn-primary center-block">Reply</button></td>
</tr>
</tbody>
@endforeach
</table>
我的用户模型是:
<?php
namespace App;
use App\Http\Controllers;
use App\Message;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
public function sendMessageTo($recipient, $message, $subject)
{
Auth::user()->sendMessageTo($request->recipient, $request->subject, $request->body);
}
protected $fillable = ['name', 'email', 'password'];
// A user can send a message
public function sent()
{
return $this->hasMany(Message::class, 'sender_id');
}
// A user can also receive a message
public function received()
{
return $this->hasMany(Message::class, 'sent_to_id');
}
public function message()
{
return $this->belongsTo(Message::class);
}
public function user()
{
return $this->belongsTo(User::class);
}
}
,这是我的消息模型:
<?php
namespace App;
use App\User;
use Illuminate\Database\Eloquent\Model;
class Message extends Model
{
protected $fillable = ['body', 'subject', 'sent_to_id', 'sender_id'];
// A message belongs to a sender
public function sender()
{
return $this->belongsTo(User::class, 'sender_id');
}
// A message also belongs to a receiver
public function receiver()
{
return $this->belongsTo(User::class, 'sent_to_id');
}
public function user()
{
return $this->belongsTo(User::class);
}
public function message()
{
return $this->belongsTo(Message::class);
}
} 我的MessageController
public function sendMessage(Request $request)
{
// Do the validation...
// Send the message from the current user to the user with ID of 1,
// You probably always want the current logged-in user as the sender.
// We talk about the recipient later...
//
Auth::user()->sent()->create([
'body' => $request->body,
'subject' => $request->subject,
'sent_to_id' => $request->recipient,
]);
$messages = Message::where('sent_to_id', '=', Auth::user()->name)->get();
$users = User::where('id', '!=', Auth::id())->get()->pluck('name', 'id');
return view('mail')->with(compact('messages', 'users'));
}
有关如何回复此邮件的任何提示