Skip to content

Commit

Permalink
Gallery of images with zoom effect was added to the product panel . I…
Browse files Browse the repository at this point in the history
…mprovements in appearance of the page and better working
  • Loading branch information
vilgefortzz committed May 29, 2017
1 parent ea18493 commit e054661
Show file tree
Hide file tree
Showing 48 changed files with 3,323 additions and 356 deletions.
9 changes: 6 additions & 3 deletions app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public function show(Product $product){
// Get all reviews for this product and sort reviews by date from the newest one
$reviews = Review::where('product_id', $product->id)->orderBy('created_at', 'desc')->paginate(2);

// Get all images( gallery ) for this product
$images = $product->images;

// Check if has user already given a review to this product and if has user ordered this product
if (Auth::check()){

Expand All @@ -25,10 +28,10 @@ public function show(Product $product){
$isOrdered = true;
}
}
return view('products.product_details', compact('product', 'isGiven', 'isOrdered', 'reviews'));
return view('products.product_details', compact('product', 'images', 'isGiven', 'isOrdered', 'reviews'));
}

return view('products.product_details', compact('product', 'reviews'));
return view('products.product_details', compact('product', 'images', 'reviews'));
}

public function search(Request $request){
Expand All @@ -43,7 +46,7 @@ public function search(Request $request){

$output .= '<li>'.
'<a href="/products/'.$product->id.'" class = "nice_links">'.
'<img src="'.$product->path_to_image.'" width="50" height="50">'.
'<img src="'.$product->path_to_thumbnail.'" width="50" height="50">'.
'<b>'.$product->name.'</b>'.
'</a>'.
'</li>';
Expand Down
13 changes: 13 additions & 0 deletions app/Image.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Image extends Model
{
public function products()
{
return $this->belongsToMany('App\Product', 'products_images');
}
}
5 changes: 5 additions & 0 deletions app/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ public function orderProducts()
{
return $this->hasMany('App\OrderProduct');
}

public function images()
{
return $this->belongsToMany('App\Image', 'products_images');
}
}
6 changes: 6 additions & 0 deletions database/factories/ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@
'name' => $faker->unique()->word
];
});

$factory->define(App\Image::class, function (Faker\Generator $faker) {

return [
];
});
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function up()
$table->increments('id');
$table->string('name', 30)->unique();
$table->string('description', 50)->nullable();
$table->string('path_to_image')->default('/images/missing.png');
$table->string('path_to_thumbnail')->default('/images/missing.png');
$table->float('price')->unsigned();
$table->integer('quantity')->unsigned()->nullable();
$table->boolean('recommended')->default(false);
Expand Down
33 changes: 33 additions & 0 deletions database/migrations/2017_05_28_162555_create_images_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateImagesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('images', function (Blueprint $table) {
$table->increments('id');
$table->string('path_to_image')->default('/images/missing.png');
$table->string('path_to_thumbnail')->default('/images/missing.png');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('images');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProductsImagesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('products_images', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();

$table->integer('product_id')->index()->unsigned();
$table->foreign('product_id')->references('id')->on('products')
->onDelete('cascade');

$table->integer('image_id')->index()->unsigned();
$table->foreign('image_id')->references('id')->on('images')
->onDelete('cascade');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('products_images');
}
}
1 change: 1 addition & 0 deletions database/seeds/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public function run()
//$this->call(ReviewsTableSeeder::class);
$this->call(DeliveriesTableSeeder::class);
$this->call(PaymentsTableSeeder::class);
$this->call(ImagesTableSeeder::class);
}
}
45 changes: 45 additions & 0 deletions database/seeds/ImagesTableSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

use App\Image;
use App\Product;
use Illuminate\Database\Seeder;

class ImagesTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$products = Product::all();

