mirror of https://github.com/4xmen/xshop.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.3 KiB
PHP
39 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Web;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Resources\AdvResource;
|
|
use App\Http\Resources\CategoryResource;
|
|
use App\Http\Resources\PostResource;
|
|
use App\Http\Resources\ProductResource;
|
|
use App\Http\Resources\SliderResource;
|
|
use App\Models\Adv;
|
|
use App\Models\Category;
|
|
use App\Models\Menu;
|
|
use App\Models\Post;
|
|
use App\Models\Product;
|
|
use App\Models\Slider;
|
|
use Illuminate\Http\Request;
|
|
|
|
class HomeController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$data = [];
|
|
$data['menu'] = Menu::with(['items' => function ($query) {
|
|
$query->select(['id', 'title', 'menuable_id', 'menuable_type', 'kind', 'meta', 'parent', 'sort', 'user_id', 'menu_id']);
|
|
}])->first(['id', 'name']);
|
|
$data['slider'] = SliderResource::collection(Slider::take(6)->get());
|
|
$data['categories'] = CategoryResource::collection(Category::with('products')->whereNull('parent_id')->orderBy('sort')->take(8)->get());
|
|
$data['adv'] = AdvResource::collection(
|
|
Adv::query()
|
|
->where('status', true)
|
|
->whereColumn('click', '<', 'max_click')
|
|
->get()
|
|
);
|
|
$data['post'] = PostResource::collection(Post::orderByDesc('created_at')->take(8)->get());
|
|
return success($data);
|
|
}
|
|
}
|