jeudi 15 octobre 2020

how can i reduce repeated code in laravel?

i am new in laravel, i have array like


{ 
 music : {'a' =>1, 'b'=> 2},
 video :{'c' =>10, 'd'=> 20}
}

i got this by using this code


$video = ResourcesVideo::where('resource_type', 'video')->get();
$music = ResourcesVideo::where('resource_type', 'music')->get();

$response['data'] = [
     "videos" => $video,
     "music" => $music,
 ];

on this code i got above array. so my quetions is. how can i reduce that code. because many things are similer except where condition tried many ways but no success.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3dvrfhj
via IFTTT

Aucun commentaire:

Enregistrer un commentaire