教你使用laravel-like-comment評(píng)論插件

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

下面由laravel教程欄目給大家介紹laravel-like-comment評(píng)論插件的使用,希望對(duì)需要的朋友有所幫助!

教你使用laravel-like-comment評(píng)論插件

Laravel like comment

laravel-like-comment 是一款基于ajax的laravel評(píng)論系統(tǒng).用戶(hù)需要登錄后對(duì)自己喜歡文章或者其它模塊進(jìn)行評(píng)論、點(diǎn)贊.

功能

  • 喜歡
  • 不喜歡
  • 評(píng)論
  • 對(duì)評(píng)論信息 支持與否
  • 用戶(hù)頭像

安裝

運(yùn)行

composer?require?risul/laravel-like-comment

配置服務(wù)

在 你的 service providerr 列表中添加

risulLaravelLikeCommentLikeCommentServiceProvider::class

發(fā)布配置服務(wù)

php?artisan?vendor:publish

遷移數(shù)據(jù)表,并創(chuàng)建評(píng)論等相關(guān)聯(lián)的數(shù)據(jù)表.

php?artisan?migrate

在你需要評(píng)論的頁(yè)面head中添加評(píng)論css樣式.

????<link> ????<link> ????<link> ????<link> ????<link>

添加 jquery 和 script

注意:因原文中jquery使用到 google資源 這里我修改成國(guó)內(nèi)的。

????<script></script> ????<script></script>

在 config/laravelLikeComment.php 加入 user 模型 路徑

注意:看好自己的user模型路徑,是否修改,默認(rèn)路徑是下面的。

'userModel'?=&gt;?'AppUser'

在你的 user 模型中加入下面的代碼.

????/** ?????*?Return?the?user?attributes.  ?????*?@return?array ?????*/ ????public?static?function?getAuthor($id) ????{ ????????$user?=?self::find($id); ????????return?[ ????????????'id'?????=&gt;?$user-&gt;id, ????????????'name'???=&gt;?$user-&gt;name, ????????????'email'??=&gt;?$user-&gt;email, ????????????'url'????=&gt;?'',??//?Optional ????????????'avatar'?=&gt;?'gravatar',??//?Default?avatar ????????????'admin'??=&gt;?$user-&gt;role?===?'admin',?//?bool ????????]; ????}

使用

在你想要添加點(diǎn)贊的頁(yè)面中加入下面代碼.

@include('laravelLikeComment::like',?['like_item_id'?=&gt;?'image_31'])

like_item_id: 是將要整合所在模塊的標(biāo)記 id .

比如,我想要在文章post模型,文章展示頁(yè)面添加此功能,并在數(shù)據(jù)表中標(biāo)記下來(lái),這條數(shù)據(jù)的詳細(xì)信息,可以這樣組合標(biāo)記 post_1(post為文章模型,1為文章id)。
引用后如下:

@include('laravelLikeComment::like',?['like_item_id'?=&gt;?"post_".$post-&gt;id])

在你想要添加評(píng)論的模塊中添加下面代碼:

標(biāo)記方式如上

@include('laravelLikeComment::comment',?['comment_item_id'?=&gt;?'video_12'])

comment_item_id: 是將要整合所在模塊的評(píng)論標(biāo)記 id .? ? ? ? ? ? ??? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

以上就是教你使用

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊13 分享