invert query from offers->articles to articles->offers
This commit is contained in:
@@ -20,6 +20,8 @@ class HomeController extends Controller
|
||||
{
|
||||
$data = self::init();
|
||||
$data['offers'] = Offers::getLast()->toArray();
|
||||
dump($data);
|
||||
exit;
|
||||
return view('Shop.home', $data);
|
||||
}
|
||||
}
|
||||
|
||||
17
app/Http/Controllers/Shop/OfferController.php
Normal file
17
app/Http/Controllers/Shop/OfferController.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Shop\Offers;
|
||||
|
||||
class OfferController extends Controller
|
||||
{
|
||||
public function show($id)
|
||||
{
|
||||
$offer = Offers::getFull($id);
|
||||
dump($offer);
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,13 @@ class Article extends Model implements HasMedia
|
||||
|
||||
public function scopeWithOffers($query)
|
||||
{
|
||||
return $query->has('Offers');
|
||||
return $query->has('offers');
|
||||
}
|
||||
|
||||
public function scopeWithCurrentOffers($query)
|
||||
{
|
||||
return $query->whereHas('offers', function ($query) {
|
||||
$query->where('status_id', 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,11 @@ use Spatie\Translatable\HasTranslations;
|
||||
use Rinvex\Tags\Traits\Taggable;
|
||||
use Wildside\Userstamps\Userstamps;
|
||||
|
||||
use Kalnoy\Nestedset\NodeTrait;
|
||||
|
||||
class Category extends Model
|
||||
{
|
||||
use HasTranslations, InteractsWithMedia, SoftDeletes, Taggable, Userstamps;
|
||||
use HasTranslations, InteractsWithMedia, NodeTrait, SoftDeletes, Taggable, Userstamps;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'categories';
|
||||
@@ -41,4 +43,9 @@ class Category extends Model
|
||||
{
|
||||
return $query->where('category_id', $category_id);
|
||||
}
|
||||
|
||||
public function scopeVisible($query)
|
||||
{
|
||||
return $query->where('visible', 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,11 @@ class Offer extends Model
|
||||
return $this->belongsTo(Variation::class);
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('status_id', 1);
|
||||
}
|
||||
|
||||
public function scopeByArticle($query, $id)
|
||||
{
|
||||
return $query->where('article_id', $id);
|
||||
|
||||
@@ -6,11 +6,6 @@ use App\Repositories\Core\Arrays;
|
||||
|
||||
class Categories
|
||||
{
|
||||
public static function getTree($withFolder = false)
|
||||
{
|
||||
$categories = self::getCategoryTree()->toArray();
|
||||
return self::getChildren($categories[0]['children'], $withFolder);
|
||||
}
|
||||
|
||||
public static function getFancyTree()
|
||||
{
|
||||
@@ -20,6 +15,12 @@ class Categories
|
||||
return $categories;
|
||||
}
|
||||
|
||||
public static function getTree($withFolder = false)
|
||||
{
|
||||
$categories = self::getCategoryTree()->toArray();
|
||||
return self::getChildren($categories[0]['children'], $withFolder);
|
||||
}
|
||||
|
||||
public static function getCategoryTree()
|
||||
{
|
||||
return self::getModel()->defaultOrder()->get()->toTree();
|
||||
|
||||
@@ -59,6 +59,11 @@ class Articles
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getArticlesWithOffers()
|
||||
{
|
||||
return Article::withCurrentOffers()->with('offers')->get();
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$data['article'] = self::getArticleEdit($id);
|
||||
|
||||
@@ -38,6 +38,11 @@ class Categories
|
||||
return $category->tags->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getTreeVisibles()
|
||||
{
|
||||
$tree = Category::get()->toTree();
|
||||
}
|
||||
|
||||
public static function getTree()
|
||||
{
|
||||
return CategoryTrees::getTree();
|
||||
|
||||
@@ -19,7 +19,7 @@ class Offers
|
||||
|
||||
public static function getLast()
|
||||
{
|
||||
return Offer::with(['article.image'])->orderByDesc('updated_at')->get();
|
||||
return Offer::with(['article.image'])->active()->orderByDesc('updated_at')->get();
|
||||
}
|
||||
|
||||
public static function getByCategoryWithTags($category_id)
|
||||
|
||||
Reference in New Issue
Block a user