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>
Advertisement
Answer
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');