#2336 redirect ad detail link if slug is different

This commit is contained in:
Muammer Top 2020-11-30 15:47:08 +03:00
parent ff9808689b
commit 9b9157d8b4
2 changed files with 13 additions and 10 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 = str_slug($object->slug, '-');
return \route('adv_detail_seo', [$seo, $id]);
}
$id = $object->getObject()->id;
$seo = str_slug($object->getObject()->name);
$seo = str_replace('_', '-', $seo);
$seo = str_slug($object->getObject()->name, '-');
return \route('adv_detail_seo', [$seo, $id]);
}

View File

@ -10,6 +10,7 @@ use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cookie;
use Illuminate\Support\Str;
use Visiosoft\AdvsModule\Adv\AdvModel;
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Visiosoft\AdvsModule\Adv\Event\ChangedStatusAd;
@ -579,12 +580,16 @@ class AdvsController extends PublicController
$configurations = $this->optionConfigurationRepository->getConf($adv->id);
if ($adv->created_by_id == isset(auth()->user()->id) or $adv->status == "approved") {
return $this->view->make('visiosoft.module.advs::ad-detail/detail', compact('adv', 'complaints',
'recommended_advs', 'categories', 'features', 'options', 'configurations'));
} else {
return back();
}
if (Str::slug($adv->slug, '-') != $seo) {
$this->messages->error(trans('visiosoft.module.advs::message.ad_doesnt_exist'));
return redirect()->route('visiosoft.module.advs::list');
} else if ($adv->created_by_id == isset(auth()->user()->id) or $adv->status == "approved") {
return $this->view->make('visiosoft.module.advs::ad-detail/detail', compact('adv', 'complaints',
'recommended_advs', 'categories', 'features', 'options', 'configurations'));
} else {
return back();
}
} else {
$this->messages->error(trans('visiosoft.module.advs::message.ad_doesnt_exist'));
return redirect()->route('visiosoft.module.advs::list');