Merge pull request #851 from openclassify/dia

#2336 redirect ad detail link if slug is different
This commit is contained in:
Ozcan Durak 2020-12-07 13:13:25 +03:00 committed by GitHub
commit b04abde541
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 22 deletions

View File

@ -218,13 +218,11 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
{ {
if ($type != null) { if ($type != null) {
$id = $object->id; $id = $object->id;
$seo = str_slug($object->name); $seo = $object->slug;
$seo = str_replace('_', '-', $seo);
return \route('adv_detail_seo', [$seo, $id]); return \route('adv_detail_seo', [$seo, $id]);
} }
$id = $object->getObject()->id; $id = $object->getObject()->id;
$seo = str_slug($object->getObject()->name); $seo = $object->getObject()->slug;
$seo = str_replace('_', '-', $seo);
return \route('adv_detail_seo', [$seo, $id]); return \route('adv_detail_seo', [$seo, $id]);
} }
@ -233,8 +231,7 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
$adv = $this->find($id); $adv = $this->find($id);
if ($adv != null) { if ($adv != null) {
$id = $adv->id; $id = $adv->id;
$seo = str_slug($adv->name); $seo = $adv->slug;
$seo = str_replace('_', '-', $seo);
return \route('adv_detail_seo', [$seo, $id]); return \route('adv_detail_seo', [$seo, $id]);
} }
} }

View File

@ -244,6 +244,20 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
return $adv; return $adv;
} }
public function findByIDAndSlug($id, $slug)
{
$adv = $this->newQuery()
->where('advs_advs.id', $id)
->where('slug', $slug)
->first();
if ($adv) {
$adv = $this->getLocationNames($adv);
}
return $adv;
}
public function getListItemAdv($id) public function getListItemAdv($id)
{ {
$adv = $this->model $adv = $this->model

View File

@ -21,6 +21,8 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface
public function getCatNames($adv); public function getCatNames($adv);
public function findByIDAndSlug($id, $slug);
public function cover_image_update($adv); public function cover_image_update($adv);
public function getRecommendedAds($id); public function getRecommendedAds($id);

View File

@ -135,10 +135,6 @@ class AdvsController extends PublicController
parent::__construct(); parent::__construct();
} }
/**
* @return \Illuminate\Contracts\View\View|mixed
*/
public function index($category = null, $city = null) public function index($category = null, $city = null)
{ {
$customParameters = array(); $customParameters = array();
@ -481,9 +477,12 @@ class AdvsController extends PublicController
public function view($seo, $id = null) public function view($seo, $id = null)
{ {
$id = is_null($id) ? $seo : $id; if ($id) {
$adv = $this->adv_repository->findByIDAndSlug($id, $seo);
$adv = $this->adv_repository->getListItemAdv($id); } else {
$id = $seo;
$adv = $this->adv_repository->getListItemAdv($id);
}
if ($adv && ((!$adv->expired() && $adv->getStatus() === 'approved') || $adv->created_by_id === \auth()->id())) { if ($adv && ((!$adv->expired() && $adv->getStatus() === 'approved') || $adv->created_by_id === \auth()->id())) {
// Check if created by exists // Check if created by exists

View File

@ -176,15 +176,16 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
$categories = array(); $categories = array();
$z = 1; $z = 1;
for ($i = 1; $i <= $z; $i++) { for ($i = 1; $i <= $z; $i++) {
$main = $this->newQuery()->where('id', $id)->first(); if ($main = $this->newQuery()->where('id', $id)->first()) {
$new = array(); $new = array();
$new['id'] = $main->id; $new['id'] = $main->id;
$new['val'] = $main->name; $new['val'] = $main->name;
$new['slug'] = $main->slug; $new['slug'] = $main->slug;
$categories[] = $new; $categories[] = $new;
if ($main->parent_category_id != null) { if ($main->parent_category_id != null) {
$id = $main->parent_category_id; $id = $main->parent_category_id;
$z++; $z++;
}
} }
} }
$categories = array_reverse($categories); $categories = array_reverse($categories);