Skip to content

Instantly share code, notes, and snippets.

@tiagoandrepro
Created August 19, 2017 04:30
Show Gist options
  • Save tiagoandrepro/4188c01149c5987df33d781f62cb7fa0 to your computer and use it in GitHub Desktop.
Save tiagoandrepro/4188c01149c5987df33d781f62cb7fa0 to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
import { FlatList, StyleSheet, Text, View } from "react-native";
export default class HttpExample extends Component {
state = {
data: []
};
componentWillMount() {
this.fetchData();
}
fetchData = async () => {
const response = await fetch("https://tiagoandre.com.br/horarios.json");
const json = await response.json();
this.setState({ data: json.terminalUtil });
};
render() {
return (
<View style={styles.container}>
<Text> Semana </Text>
<FlatList
data={this.state.data}
keyExtractor={(x, i) => i}
renderItem={({ item }) =>
<Text>
{`${item.horario}`}
</Text>
}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
marginTop: 15,
flex: 1,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5FCFF"
}
});
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
Use App\Models\Horario;
use DB;
class HorarioController extends Controller
{
public function index ()
{
//$horario = Horario::get();
$horarioTerminalUtil = DB::table('horario')->where('localPartida', 'terminal')->where('dia', 'util')->get();
$horarioTerminalSabado = DB::table('horario')->where('localPartida', 'terminal')->where('dia', 'sabado')->get();
$horarioTerminalDomingo = DB::table('horario')->where('localPartida', 'terminal')->where('dia', 'domingo')->get();
return response()->json(array([
'terminalUtil' => $horarioTerminalUtil,
'terminalSabado' => $horarioTerminalSabado,
'terminalDomingo' => $horarioTerminalDomingo
]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment