BoraN7
web.php çok büyük olduğu için sadece sitemap kısmı için eklediğim kodları dahil ettim hocam
SitemapController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Category;
use App\Models\Product;
class SitemapController extends Controller
{
public function index()
{
$products = Product::all()->first();
$categories = Category::all()->first();
return response()->view('sitemap.index', [
'products' => $articles,
'categories' => $categories,
])->header('Content-Type', 'text/xml');
}
public function products()
{
$products = Article::latest()->get();
return response()->view('sitemap.products', [
'products' => $products,
])->header('Content-Type', 'text/xml');
}
public function categories()
{
$categories = Category::all();
return response()->view('sitemap.categories', [
'categories' => $categories,
])->header('Content-Type', 'text/xml');
}
}
web.php
Route::get('/sitemap.xml', 'SitemapController@index');
Route::get('/sitemap.xml/products', 'SitemapController@articles');
Route::get('/sitemap.xml/categories', 'SitemapController@categories');
index.blade.php
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>http://localhost/554/sitemap.xml/products</loc>
</sitemap>
<sitemap>
<loc>http://localhost/554/sitemap.xml/categories</loc>
</sitemap>
</sitemapindex>
ek olarak projede yönetici ürünleri ve satıcı ürünleri var
buda tüm ürünler fonksiyonu
ProductController.php
public function all_products(Request $request)
{
$col_name = null;
$query = null;
$seller_id = null;
$sort_search = null;
$products = Product::orderBy('created_at', 'desc')->where('auction_product',0);
if ($request->has('user_id') && $request->user_id != null) {
$products = $products->where('user_id', $request->user_id);
$seller_id = $request->user_id;
}
if ($request->search != null){
$products = $products
->where('name', 'like', '%'.$request->search.'%');
$sort_search = $request->search;
}
if ($request->type != null){
$var = explode(",", $request->type);
$col_name = $var[0];
$query = $var[1];
$products = $products->orderBy($col_name, $query);
$sort_type = $request->type;
}
$products = $products->paginate(15);
$type = 'All';
return view('backend.product.products.index', compact('products','type', 'col_name', 'query', 'seller_id', 'sort_search'));
}