lundi 16 juillet 2018

Replace ' ' for '-' inside imploded query in Laravel

I have this piece of code that gets all subcategories for my article and includes them as CSS classes

<article class=" article-item">

Where $a is an Article model.

This works great except in case one of the categories having multiple words (a recent petition by my client).

Example:

Categories: 'home', 'ofice' and 'archive and storage'.

What I get:

<article class="home office archive and storage article-item">

What I want:

<article class="home office archive-and-storage article-item">

I hope with this my request is clear, how do I implode multiple words for each of my categories? I've tried to implode and str_replace() on various parts of the query builder but I can't get it right.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire