Move logic from blade file at least to controller or god forbid some service class.
Feb 7, 2020
3
Level 2
Cleaing up some php code
hello I have this messy code and it gets messier every time I add to it and I want to make it cleaner but couldn't do it myself can you please help me with this and thanks
// those are the var used to replace words from an article to bold the specific word if found at the string
@php
$Tags = @explode(',',$game_info->g_tags);
$g_tag = current($Tags);
$Tags = @explode(',',$game_info->g_tags);
$s_gamename = "<span class='text-light'>$game_info->g_name</span>";
$b_3d = "<b class='text-light'>3D</b>";
$b_2d = "<b class='text-light'>2D</b>";
$b_crossplatform = "<b class='text-light'>Cross Platform</b>";
$b_multiplayer = "<b class='text-light'>Multiplayer</b>";
$b_guide = "<b class='text-light'>Story </b>";
$b_story = "<b class='text-light'>Guide </b>";
$b_pvp = "<b class='text-light'>PVP </b>";
$b_pve = "<b class='text-light'>PVE </b>";
$b_game = "<b class='text-light'> Game </b>";
$b_classes = "<b class='text-light'>Classes</b>";
$b_players = "<b class='text-light'>Players</b>";
$b_mmo = "<a class='text-warning' href='/mmo-games'> MMO </a>";
$b_r2games = "<b class='text-light'>R2Games</b>";
$b_gtarcade = "<b class='text-light'>GTArcade</b>";
$b_upjers = "<b class='text-light'>Upjers</b>";
$b_101xp = "<b class='text-light'>101XP</b>";
$b_gameforge = "<b class='text-light'>GameForge</b>";
@endphp
and this is the article code
<p>
{!! str_ireplace(array("\r","\n\n","\n", $game_info->g_name, '3D','2D', 'cross platform', 'cross-platform', 'multiplayer', 'r2games', 'upjers', '101xp', 'gameforge', 'story', 'guide', 'classes', 'pvp', 'pve', ' game ', 'players', ' mmo ', 'gtarcade'),array('',"\n","</p>\n<p>", $s_gamename, $b_3d, $b_2d, $b_crossplatform,$b_crossplatform, $b_multiplayer, $b_r2games, $b_upjers, $b_101xp, $b_gameforge, $b_story, $b_guide, $b_classes, $b_pvp, $b_pve, $b_game, $b_players, $b_mmo, $b_gtarcade),trim($game_info->g_info,"\n\r")) !!}</p>
Please or to participate in this conversation.