Skip to content

Commit

Permalink
Products reviews was added
Browse files Browse the repository at this point in the history
  • Loading branch information
vilgefortzz committed Apr 29, 2017
1 parent 52fa2b1 commit 5815e40
Show file tree
Hide file tree
Showing 12 changed files with 447 additions and 13 deletions.
18 changes: 17 additions & 1 deletion app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@

namespace App\Http\Controllers;

use App\Product;
use App\Review;
use Auth;
use Illuminate\Http\Request;

class ProductController extends Controller
{
//
public function show(Product $product){

// Get all reviews for this product
$reviews = $product->reviews;

// Check if has user already given a review to this product
if (Auth::check()){
$isGiven = $reviews->contains('user_id', Auth::user()->id);
return view('product_details', compact('product', 'isGiven', 'reviews'));
}

return view('product_details', compact('product', 'reviews'));

}
}
33 changes: 33 additions & 0 deletions app/Http/Controllers/ReviewController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Http\Controllers;

use App\Product;
use App\Review;
use Auth;
use Illuminate\Http\Request;

class ReviewController extends Controller
{
public function store(Product $product, Request $request){

/*
* Validate review
*/
$this->validate($request, [
'review' => 'min:5|max:1000',
]);

$user = Auth::user();

// Create new review for user and product

$review = new Review();
$review->review = $request->review;
$review->user_id = $user->id;
$review->product_id = $product->id;
$review->save();

return back();
}
}
5 changes: 5 additions & 0 deletions app/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public function subcategory()
return $this->belongsTo('App\Subcategory');
}

public function reviews()
{
return $this->hasMany('App\Review');
}

public function items()
{
return $this->hasMany('App\Item');
Expand Down
2 changes: 1 addition & 1 deletion database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
return [
'subcategory_id' => rand(1, 7),
'name' => $faker->unique()->word,
'description' => $faker->text(50),
'description' => $faker->text(800),
'price' => $faker->randomFloat(2, 150, 900)
];
});
64 changes: 63 additions & 1 deletion public/css/app.css

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11264,6 +11264,54 @@ $(document).ready(function () {
} else {
localStorage.clear();
}

var orig_height = $('#review_text_area').height();
var new_height = 150;

$('#review_text_area').on('focus', function () {

$(this).animate({ height: new_height + 'px' });
});

$('#review_text_area').on('blur', function () {

$(this).animate({ height: orig_height + 'px' });
});

$('#give_review_this_page').on('click', function () {
if ($('#write_review').length != 0) {
$('html, body').animate({
scrollTop: $('#write_review').offset().top - 170
}, 800);

$('#review_text_area').focus();
} else {
$('html, body').animate({
scrollTop: $('#review_given').offset().top - 170
}, 800);
}
});

$('.give_review').on('click', function () {

sessionStorage.setItem('hash', 'write_review');
});

if (sessionStorage.length > 0) {
if ($('#write_review').length != 0) {
$('html, body').animate({
scrollTop: $('#write_review').offset().top - 170
}, 800);

$('#review_text_area').focus();
} else {
$('html, body').animate({
scrollTop: $('#review_given').offset().top - 170
}, 800);
}

sessionStorage.clear();
}
});
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(1)))

Expand Down
50 changes: 50 additions & 0 deletions resources/assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,54 @@ $(document).ready(function() {
else {
localStorage.clear();
}

var orig_height = $('#review_text_area').height();
var new_height = 150;

$('#review_text_area').on('focus', function(){

$(this).animate({height: new_height + 'px'});
});

$('#review_text_area').on('blur', function(){

$(this).animate({height: orig_height + 'px'});
});

$('#give_review_this_page').on('click', function() {
if($('#write_review').length != 0) {
$('html, body').animate({
scrollTop: $('#write_review').offset().top - 170
}, 800);

$('#review_text_area').focus();
}
else{
$('html, body').animate({
scrollTop: $('#review_given').offset().top - 170
}, 800);
}
});

$('.give_review').on('click', function () {

sessionStorage.setItem('hash', 'write_review');
});

if (sessionStorage.length > 0){
if($('#write_review').length != 0) {
$('html, body').animate({
scrollTop: $('#write_review').offset().top - 170
}, 800);

$('#review_text_area').focus();
}
else{
$('html, body').animate({
scrollTop: $('#review_given').offset().top - 170
}, 800);
}

sessionStorage.clear();
}
});
64 changes: 64 additions & 0 deletions resources/assets/sass/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,68 @@ body{

.trash-remove:focus{
color: black;
}

// Text area to write reviews

.textarea_review{
border: 2px solid black;
border-radius: 8px;
width: 70%;
height: 45px;
}

.textarea_review:focus{
outline:none;
}

.vertical-space{
margin-top: 50px;
}

// Reviews formatting

.panel-review {
position:relative;
border-color: black;
}

.thumbnail-user{
margin-top: 4px;
}

.panel-heading{
font-size: 14px;
border: none;
}

.panel > .panel-heading-review:after, .panel > .panel-heading-review:before{
position:absolute;
top:11px;left:-16px;
right:100%;
width:0;
height:0;
display:block;
content:" ";
border-color:transparent;
border-style:solid solid outset;
pointer-events:none;
}

.panel >.panel-heading-review:after{
border-width:7px;
border-right-color: white;
margin-top:1px;
margin-left:2px;
}

.panel>.panel-heading-review:before{
border-right-color: black;
border-width:8px;
}

#review_given{
font-size: 30px;
color: #780014;
background-color: white;
}
21 changes: 14 additions & 7 deletions resources/views/main_page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<h2 class="group inner list-group-item-heading">
<b>
{{$recommendedProduct->name}}
<a href="#" style="font-size: 18px">
<a href="{{ url('/products/'.$recommendedProduct->id) }}" style="font-size: 18px">
<span class="glyphicon glyphicon-triangle-right"></span>See details
</a>
</b>
Expand All @@ -88,16 +88,23 @@
<div class="row" style="margin-top: 50px">
<div class="col-xs-12 col-md-4">
<p><b>Buy now:</b></p>
<p class="lead_main"><b>${{$recommendedProduct->price}}</b></p>
<p class="lead_main"><b>{{$recommendedProduct->price}}$</b></p>
</div>
<div class="col-xs-12 col-md-6">
<a id="{{$recommendedProduct->id}}" class="btn btn-success add_to_cart" href="{{ url('/cart/add/'.$recommendedProduct->id) }}">
<span class="glyphicon glyphicon-shopping-cart"></span>Add to cart
<a id="add_{{$recommendedProduct->id}}" class="add_to_cart" href="{{ url('/cart/add/'.$recommendedProduct->id) }}">
<span class="glyphicon glyphicon-shopping-cart"></span><b>Add to cart</b>
</a>

{{-- Hidden link - dynamically change--}}
<a id="remove_{{$recommendedProduct->id}}" class="remove_from_cart" href="{{ url('/cart/delete/'.$recommendedProduct->id) }}" hidden>
<span class="glyphicon glyphicon-remove"></span><b>Remove</b>
</a>

{{--For autheniticated users--}}
@if(Auth::check())
<a class="btn btn-warning" href="#" style="margin-top: 3px">
<span class="glyphicon glyphicon-comment"></span>Give a review
<br>
<a class="give_review" href="{{ url('/products/'.$recommendedProduct->id) }}">
<span class="glyphicon glyphicon-comment"></span><b>Give a review</b>
</a>
@endif
</div>
Expand All @@ -116,6 +123,6 @@
{{-- AJAX scripts--}}

<script src="{{ asset('js/add_to_cart_ajax.js') }}"></script>
<script src="{{ asset('deldelete_from_cart_view_products_ajax.jscts_ajax.js') }}"></script>
<script src="{{ asset('js/delete_from_cart_view_products_ajax.js') }}"></script>

@endsection
Loading

0 comments on commit 5815e40

Please sign in to comment.