File: D:/HostingSpaces/netwerkbrabant/netwerkbrabant.nl/app/Http/Wildcards/MagazinesWildcard.php
<?php
namespace App\Http\Wildcards;
use App\KommaApp\MagazineArticles\Models\MagazineArticleTranslation;
use App\KommaApp\Magazines\Models\MagazineTranslation;
class MagazinesWildcard implements WildcardInterface
{
/**
* @param $request
* @param $wildcard
* @return mixed
*/
public function handle($request, $wildcard)
{
// Check if the first segment is found in the MagazineArticleTranslation
if($magazineArticleTranslation = MagazineArticleTranslation::where('slug', $wildcard->tail[0])->with('translatable')->first())
{
// Check if the second segment isset and matches a MagazineTranslation
if(isset($wildcard->tail[1]) && $magazineTranslation = MagazineTranslation::where('slug', $wildcard->tail[1])->first())
{
// Only continue if the found MagazineArticle belongs to the found Magazine
if($magazineArticleTranslation->translatable->magazine()->id === $magazineTranslation->magazine_id){
//Set the request URI
$request->server->set('REQUEST_URI', 'magazineArticles/'.$magazineArticleTranslation->magazine_article_id);
return $request;
}
}
}
// Check if the first segment is found in the MagazineTranslation
if($magazineTranslation = MagazineTranslation::where('slug', $wildcard->tail[0])->first())
{
//Set the request URI
$request->server->set('REQUEST_URI', 'magazines/'.$magazineTranslation->magazine_id);
return $request;
}
if(config('app.env') == 'local'){
var_dump('maybe make a correct pointer for the following tail');
dd($wildcard->tail);
}
return $request;
}
}