Skip to content

Commit 64a7cf2

Browse files
committed
Most View Products
1 parent 11dfa64 commit 64a7cf2

File tree

5 files changed

+123
-117
lines changed

5 files changed

+123
-117
lines changed

EasyShop/app/recommends.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class recommends extends Model
8+
{
9+
//
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreateRecommendsTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::create('recommends', function (Blueprint $table) {
17+
$table->increments('id');
18+
19+
$table->integer('pro_id');
20+
$table->integer('uid');
21+
22+
$table->timestamps();
23+
});
24+
}
25+
26+
/**
27+
* Reverse the migrations.
28+
*
29+
* @return void
30+
*/
31+
public function down()
32+
{
33+
Schema::drop('recommends');
34+
}
35+
}

EasyShop/resources/views/front/product_details.blade.php

+4-90
Original file line numberDiff line numberDiff line change
@@ -416,96 +416,10 @@
416416
</div>
417417
</div><!--/category-tab-->
418418

419-
<div class="recommended_items"><!--recommended_items-->
420-
<h2 class="title text-center">recommended items</h2>
421-
422-
<div id="recommended-item-carousel" class="carousel slide" data-ride="carousel">
423-
<div class="carousel-inner">
424-
<div class="item active">
425-
<div class="col-sm-4">
426-
<div class="product-image-wrapper">
427-
<div class="single-products">
428-
<div class="productinfo text-center">
429-
<img src="images/home/recommend1.jpg" alt="" />
430-
<h2>$56</h2>
431-
<p>Easy Polo Black Edition</p>
432-
<button type="button" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</button>
433-
</div>
434-
</div>
435-
</div>
436-
</div>
437-
<div class="col-sm-4">
438-
<div class="product-image-wrapper">
439-
<div class="single-products">
440-
<div class="productinfo text-center">
441-
<img src="images/home/recommend2.jpg" alt="" />
442-
<h2>$56</h2>
443-
<p>Easy Polo Black Edition</p>
444-
<button type="button" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</button>
445-
</div>
446-
</div>
447-
</div>
448-
</div>
449-
<div class="col-sm-4">
450-
<div class="product-image-wrapper">
451-
<div class="single-products">
452-
<div class="productinfo text-center">
453-
<img src="images/home/recommend3.jpg" alt="" />
454-
<h2>$56</h2>
455-
<p>Easy Polo Black Edition</p>
456-
<button type="button" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</button>
457-
</div>
458-
</div>
459-
</div>
460-
</div>
461-
</div>
462-
<div class="item">
463-
<div class="col-sm-4">
464-
<div class="product-image-wrapper">
465-
<div class="single-products">
466-
<div class="productinfo text-center">
467-
<img src="images/home/recommend1.jpg" alt="" />
468-
<h2>$56</h2>
469-
<p>Easy Polo Black Edition</p>
470-
<button type="button" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</button>
471-
</div>
472-
</div>
473-
</div>
474-
</div>
475-
<div class="col-sm-4">
476-
<div class="product-image-wrapper">
477-
<div class="single-products">
478-
<div class="productinfo text-center">
479-
<img src="images/home/recommend2.jpg" alt="" />
480-
<h2>$56</h2>
481-
<p>Easy Polo Black Edition</p>
482-
<button type="button" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</button>
483-
</div>
484-
</div>
485-
</div>
486-
</div>
487-
<div class="col-sm-4">
488-
<div class="product-image-wrapper">
489-
<div class="single-products">
490-
<div class="productinfo text-center">
491-
<img src="images/home/recommend3.jpg" alt="" />
492-
<h2>$56</h2>
493-
<p>Easy Polo Black Edition</p>
494-
<button type="button" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</button>
495-
</div>
496-
</div>
497-
</div>
498-
</div>
499-
</div>
500-
</div>
501-
<a class="left recommended-item-control" href="#recommended-item-carousel" data-slide="prev">
502-
<i class="fa fa-angle-left"></i>
503-
</a>
504-
<a class="right recommended-item-control" href="#recommended-item-carousel" data-slide="next">
505-
<i class="fa fa-angle-right"></i>
506-
</a>
507-
</div>
508-
</div><!--/recommended_items-->
419+
<div class="recommended_items"><!--recommended_items-->
420+
<h2 class="title text-center">recommended items</h2>
421+
@include('front.recommends')
422+
</div><!--/recommended_items-->
509423

