VueJs and Laravel dom contents not updating - laravel

I have this method when I click to view any member it shows the detail of the member in the modal, but it's not working as I expected
vue js code
const member_modal = ref(null);
const viewMember = (member) => {
axios.get("/api/member/" + member.id).then((response) => {
member_modal.value = response.data;
console.log(member_modal.value);
$("#viewMemberModal").modal("show");
});
};
code inside the modal (DOM)
<a href="#" #click.prevent="viewMember(member)"
><i class="fa fa-eye ml-2"></i
></a>
<img class="profile-user-img img-fluid img-circle"
src="{{ member_modal.image }}"
alt="User profile picture"
/>
</div>
<h3 class="profile-username text-center">
{{ member_modal.full_name }}
</h3>
<ul class="list-group list-group-unbordered mb-3">
<li class="list-group-item">
<b>Gender</b>
<a class="float-right">{{ member_modal.gender }}</a>
</li>
<li class="list-group-item">
<b>Phone</b>
<a class="float-right">{{ member_modal.phone }}</a>
</li>
<li class="list-group-item">
<b>Email</b>
<a class="float-right">{{ member_modal.email }}</a>
</li>
</ul>
I want when I click on the view member button it shows the specific member data in the modal, but it's not updating the values in the (dom), when I click the view member, it fetches the data from the database successfully and assigns the response result to the member_modal but the change is not showing the data in the modal

Related

v-show condition not working with certain strings like "&laqua; Previous" and "Next »"

Hi I am encountering a bug where checking a string variable whether it matches certain string is not working, even though from checking the variable through the vue browser plugin shows that the string has the value of "&laqua; Previous".
I am just trying to paginate the returned value by looping and deciding to show or not show based on the string variable not being both "&laqua; Previous" and "Next &raquo". And it keeps on failing although the string value clearly has the above values.
One thing I had also noticed is that &laqua is the double left angle quote and &raquo is the double right angle quote. This clearly has to do something with the problem.
Pagination.vue
<template>
<nav>
<ul class="pagination justify-content-center">
<li class="page-item" v-for="(d, index) in data" :key="index">
<a
class="page-link"
href="#"
v-show="d.label !== '« Previous' && d.label !== 'Next »'"
>
{{ d.label }}
</a>
</li>
<!-- <li class="page-item active">
<a class="page-link" href="#">2 <span class="sr-only">(current)</span></a>
</li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item">
<a class="page-link" href="#">
<i class="fa fa-angle-right"></i>
<span class="sr-only">Next</span>
</a>
</li> -->
</ul>
</nav>
</template>
<script>
export default {
name: "Pagination",
props: {
data: Array,
},
}
</script>

Laravel8 Property [Eng2] does not exist on this collection instance

I am facing a strange problem: I have 2 pages with similar structure relating to same DB, the first one displaying a grid of products working perfectly, the second the item detail giving me this error. I can get the all JSON string {{$wine}} on the page but no way to extract elements with {{$wine->Eng2}} or {{$wine['Eng2']}}
#extends('layouts.layout')
#include('partials.sidebar')
<div class="detail-container">
<img src="/img/9122705276958.png" alt="" />
<ul>
<!--<li>{{$wine}}</li>-->
<li>{{$wine->Eng2}}</li>
<li></li>
</ul>
<!--<div class="addCart">
<i class="fas fa-shopping-cart"></i>
</div>
<ul class="side-icons">
<span><i class="fas fa-search"></i></span>
<span><i class="far fa-heart"></i></span>
<span><i class="fas fa-sliders-h"></i></span>
</ul>
</div>
<div class="bottom">
<ul>
<li></li>
<li></li>
</ul>
<ul class="price">
<li>Retail price: Ntd </li>
<li>Member price: Ntd </li>
<li>VIP price down to: Ntd </li>
</ul>
</div> -->
</div>
public function detail($id) {
$wine =Wine::where('ART','=',$id)->get();
return view('detail', [
'wine' => $wine
]);
}
Route::get('wines', [WineController::class,'index']);
Route::get('/wines/{id}',[WineController::class,'query']);
Route::get('detail/{id}', [WineController::class,'detail']);
Try to use
$wine = Wine::where('ART','=',$id)->first();
instead of
$wine = Wine::where('ART','=',$id)->get();
first() will get you the first element in the collection but get() will get you the whole collection, so you can use first() if the collection has one element, or you have to use foreach in the view.

