@keroherox30 are you going to delete this thread whenever you get the answer - like you did the last one?
Jun 30, 2022
9
Level 1
laravel: Showing the slug in URL instead of ID - List of Products
Hello,
i want to remove id and want only slug how will be?! i trying but get 404 error
Model Products
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Product extends Model
{
use SoftDeletes;
protected $guarded = ['id'];
protected $casts = [
'extra_descriptions' => 'array',
'specification' => 'array',
];
public function categories()
{
return $this->belongsToMany(Category::class, 'products_categories', 'product_id', 'category_id');
}
public function orderDetails()
{
return $this->hasMany(OrderDetails::class);
}
public function orders()
{
return $this->hasMany(Order::class);
}
}
Product Controller
public function productDetails($id, $order_id =null)
{
$product = Product::where('id', $id)->where('status', 1)
->with('categories'')
->whereHas('categories')
->firstOrFail();
$review_available = false;
if($order_id){
$order = Order::where('order_number', $order_id)->where('user_id', auth()->id())->first();
if($order){
$od = OrderDetail::where('order_id', $order->id)->where('product_id', $id)->first();
if($od){
$review_available = true;
}
}
}
$pageTitle = 'Product Details';
return view($this->activeTemplate . 'product_details', compact('product', 'pageTitle', 'review_available ');
}
Route
Route::get('product/detail/{id}/{slug}/', 'ShopController@productDetails')->name('product.detail');
i want help and thanks
Please or to participate in this conversation.