510424
</div>
511425

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
$products1 = DB::table('recommends')
3+
->leftJoin('products','recommends.pro_id','products.id')
4+
->select('pro_id','pro_name','pro_img','pro_price', DB::raw('count(*) as total'))
5+
->groupBy('pro_id','pro_name','pro_img','pro_price')
6+
->orderby('total','DESC')
7+
->take(3)
8+
->get();
9+
10+
11+
$products2 = DB::table('recommends')
12+
->leftJoin('products','recommends.pro_id','products.id')
13+
->where('uid',Auth::user()->id)
14+
->inRandomOrder()
15+
->take(3)
16+
->get();
17+
18+
?>
19+
<div id="recommended-item-carousel" class="carousel slide" data-ride="carousel">
20+
<div class="carousel-inner">
21+
<div class="item active">
22+
@foreach($products1 as $p)
23+
<div class="col-sm-4">
24+
<div class="product-image-wrapper">
25+
<div class="single-products">
26+
<div class="productinfo text-center">
27+
<a href="{{url('/product_details')}}/{{$p->pro_id}}">
28+
<img src="{{$p->pro_img}}" alt="" /></a>
29+
<h2>${{$p->pro_price}}</h2>
30+
<p> <a href="{{url('/product_details')}}/{{$p->pro_id}}">
31+
{{$p->pro_name}} {{$p->pro_id}}</a></p>
32+
<a href="{{url('/cart/addItem')}}/{{$p->pro_id}}" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>
33+
</div>
34+
35+
</div>
36+
</div>
37+
</div>
38+
@endforeach
39+
</div>
40+
<div class="item">
41+
@foreach($products2 as $p)
42+
<div class="col-sm-4">
43+
<div class="product-image-wrapper">
44+
<div class="single-products">
45+
<div class="productinfo text-center">
46+
<a href="{{url('/product_details')}}/{{$p->pro_id}}">
47+
<img src="{{$p->pro_img}}" alt="" /></a>
48+
<h2>${{$p->pro_price}}</h2>
49+
<p> <a href="{{url('/product_details')}}/{{$p->pro_id}}">
50+
{{$p->pro_name}} {{$p->pro_id}}</a></p>
51+
<a href="{{url('/cart/addItem')}}/{{$p->pro_id}}" class="btn btn-default add-to-cart">
52+
<i class="fa fa-shopping-cart"></i>
53+
Add to cart</a>
54+
</div>
55+
56+
</div>
57+
</div>
58+
</div>
59+
@endforeach
60+
61+
</div>
62+
</div>
63+
<a class="left recommended-item-control" href="#recommended-item-carousel" data-slide="prev">
64+
<i class="fa fa-angle-left"></i>
65+
</a>
66+
<a class="right recommended-item-control" href="#recommended-item-carousel" data-slide="next">
67+
<i class="fa fa-angle-right"></i>
68+
</a>
69+
</div>

EasyShop/routes/web.php

+5-27
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
<?php
22

3-
/*
4-
|--------------------------------------------------------------------------
5-
| Web Routes
6-
|--------------------------------------------------------------------------
7-
|
8-
| This file is where you may define all of the routes that are handled
9-
| by your application. Just tell Laravel the URIs it should respond
10-
| to using a Closure or controller method. Build something great!
11-
|
12-
*/
13-
Route::get('/test', 'HomeController@test');
14-
153
Route::get('/', 'HomeController@index');
164
Route::get('/home', 'HomeController@index');
175

@@ -72,37 +60,27 @@
7260

7361
Route::Post('/catForm', 'AdminController@catForm');
7462
Route::get('/categories', 'AdminController@view_cats');
75-
Route::get('/CatEditForm/ {
76-
id
77-
}', 'AdminController@CatEditForm');
63+
Route::get('/CatEditForm/{id}', 'AdminController@CatEditForm');
7864

7965
Route::post('/editCat', 'AdminController@editCat');
8066

8167

82-
Route::get('ProductEditForm/ {
83-
id
84-
}', 'AdminController@ProductEditForm');
68+
Route::get('ProductEditForm/{id}', 'AdminController@ProductEditForm');
8569

8670

8771
Route::post('editProduct', 'AdminController@editProduct');
8872

89-
Route::get('EditImage/ {
90-
id
91-
}', 'AdminController@ImageEditForm');
73+
Route::get('EditImage/{id}', 'AdminController@ImageEditForm');
9274

9375
Route::post('editProImage', 'AdminController@editProImage');
9476

95-
Route::get('deleteCat/ {
96-
id
97-
}', 'AdminController@deleteCat');
77+
Route::get('deleteCat/{id}', 'AdminController@deleteCat');
9878
});
9979
Route::get('/logout', 'Auth\LoginController@logout');
10080
Route::post('addToWishList', 'HomeController@wishList');
10181
Route::get('/WishList', 'HomeController@View_wishList');
10282

103-
Route::get('/removeWishList/ {
104-
id
105-
}', 'HomeController@removeWishList');
83+
Route::get('/removeWishList/{id}', 'HomeController@removeWishList');
10684
//Route::get('/admin', 'AdminController@index');
10785

10886

0 commit comments

Comments
 (0)