Laravel submit form from a tab and return to same tab in view

I have a view with multiple tabs. Each having different forms. When I submit a form from one tab, it returns to same page but primary tab. How could I get to return to same tab from which I was working.
Controller
public function recieve(Request $request)
{
$item = Item::find($request->input('item'));
$item->recieved_at = now();
$item->recieved_status = "1";
$item -> save();
return redirect('/files/'.$item->file)->with('success','Item Recieved Confirmed');
}
view - tabs
<ul class="nav nav-tabs" id="fileTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="profile-tab" data-toggle="tab" href="#profile" role="tab"
aria-controls="profile" aria-selected="true">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" id="job-tab" data-toggle="tab" href="#job" role="tab" aria-controls="job"
aria-selected="false">Job</a>
</li>
<li class="nav-item">
<a class="nav-link" id="items-tab" data-toggle="tab" href="#items" role="tab" aria-controls="items"
aria-selected="false">Items</a>
</li>
<li class="nav-item"><a class="nav-link" id="mechanic-tab" data-toggle="tab" href="#mechanic" role="tab"
aria-controls="mechanic" aria-selected="false">Labour Hours</a>
</li>
<li class="nav-item">
<a class="nav-link" id="accounts-tab" data-toggle="tab" href="#accounts" role="tab"
aria-controls="accounts" aria-selected="false">Accounts</a>
</li>
<li class="nav-item">
<a class="nav-link" id="accounts-tab" data-toggle="tab" href="#preview" role="tab"
aria-controls="accounts" aria-selected="false">Print Preview</a>
</li>
</ul>
Form
#if($file->job_status == "Closed")#else
{!! Form::open(['action' => 'FilesController#item','method' => 'POST']) !!}
<div class="row pt-3 pb-1">
<div class="form-group col-xs-12 col-sm-12 col-md-2">
{{Form::text('part_number','',['class'=>'form-control','placeholder'=>'Part Number'])}}
</div>
<div class="form-group col-xs-12 col-sm-12 col-md-6">
{{Form::text('description','',['class'=>'form-control','placeholder'=>'Part Name'])}}
</div>
<div class="form-group col-xs-12 col-sm-12 col-md-2">
{{Form::text('qty','',['class'=>'form-control','placeholder'=>'Qty'])}}
</div>
<div class="form-group col-xs-12 col-sm-12 col-md-2">
{{Form::select('recieved_by',$users,null,['class'=>'form-control'])}}
</div>
</div>
{{Form::hidden('file',$file->id)}}
{{Form::submit('Release Item',['class'=>'form-control btn-danger btn btn-sm'])}}
{!! Form::close() !!}
#endif
I tried using hashtag tab name in return redirect statement,
return redirect('/files/'.$item->file."#items-tab")->with('success','Item Recieved Confirmed');
it would simply highlight the name but would not select. How could I achieve it?
your tab navigation,
<ul class="nav nav-tabs" id="tabMenu" role="tablist">
<li><i class="fa fa-camera" aria-hidden="true"></i> Galleries</li>
</ul>
hidden input field for tab
<input type="hidden" name="tab" value="Galleries">
RedirectRoute
$tab = $request->get('tab');
return back()->withInput(['tab'=>$tab]);
Javascript,
<script>
//redirect to specific tab
$(document).ready(function () {
$('#tabMenu a[href="#{{ old('tab') }}"]').tab('show')
});
</script>
If you want to do it in laravel than all you can do is,
-Give an id to each tab and an write an active class.
-Put a hidden input with value of the parent tab id.
-So, laravel will receive the tab id in the request object.
-Now, you can do whatever and return the tab id with to the view.
-Give a if condition to each tab item and check if matches the id from laravel response.
The match the id set the active class to it.
example
<ul>
<li id='tab1 {{ session()->get('tabId') === 'tab1' ? 'active' : '' }}'></li>
<li id='tab2 {{ session()->get('tabId') === 'tab2' ? 'active' : '' }}'></li>
</ul>
// tab1 body
<form>
<input type="hidden" name="tabId" value="tab1">
...
</form>
// tab2 body
<form>
<input type="hidden" name="tabId" value="tab2">
...
</form>
// controller
public funciton(Request $request) {
//tabId
$tabId = $request->input('tabId')
....
....
return redirect()->back()->with('tabId' => $tabId);
}
You can do this:
Controller:
public function tab() {
$active_tab = "tab2";
return view('tabs.index', compact('active_tab'));
}
View:
<ul class="nav nav-tabs">
<li class="#if($active_tab=="tab1") active #endif"><a data-toggle="tab" href="#home">Home</a></li>
<li class="#if($active_tab=="tab2") active #endif"><a data-toggle="tab" href="#menu1">Menu 1</a></li>
<li class="#if($active_tab=="tab3") active #endif"><a data-toggle="tab" href="#menu2">Menu 2</a></li>
</ul>
<div class="tab-content">
<div id="home" class="tab-pane fade #if($active_tab=="tab1") in active #endif">
<h3>HOME</h3>
<p>Some content.</p>
</div>
<div id="menu1" class="tab-pane fade #if($active_tab=="tab2") in active #endif">
<h3>Menu 1</h3>
<p>Some content in menu 1.</p>
</div>
<div id="menu2" class="tab-pane fade #if($active_tab=="tab3") in active #endif">
<h3>Menu 2</h3>
<p>Some content in menu 2.</p>
</div>
</div>
You can show a specific tab with this code:
function showTab(tab){
$('.nav-tabs a[href="#' + tab + '"]').tab('show');
};
// Verify location.hash
if (window.location.hash !== ''){
showTab(window.location.hash);
}
But I would pass a query string in the return, just to make sure there will be no collision with other eventual hashes. Something like:
return redirect('/files/'.$item->file."?openTab=your-tab-id")->with('success','Item Recieved Confirmed');
Of course, you would change the "location.hash" verification to a query string verification. Example: https://davidwalsh.name/query-string-javascript

