PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 17, 2022

[FIXED] Method Illuminate\View\View::response does not exist

 February 17, 2022     laravel, laravel-5, vue.js, vuejs2     No comments   

Issue

I'm getting an error when I want to fetch my data from table.

My controller :

public function admin()
{
    $users = User::with('subs')->get();
    return view('admin')->response()->json([
        'users' => $users,
    ], 200);
}

My vue.js script :

export default {
    data() {
        return {
            users: []
        }
    },

    methods: {
        showUsers() {
            axios.get('admin/routes').then(response => {
                this.users = response.data.users;
            });
        }
    },
    mounted() {
        this.showUsers();
    }
}

My blade html code:

<tr v-for="user in users">
    <td>{{ user.id }}</td>
    <td>{{ user.name }}</td>
</tr>

Method Illuminate\View\View::response does not exist.

When I want to fetch my data from table.


Solution

You don't need to return view for that since you just need the JSON response for the API to work.

return response()->json([
    'users' => $users,
]);


Answered By - Adlan Arif Zakaria
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing