I tried everything to push item into json
file but when call
file_put_contents("file.json",$data)
doesn't work and the page shutdown.
Here's my controller code.
public function addJson()
{
$titulo = Input::get('title');
$name = Input::file('image')->getClientOriginalName();
$arr = json_decode(file_get_contents("js/data.json"), true);
array_push($arr['galerias'], array('id' => count($arr['galerias'])+1, 'name' => $name, 'img' => 'galeria/'.$name));
$arr2 = $arr['galerias'];
$arr = json_encode($arr);
echo $arr;
file_put_contents('js/data.json', $arr);
return view('main.prueba')->with('name',$arr2);
}
And here is the json
file.
{
"galerias": [
{
"id": 1,
"name": "Fiesta Privada",
"img": "galeria/FP.JPG"
},
{
"id": 2,
"name": "Fiesta Privada",
"img": "galeria/FP2.JPG"
},
{
"id": 3,
"name": "Fiesta Privada",
"img": "galeria/FP3.JPG"
},
{
"id": 4,
"name": "Fiesta Privada",
"img": "galeria/FP4.JPG"
},
{
"id": 5,
"name": "Fiesta Privada",
"img": "galeria/FP5.JPG"
},
{
"id": 6,
"name": "Fiesta Privada",
"img": "galeria/FP6.JPG"
},
{
"id": 7,
"name": "Los Kjarkas",
"img": "galeria/Los_Kjarkas.jpg"
},
{
"id": 8,
"name": "Palmenia Pizarro",
"img": "galeria/Palmenia_Pizarro.jpg"
},
{
"id": 9,
"name": "Palmenia Pizarro",
"img": "galeria/Palmenia_Pizarro_2.jpg"
},
{
"id": 10,
"name": "Palmenia Pizarro",
"img": "galeria/Palmenia_Pizarro_3.jpg"
}
]
}
Heeeelp me pls :C