VueJS get variable as text

I'm working on a Laravel project and i use VueJS for notifications system.
However, i'm a real noob in VueJS dev'. Consequently, i don't know how to print a variable as text.
Situation : System of notifications work and i would like to print the number of notifications in a bootsrap badge. So, i did this :
<i class="fa fa-bell-o" aria-hidden="true"></i> Notifications <span id='badge' class="badge badge-info">{{notifications.length}}</span> <span class="caret"></span>
With this code in my Notification.vue file :
<template>
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
<i class="fa fa-bell-o" aria-hidden="true"></i> Notifications <span id='badge' class="badge badge-info">{{notifications.length}}</span> <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li style="text-align:center" v-for="notification in notifications">
<a href="#" v-on:click="MarkAsRead(notification)">
{{notification.data.idea.name}} a été validée !<br>
</a>
</li>
<li style="text-align: center" v-if="notifications.length==0">
Aucune notification !
</li>
</ul>
</li>
</template>
<script>
export default {
props: ['notifications'],
methods: {
MarkAsRead: function (notification) {
var data = {
id: notification.id
};
axios.post('/notification/read', data).then(response => {
window.location.href = "/manif/";
});
}
}
}
</script>
Finally i only see {{notifications.length}} write in the badge instead of a number...
Can you help me about this ?
Thank's
The raw mustache tags are shown because you've used v-pre directive in the parent element, which tells Vue to not compile the element and its children:
<a id="navbarDropdown" ... v-pre> <!-- Don't use v-pre here -->
...
<span ...>{{notifications.length}}</span>
</a>
Simply removing that directive should resolve the issue: demo

How to pass a variable without Controller in Laravel 5.4?

I have a application with extends a view with name "notification". How you can see in the picture.
That fragment is just a list, don't extends anything, How I pass a variable to that list? Something fixed. Any suggestion?
<li class="dropdown notifications-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="livicon" data-name="bell" data-loop="true" data-color="#e9573f"
data-hovercolor="#e9573f" data-size="28"></i>
<span class="label label-warning">7</span>
</a>
<ul class=" notifications dropdown-menu drop_notify">
<li class="dropdown-title">Você tem novas notificações</li>
<li>
<!-- inner menu: contains the actual data -->
<ul class="menu">
#foreach($notificacao as $value)
<li>
<i class="livicon default" data-n="asterisk" data-s="20" data-c="white"
data-hc="white"></i>
Você tem novas perguntas
<small class="pull-right">
<span class="livicon paddingright_10" data-n="timer" data-s="10"></span>
{{$value->created_at->diffForHumans()}}
</small>
</li>
#endforeach
</ul>
</li>
<li class="footer">
View all
</li>
</ul>
</li>

Resources