1
0
Files
lkafu/app/Http/Controllers/IndexController.php
2020-08-06 14:45:56 +08:00

62 lines
1.8 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Advert;
use App\Models\Category;
use App\Models\Goods;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
class IndexController extends Controller
{
public function __construct(Request $request)
{
View::share('nav', 1);
view()->share('app_title', '会员商城');
}
public function index(Request $request)
{
$title = $request->title;
$adverts = Advert::where('channel', 'member')->orderBy('sort', 'asc')->take(5)->get(); //banner
$c_lists = Category::where('type', 'goods')->where('parent_id', 0)->orderBy('order', 'asc')->take(4)->get();
$lists = Goods::where('status', 1)
->when($title, function ($q) use ($title) {
$q->where('title', 'like', "%{$title}%");
})
->where('type', 'member')
->where('is_hot_sell', 1)
->orderBy('sort', 'asc')
->orderBy('created_at', 'desc')
->paginate(10);
return view('index.index', compact('c_lists', 'adverts', 'lists', 'title'));
}
public function more(Request $request)
{
$category_id = $request->category;
$title = $request->title;
$lists = Goods::where('status', 1)
->when($title, function ($q) use ($title) {
$q->where('title', 'like', "%{$title}%");
})
->where('type', 'member')
->where('is_hot_sell', 1)
->orderBy('sort', 'asc')
->orderBy('created_at', 'desc')
->paginate(10);
if ($lists->isNotEmpty()) {
$html = response(view('index.more', compact('lists')))->getContent();
return $this->success($html);
} else {
return $this->error('没有数据了');
}
}
}