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

View File

@ -244,6 +244,20 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
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)
{
$adv = $this->model

View File

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

View File

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

View File

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