Add display articles & categories, raw mode
This commit is contained in:
@@ -28,9 +28,9 @@ class HomeController extends Controller
|
||||
public function index()
|
||||
{
|
||||
$data['categories'] = Categories::getTree();
|
||||
$data['category'] = Categories::get(15)->toArray();
|
||||
$data['articles'] = Articles::getByCategory(0)->toArray();
|
||||
dump($data);
|
||||
exit;
|
||||
// dump($data);
|
||||
return view('Shop.home', $data);
|
||||
}
|
||||
}
|
||||
|
||||
12
app/Models/Core/Media.php
Normal file
12
app/Models/Core/Media.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Core;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Media extends Model
|
||||
{
|
||||
protected $table = 'media';
|
||||
|
||||
}
|
||||
@@ -26,9 +26,14 @@ class Article extends Model implements HasMedia
|
||||
return $this->hasMany('App\Models\Shop\ArticleAttribute');
|
||||
}
|
||||
|
||||
public function prices()
|
||||
public function images()
|
||||
{
|
||||
return $this->hasManyThrough('App\Models\Shop\ArticlePrice','App\Models\Shop\ArticleAttribute');
|
||||
return $this->hasMany('App\Models\Core\Media','model_id')->where('model_type','App\Models\Shop\Article');
|
||||
}
|
||||
|
||||
public function image()
|
||||
{
|
||||
return $this->hasOne('App\Models\Core\Media','model_id')->where('model_type','App\Models\Shop\Article');
|
||||
}
|
||||
|
||||
public function inventories()
|
||||
@@ -41,6 +46,11 @@ class Article extends Model implements HasMedia
|
||||
return $this->hasMany('App\Models\Shop\InvoiceItem');
|
||||
}
|
||||
|
||||
public function prices()
|
||||
{
|
||||
return $this->hasManyThrough('App\Models\Shop\ArticlePrice','App\Models\Shop\ArticleAttribute');
|
||||
}
|
||||
|
||||
public function product()
|
||||
{
|
||||
return $this->morphTo();
|
||||
|
||||
@@ -49,7 +49,7 @@ class Articles
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
return Article::with(['prices.article_attribute.attribute_value'])->get();
|
||||
return Article::with(['prices.article_attribute.attribute_value','product','image'])->get();
|
||||
}
|
||||
|
||||
public static function getCategoriesByArticle($article)
|
||||
@@ -92,7 +92,7 @@ class Articles
|
||||
self::storeCategories($article, $categories);
|
||||
self::storeTags($article, $tags);
|
||||
self::storePrices($article, $prices);
|
||||
return $article_id;
|
||||
return $article->id;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
@@ -175,6 +175,17 @@ class Articles
|
||||
}
|
||||
}
|
||||
|
||||
public static function getThumbSrc($image)
|
||||
{
|
||||
$id = $image['id'];
|
||||
$images = json_decode($image['responsive_images'], true);
|
||||
$urls = $images['medialibrary_original']['urls'];
|
||||
|
||||
$img = $urls[count($urls)-1];
|
||||
$src = "storage/$id/responsive-images/$img";
|
||||
return $src;
|
||||
}
|
||||
|
||||
|
||||
public static function deleteImage($id, $index)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user