In itself, they are not generated automatically. you would have to generate a global route for all your products, but instead of how you usually access it through the id
, you can access a field slug
or url
in your table. you must add a field in your table for example url
In your model Categoria
, in your mutador
at the time you add the name, assign the field url
by calling the function str_slug () to generate a% friendly% co
/**
* Mutator for name attribute.
*
* @return void
*/
public function setNameAttribute($value)
{
$this->attributes['name'] = ucwords($value);
// asignamos el campo url con nombre
$this->attributes['url'] = str_slug($value);
}
On your routes
Route::get('categorias/{categoria}',
'CategoriaContoller@categoriaunica')->name('categoriaunica');
In your controller you might have something like this, for example to recover the URL
, (this method can be improved)
public function categoriaunica($categoria)
{
$categoria = Categoria::where('url','=',$categoria)->first();
$subcategorias = SubCategoria::where('categoria' ,'=',$categoria->id)->get();
return view('subcatexcategoria',compact('subcategorias','categoria'));
}