foreach ($products as $product) {

// Gallery of images ( high resolutions )
$productImagesHighRes = [
'/images/galleries/'.$product->subcategory->name.'/'.$product->id.'/1.jpg',
'/images/galleries/'.$product->subcategory->name.'/'.$product->id.'/2.jpg',
'/images/galleries/'.$product->subcategory->name.'/'.$product->id.'/3.jpg'
];

// Gallery of images ( low resolutions - thumbnails )
$productImagesLowRes = [
'/images/galleries/'.$product->subcategory->name.'/'.$product->id.'/1_tb.jpg',
'/images/galleries/'.$product->subcategory->name.'/'.$product->id.'/2_tb.jpg',
'/images/galleries/'.$product->subcategory->name.'/'.$product->id.'/3_tb.jpg'
];

for ($i = 0; $i < count($productImagesHighRes); $i++) {

$image = factory(Image::class)->create([
'path_to_image' => $productImagesHighRes[$i],
'path_to_thumbnail' => $productImagesLowRes[$i]
]);

$product->images()->attach($image->id);
}
}
}
}
28 changes: 17 additions & 11 deletions database/seeds/ProductsTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@ class ProductsTableSeeder extends Seeder
public function run()
{

$productsToSwords = ['miecz jednoręczny - dekoracyjny', 'miecz jednoręczny - dekoracyjny2', 'miecz jednoręczny - dekoracyjny3',
'miecz jednoręczny - dekoracyjny4', 'miecz jednoręczny - dekoracyjny5', 'miecz jednoręczny - dekoracyjny6', 'miecz jednoręczny - szczerbiec'];
$productsToSwords = [
'FINE AND RARE BOLIVIAN OFFICER’S SWORD',
'miecz jednoręczny - dekoracyjny2', 'miecz jednoręczny - dekoracyjny3',
'miecz jednoręczny - dekoracyjny4', 'miecz jednoręczny - dekoracyjny5', 'miecz jednoręczny - dekoracyjny6', 'miecz jednoręczny - szczerbiec'
];

$productsToAxes = ['axe'];
$productsToShields = ['legion shield'];
$productsToHelmets = ['helmet'];

$swordsImages = ['/images/swords/1.jpg', '/images/swords/2.JPG', '/images/swords/3.JPG',
'/images/swords/4.jpg', '/images/swords/5.JPG', '/images/swords/6.jpg', '/images/swords/7.jpg'];
$swordsThumbnails = [
'/images/thumbnails/swords/1.jpg', '/images/thumbnails/swords/2.jpg', '/images/thumbnails/swords/3.jpg',
'/images/thumbnails/swords/4.jpg', '/images/thumbnails/swords/5.jpg', '/images/thumbnails/swords/6.jpg', '/images/thumbnails/swords/7.jpg'
];

$axesImages = ['/images/axes/axe.JPG'];
$shieldsImages = ['/images/shields/legion_shield.jpg'];
$helmetsImages = ['/images/helmets/helmet.jpg'];
$axesThumbnails = ['/images/thumbnails/axes/axe.jpg'];
$shieldsThumbnails = ['/images/thumbnails/shields/legion_shield.jpg'];
$helmetsThumbnails = ['/images/thumbnails/helmets/helmet.jpg'];

$subcategories = Subcategory::all();

Expand All @@ -38,7 +44,7 @@ public function run()
factory(Product::class)->create([
'subcategory_id' => $subcategorySwords->id,
'name' => $productsToSwords[$i],
'path_to_image' => $swordsImages[$i],
'path_to_thumbnail' => $swordsThumbnails[$i],
'quantity' => 5
]);
}
Expand All @@ -47,7 +53,7 @@ public function run()
factory(Product::class)->create([
'subcategory_id' => $subcategoryAxes->id,
'name' => $productsToAxes[$i],
'path_to_image' => $axesImages[$i],
'path_to_thumbnail' => $axesThumbnails[$i],
'quantity' => 8
]);
}
Expand All @@ -56,7 +62,7 @@ public function run()
factory(Product::class)->create([
'subcategory_id' => $subcategoryShields->id,
'name' => $productsToShields[$i],
'path_to_image' => $shieldsImages[$i],
'path_to_thumbnail' => $shieldsThumbnails[$i],
'quantity' => 14
]);
}
Expand All @@ -65,7 +71,7 @@ public function run()
factory(Product::class)->create([
'subcategory_id' => $subcategoryHelmets->id,
'name' => $productsToHelmets[$i],
'path_to_image' => $helmetsImages[$i],
'path_to_thumbnail' => $helmetsThumbnails[$i],
'quantity' => 3
]);
}
Expand Down
66 changes: 64 additions & 2 deletions public/css/app.css

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions public/css/font-awesome/font-awesome.min.css

Large diffs are not rendered by default.

Binary file added public/css/fonts/FontAwesome.otf
Binary file not shown.
Binary file added public/css/fonts/fontawesome-webfont.eot
Binary file not shown.
Loading

0 comments on commit e054661

Please sign in to comment.