I new here in React Js With Laravel Php Framework.
The Problem: Is it possible to get every array object to my API and fetch it in every section.because i got an error in my console that says
Uncaught TypeError: this.state.missions.map is not a function. I don't know what the problem is but the main goal is to get every object and the loop must be in specific div section in the views
Ex. If i already get the array object of mission and store
<div className="mission">
the object of mission must be here.
</div>
<div className="store">
the object of store must be here.
</div>
and other object. etc
My Controller:
public function index() {
$content_mission = DB::table('content_structure')
->where('content_pages','=','Home')
->where('content_section','=','Mission-Vision')
->where('status','=','Active')
->orderBy('content_id','Desc')
->limit(1)
->get();
$content_store = DB::table('content_structure')
->leftJoin('content_upload_assets','content_structure.content_id','=','content_upload_assets.cid')
->where('content_pages','=','Home')
->where('content_section','=','Store')
->where('status','=','Active')
->orderBy('content_id','Desc')
->limit(1)
->get();
return response()->json(
array(
'mission'=>$content_mission,
'store'=>$content_store)
);
}
My Components:
export default class Content extends Component {
constructor() {
super();
this.state = {
missions: [],
store: [],
}
}
componentWillMount() {
axios.get('/api/contents').then(response => {
this.setState({
missions: response.data
});
}).catch(error => {
console.log(error);
})
}
render() {
return (
<div>
// this div is for mission
<div className="mission-section">
<h1></h1>
<p></p>
<div className="container">
{this.state.missions.map(mission => <li>{mission.content}</li>)}
</div>
</div>
//this div is for store
<div className="Store"></div>
</div>
)
}
}
if(document.getElementById('app'))
{
ReactDOM.render(<Content/>, document.getElementById('app'));
}