Версия laravel 5.2
Не могу сообразить, как из $category исключить категорию с определенным id?
Контроллер карты сайта:
<?php
namespace App\Http\Controllers;
use App\Models\Category;
use App\Models\Country;
use App\Models\PhotoCategory;
use App\Models\Photowork;
class SitemapController extends Controller
{
public function index()
{
$photographer_category = PhotoCategory::get(['slug'])->map(function ($item) {
return $item->slug;
})->push('')->all();
$users = Photowork::join('users' , 'users.id', '=', 'photoworks.user_id')
->where('users.active', true)
->where('parent_id', 0)
->groupBy('user_id')
->get()
->map(function ($item){
return [$item->user_id => $item->user->username];
})->flatten()->all();
$categories = Category::get(['slug'])->map(function ($item) {
return $item->slug;
})->push('')->all();
return response()->view('sitemap.index', [
'photographer_categories' => $photographer_category,
'users' => $users,
'categories' => $categories
])->header('Content-Type', 'text/xml');
}
}
Вьюшка
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
@foreach ($photographer_categories as $photographer_category)
<url>
<loc>{{route('photostream.index').'/'.$photographer_category }}</loc>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
@endforeach
@foreach ($users as $user)
<url>
<loc>{{route('users.show',[$user]) }}</loc>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
@endforeach
@foreach ($categories as $category)
<url>
<loc>{{route('users.search').'/'.$category }}</loc>
<changefreq>weekly</changefreq>
<priority>0.6</priority>
</url>
@endforeach
</urlset>
Роут:
Route::get('sitemap.xml', ['as' => 'sitemap', 'uses' => 'SitemapController@index']);