Armin Rahmati
4 سال پیش توسط Armin Rahmati مطرح شد
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>

ثبت پرسش جدید
حسام موسوی
تخصص : طراح و برنامه نویس
@hesammousavi 4 سال پیش مطرح شد
0

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

      return \request()->all();

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


Armin Rahmati
@arminrahmati999 4 سال پیش آپدیت شد
0

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

commentable_id 

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


علی بیات
تخصص : توسعه دهنده ارشد وب
@ali.bayat 4 سال پیش مطرح شد
0

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

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

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

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


Armin Rahmati
@arminrahmati999 4 سال پیش مطرح شد
0

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


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

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