コード例 #1
0
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('product_snapshot', function (Blueprint $table) {
         $table->increments('id');
         $table->integer('product_id')->default(0);
         $table->integer('snapshot_id')->default(0);
         $table->timestamps();
     });
     // rows have been stored in a comma delimited list, get them out and store in db
     $snapshots = Snapshot::orderBy('created_at', 'asc')->get();
     foreach ($snapshots as $snapshot) {
         if ($snapshot->snapshot_products != '') {
             $products = explode(',', $snapshot->snapshot_products);
             if (count($products)) {
                 foreach ($products as $product) {
                     $snapshot->products()->attach($product);
                 }
             }
         }
     }
 }
コード例 #2
0
 /**
  * Display a gallery of all of the snapshots
  *
  * @param  Request  $request
  * @return Response
  */
 public function gallery(Request $request)
 {
     $query = Snapshot::orderBy('created_at', 'desc');
     if ($request->from_date) {
         $query->where('purchase_date', '>=', date('Y-m-d', strtotime($request->from_date)));
     }
     if ($request->to_date) {
         $query->where('purchase_date', '<=', date('Y-m-d', strtotime($request->to_date)));
     }
     $snapshots = $query->get();
     return view('snapshots.gallery', ['snapshots' => $snapshots]);
 }