public function fileJsonUpdate() { /* Buscamos todos los datos de school y traemos solo el id y el name */ $school = School::select('id', 'name')->get(); $dataJson = ''; foreach ($school as $schools) { $dataJson[] = array('value' => $schools->id, 'text' => $schools->name); } $fh = fopen('json/schools.json', 'w') or die('Error al abrir fichero de salida'); fwrite($fh, json_encode($dataJson, JSON_UNESCAPED_UNICODE)); fclose($fh); }
public function schools() { return $this->belongsToMany(School::getClass()); }