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

Thursday, January 13, 2022

[FIXED] How can I convert "Vue JS value to PHP value and PHP value to Vue JS value"?

 January 13, 2022     laravel, php, vue.js     No comments   

Issue

Is this possible ?? anyone please help me . How can I convert "Vue JS value to PHP value and PHP value to Vue JS value" ?

<span v-for="comment in post.comments"> <?php $ud = comment.userId; $commentUser = DB::table('users') ->where('users.id', '=', $ud) ->first(); ?> <div class="post-comment" style="border-bottom: 1px solid #e6e6e6;margin-left: 5px;"> <!-- <img :src="'{{Config::get('app.url')}}/BUproject/public/frontEnd/images/users/' + post.user.pic" alt="" class="profile-photo-sm" style=" margin-bottom: 5px; margin-top:4px;"/>--> <img src="{{asset('public/frontEnd/')}}/images/users/{{$commentUser->pic}}" alt="" class="profile-photo-sm" /> <p style="margin-right: 15px;"><a :href="'{{url('/timeline')}}/' + comment.slug" class="profile-link">@{{post.user.firstName | uppercase}} @{{post.user.lastName}}</a> @{{comment.comment}} </p> </div> </span>

Solution

you can use axios for getting the data from database, you dont have to write php. That is how you can get the data from database using axios in vue.js.

<script>
 export default {
   data() {
      return {
        users: [],
     }
  },
    methods: {
      loadusers(){
        axios.get('users').then(response => this.users= response.data);
       },
   }
 },
    mounted() {
     this.loadusers();
  }
</script>

Your Controller:

public function index()
    {
      return User::all();
    }

your web.php:

Route::resource('users', 'UserController');



Answered By - Sajad Haibat
  • 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