راکت

کامنت در وب سایت

4 پاسخ

سلام.
دوستان چرا

commentable_id

نال برمیگردونه؟

{
"_token": "t0sh0tp2QOmZar9TbF3sK0VfuVLB4drJ0keximzI",
"parent_id": "0",
"commentable_id": null,
"commentable_type": "App\\Article",
"comment": "مقاله خوبی بود."
}
Schema::create('comments', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('parent_id')->default(0);
            $table->text('comment');
            $table->unsignedInteger('commentable_id');
            $table->string('commentable_type');
            $table->timestamps();
        });
public function comment() {
        $this->validate(request(),[
           'comment' => 'required|min:5'
        ]);

        return \request()->all();

    }
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{

    protected $fillable = ['user_id' , 'parent_id' , 'comment' , 'commentable_id' , 'commentable_type'];

    public function commentable()
    {
        return $this->morphTo();
    }
}
<form role="form" action="/comment" method="post">
                            {{ csrf_field() }}
                            <input type="hidden" name="parent_id" value="0">
                            <input type="hidden" name="commentable_id" value="{{ $article->id }}">
                            <input type="hidden" name="commentable_type" value="{{ get_class($article) }}">
                            <div class="form-group">
                                <textarea name="comment" class="form-control" rows="3"></textarea>
                            </div>
                            <button type="submit" class="btn btn-primary">ارسال</button>
                        </form>
ثبت پرسش جدید

پاسخ‌ها

4
حسام موسوی
حسام موسوی
@hesammousavi

تخصص: طراح و برنامه نویس

زمانی که میگید

      return \request()->all();

تمام اطلاعات رو درست بر میگردونه ؟

Armin Rahmati
Armin Rahmati
@arminrahmati999

@hesammousavi
بله همه ی اطلاعات رو درست برمیگردونه، فقط

commentable_id 

رو نال برمیگردونه.

شاید پاسخ شما همین‌جا باشد

علی بیات
علی بیات
@ali.bayat

تخصص: توسعه دهنده ارشد وب

میتونید از پکیج زیر استفاده کنید..
خیلی ساده است و مستندات هم کامله

https://github.com/AliBayat/Laravel-Commentable

میتونی باهاش کامنت ها رو با و یا بدون Parent به هر مدلی اضافه کنی
مثلا برای Post ها, Video ها و غیره..

در حال حاظر با لاراول ۶ سازگاره اما تا یکی ۲ روز آینده لاراول ۷ رو هم ساپورت میکنه

Armin Rahmati
Armin Rahmati
@arminrahmati999

من پروژم لاراول 7 هست.
میخوام ببینم کد خودم چرا نال برمیگردونه؟

برای ارسال پاسخ لازم است وارد شده یا ثبت‌نام کنید

ورود یا ثبت‌نام