I beginner in Laravel. I use in my project Laravel 5.8. I have this code:
Schema::create('db_id', function (Blueprint $table) {
$table->bigIncrements('id');
$table->unsignedBigInteger('user_id1')->nullable();
$table->foreign('user_id1')->references('id')->on('users')->onDelete('cascade');
$table->unsignedBigInteger('user_id2')->nullable();
$table->foreign('user_id2')->references('id')->on('users')->onDelete('cascade');
$table->string('token', 240);
$table->char('status', 1)->default(0);
$table->dateTime('last_message')->nullable();
$table->dateTime('read_at')->nullable();
$table->engine = "InnoDB";
$table->charset = 'utf8mb4';
$table->collation = 'utf8mb4_unicode_ci';
});
When I run this code:
DbID::where('user_id2', '=', Auth::user()->id)
->orWhere('user_id1', Auth::user()->id)
->orderBy('last_message', 'DESC')
->get();
Sometimes I have duplications.
In my db I have record with user_id2 and user_id1 - Auth::user()->id.
I need show this record only one.
How can I fix it?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2EYxIkr
via IFTTT
Aucun commentaire:
Enregistrer un commentaire