Skip to content
Snippets Groups Projects
Commit 3e1ed675 authored by David's avatar David
Browse files

add notification (not completed)

parent 4b09095b
No related merge requests found
Pipeline #2856 skipped
......@@ -10,6 +10,7 @@ use App\Model\VendorUser;
use App\Model\VendorRateAndReview;
use App\Model\ObjectSell;
use App\Model\Recommendation;
use App\Model\Notification;
use Auth;
class VendorUserController extends Controller
......@@ -33,6 +34,8 @@ class VendorUserController extends Controller
$loggedInUserId = Auth::user()['id'];
$isRecommended = count(Recommendation::getRecommendation($loggedInUserId, $vendorId))>0;
$recommendationReceivedSinceLastRead = $loggedInUserId === $vendorId?Notification::countRecommendationReceivedSinceLastRead($vendorId):0;
return view('vendorUser', [
'editable' => $editable,
'user' => $user,
......@@ -42,6 +45,7 @@ class VendorUserController extends Controller
'userId' => $loggedInUserId,
'vendorId' => $vendorId,
'recommendation' => $recommendation,
'recommendationReceivedSinceLastRead' => $recommendationReceivedSinceLastRead,
'isRecommended' => $isRecommended]);
}
......
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use App\Model\Recommendation;
use App\User;
class Notification extends Model
{
protected $table = 'notification';
public static function getLastNotificationReadTime($vendorId){
$time = Notification::
where('vendor_id', '=', $vendorId)
->first();
if(count($time) == 0){
$model = new Notification;
$model->vendor_id = $vendorId;
$model->save();
echo $model;
return $model['updated_at'];
} else {
return $time['updated_at'];
}
}
public static function countRecommendationReceivedSinceLastRead($vendorId) {
$lastRead = Notification::getLastNotificationReadTime($vendorId);
return Recommendation::
where('vendor_id', '=', $vendorId)
->where('updated_at', '>', $lastRead)
->get()
->count('vendor_id');
}
}
......@@ -31,7 +31,7 @@ class Recommendation extends Model
return Recommendation::
where('vendor_id', '=', $vendorId)
->get()
->sum('vendor_id');
->count('vendor_id');
}
}
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class Notification extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('notification', function (Blueprint $table) {
$table->integer('vendor_id');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
{{ $notif = isset($recommendationReceivedSinceLastRead)? $recommendationReceivedSinceLastRead:0}}
<li class="dropdown">
<a href="#" data-toggle="dropdown" class="dropdown-toggle">
<i class="icon-bdg_alert text14"></i>
<span class="visible-xs-inline">Notifikasi</span>
<span class="badge badge-sm up bg-dark pull-right-xs">1</span>
<span class="badge badge-sm up bg-dark pull-right-xs">{{ $notif }}</span>
</a>
<!-- dropdown -->
<div class="dropdown-menu w-xl animated fadeIn">
<div class="panel bg-white">
<div class="panel-heading b-light bg-light">
<strong>Kamu Punya <span>1</span> Notifikasi</strong>
<strong>Kamu Punya <span>{{ $notif?1:0 }}</span> Notifikasi baru</strong>
</div>
<div class="list-group" {{ $notif?"":"hidden" }} >
<a href class="list-group-item">
<span class="clear block m-b-none">
{{ $notif }} user merekomendasikanmu<br>
</span>
</a>
</div>
<div class="list-group">
<a href class="list-group-item">
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment