Skip to content

Commit

Permalink
Redirect with slug
Browse files Browse the repository at this point in the history
  • Loading branch information
amenk committed Jul 23, 2024
1 parent 5568539 commit d347c06
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions app/Http/Controllers/DetailRedirectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,36 @@

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Validation\ValidatesRequests;
use App\Facades\Fallback;
use App\Models\OsmId;
use App\Models\Place;
use App\Services\Language;
use App\Services\Overpass;
use App\Services\Repository;
use Illuminate\Routing\Controller as BaseController;

class DetailRedirectController extends BaseController
{
public function node(string $osmId)
{
return redirect(route('osmPlace.en', ['osmId' => $osmId, 'osmTypeLetter' => 'n']));
return $this->redirect($osmId, 'n');
}

public function way(string $osmId)
{
return redirect(route('osmPlace.en', ['osmId' => $osmId, 'osmTypeLetter' => 'w']));
return $this->redirect($osmId, 'w');
}

public function relation(string $osmId)
{
return redirect(route('osmPlace.en', ['osmId' => $osmId, 'osmTypeLetter' => 'r']));
return $this->redirect($osmId, 'r');
}

private function redirect($osmId, $osmTypeLetter)
{
$osmInfo = (new Overpass())->fetchOsmInfo([new OsmId($osmTypeLetter, $osmId)], Repository::getInstance()->listLeafAreas());

$slug = Language::slug(Fallback::field($osmInfo[0]->tags, 'name', language: 'en'));
return redirect(route('osmPlace.en', ['osmId' => $osmId, 'osmTypeLetter' => $osmTypeLetter, 'slug' => $slug]));
}
}

0 comments on commit d347c06

Please sign in to comment.