1๐
โ
You can achieve this simply by using response
method of laravel
public function something()
{
$data=Model::all();
$comments=Comment::all()
return response()->json([
'data'=> $data,
'comments'=> $comments
], 200);
}
or the other way using same method
public function something()
{
$data=Model::all();
$comments=Comment::all()
return response([
'data'=> $data,
'comments'=> $comments
], 200);
}
and in your component you can simply get data using
export default
{
created()
{
axios.get("a url")
.then(res=>{
console.log(res.data.data)
console.log(res.data.comments)
}
}
}
Thanks
๐คSalman Zafar
2๐
Here you go you can create an associate array and send through json.
public function something()
{
$data=Model::all();
$comments=Comment::all()
return response()->json([
'data'=>$data,
'comments'=>$comments
]) //here i want to send both $data and $comments to that view
}
In Vue you can write something like this.
export default
{
data(){
return {
comments:[]
}
},
created()
{
axios.get("a url")
.then(res=>{
this.comments = [...res.data.comments] //If you are using ES6
}
}
}
๐คMr.Throg
1๐
You can simply do this
public function function()
{
$data=Model::all();
$comments=Comment::all()
return response()->json([
'data'=>$data,
'comments'=>$comments
]) //here i want to send both $data and $comments to that view
}
๐คPranta Roy
Source:stackexchange.com