Laravel and Vuejs: how to use vuejs in laravel multi page application - laravel

i have a multiple pages application that i build in Laravel, i want to use Vuejs in some parts of the application.i have six modules customers,invoice,products,stocks,dashboard,analysis.
The customers,products,stock are just basic crud so i use Laravel.
How to do i turn the invoice,analysis,dashboard in single page applications. i have tried but when i use chromes back arrow to redirect back, i get 404|page not found.
this is my invoice/index.blade.php file, it loads everything corrently
<div class="row">
<div class="col-md-12">
<invoice-index></invoice-index>
</div>
</div>
inside my component, when i click on any link i a 404 error. i have tried router-link , 'a href' none is redirecting me to invoiceform
<template>
<div class="row">
<div class="col-md-12">
<div class="tile">
<div class="row pb-3">
<div class="col-md-12">
<div class="tile-header">
new Invoice
</div>
</div>
</div>
<div class="tile-body">
<table class="table table-hover table-bordered">
<thead>
<tr>
<th> # </th>
<th style="with:20%"> Date </th>
<th> Number </th>
<th> Customer </th>
<th> Due Date </th>
<th> Total </th>
<th style="width:100px; min-width:100px;" class="text-center text-danger"><i class="fa fa-bolt"> </i></th>
</tr>
<tr v-for="invoice in allInvoices" :key="invoice.id" class="py-0 text-center" >
<td class="align-middle py-0">
<a href="#" class="nav-link text-info font-weight-bold">
{{ invoice.id }}
</a>
</td>
<td style="width: 10%">{{invoice.date}}</td>
<td >{{invoice.number}}</td>
<td >{{invoice.customer_id}}</td>
<td >{{invoice.due_date}}</td>
<td >{{invoice.total}}</td>
<td class="text-center">
<div class="btn-group" role="group" aria-label="Second group">
<i class="fa fa-edit"></i>
<i class="fa fa-trash"></i>
</div>
</td>
</tr>
</thead>
</table>
</div>
</div>
</div>
I this is my routes
const router = new VueRouter({
routes: [
{
path:'/dashboard',
component: DashboardComponent
},
{
path:'/invoices',
component: InvoiceIndex
},
{
path:'/invoices/create',
component: InvoiceForm
}
],
mode:'history'
});

For SPA with Vue.js, You must define links using vue-router. When defined routes using vue-router, you can use your vue.js routes and only calls components. So you can build SPA. You can find details on here.
https://router.vuejs.org/
I hope it helps you. But It can be hard to implement if you are new on Vue.js

Related

Laravel 9 404 Error on GET Request updating database when clicking button

I was having another laravel question here. I was facing 404 error when clicking the button
Confirm Registration on the purpose of changing its database based on the item id on the view. Logically, I think my code should have work on this part.
Confirm Registration
However, it comes up 404 Error. Herby I include all the related code in the section.
Error
Frontend (To prove that the data passing is successful in the view)
web.php
Route::controller(ResidenceController::class)->group(function(){
Route::get('/residence/register', 'registration')->name('residence.register');
Route::get('/residence/search', 'SearchProperty')->name('residence.search');
Route::get('/registration/confirmation/{$uniquecode}', 'ConfirmRegistration')->name('registration.confirm');
});
The focus is on:
Route::get('/registration/confirmation/{$uniquecode}',
'ConfirmRegistration')->name('registration.confirm');
Controller
public function ConfirmRegistration($uniquecode){
$confirm = Properties::where('uniquecode', $uniquecode)->update(['status'=>'pending', 'tenant_id'=>Auth::user()->id]);
if($confirm){
session()->flash('alert-success','Successfully Applied');
}
else{
session()->flash('alert-warning','Error Occured');
}
}
register.blade.php
#foreach ($toSearch as $key=>$view)
<div class="card" style="width: 50rem;">
<div class="card-body">
<div class="container">
<div class="row">
<div class="col-md-3">
<img src="{{ (!empty($tenant->unit_image))? url('uploads/properties/'.$tenant->unit_image):url('uploads/properties/default.jpg') }}" class="img-fluid" alt="unit image" >
</div>
<div class="col-md-9">
<table>
<tr>
<td style="width: 20%">Property</td>
<td style="width:10%; text-align: center">:</td>
<td>{{$view->name}}</td>
</tr>
<tr>
<td>Address</td>
<td style="text-align: center">:</td>
<td>{{$view->address1}},{{$view->address2}},{{$view->city}}</td>
</tr>
<tr>
<td>Landlord</td>
<td style="text-align: center">:</td>
<td>{{$view->landlord->name}}</td>
</tr>
<tr>
<td>Contact No</td>
<td style="text-align: center">:</td>
<td>{{$view->landlord->phone_number}}</td>
</tr>
<tr>
<td>Status</td>
<td style="text-align: center">:</td>
<td>{{$view->status}}</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<br>
<!--To confirm registration-->
#if( $view->status != 'approved')
Confirm Registration
#endif
</div>
#endforeach
The focus is on:
#if( $view->status != 'approved')
uniquecode) }}" class="btn btn-primary">Confirm
Registration
#endif
Database:
you need to use post method for inserting data (register),
anyway, change your route parameter $uniquecode to uniquecode.
and when you use route second argument is a compact, use
route('registration.confirm',['uniquecode' => $view->uniquecode]);

Add user email addresses separated by commas in Laravel

I want to add the selected users to a separate table from the list of all users. Similar to the Trello feature, just # and tag their name. I have no idea what to write this function. Any ideas?
This is the form on my interface, and I do not know what to do next in the controller and the form block.
<div class="tab-pane fade" id="group-add-members" role="tabpanel">
<div class="users-manage" data-filter-list="form-group-users">
<div class="mb-3">
<div class="form-group row">
<textarea class="form-control col" name="group-description"
placeholder="Add users by email, each email separated by
commas
e.g: matt#.edu.com, joe#edu.com" rows="3">
</textarea>
</div>
<div class="row align-items-center">
<div class="col">
<button class="btn btn-outline-primary" type="button">
<i class="fad fa-user-plus"></i>Add</button>
<span>   or   </span>
</div>
<div class="d-none d-md-block col-4 col-lg-5 text-right">
</div>
</div>
<div class="row align-items-center mt-2">
<div class="d-block d-md-none d-sm-block ml-2">
</div>
</div>
</div>
<hr>
<h6>Member info</h6>
<div class="row justify-content-center">
<div class="table-responsive mt-3">
<table class="stripe" id="example" style="width:100%">
<thead>
<tr>
<th></th>
<th class="text-left">Full name</th>
<th class="text-left">Email</th>
<th class="text-left">Student ID</th>\
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td class="text-left">My name</td>
<td class="text-left">qnv164#edu.com</td>
<td class="text-left">123456789</td>
<td>
<span class="ic-dark"><i class="fad fa-trash-alt"></i></span>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<th></th>
<th class="text-left">Full name</th>
<th class="text-left">Email</th>
<th class="text-left">Student ID</th>
<th>Action</th>
</tr>
</tfoot>
</table>
</div>
<!-- end div table responsive -->
</div>
<!-- end div row -->
</div>
</div>
{{ profile->description ?? 'Not Available' }}

Update Data Using Modal on Laravel

I want to create edit data on laravel using a modal for view .
but i dont know how to catch one data on on my edit form .
i build controller like edit data on another page ( not using modals )
public function index()
{
$ipsrs = DB::table('ipsrs')->pluck('nama_bagian','id');
$belum_kerjakan = Aduan::with('users')->where('status','Belum Dikerjakan')->get();
$dalam_proses = Aduan::with('users')->where('status','Sedang Dikerjakan')->get();
$selesai = Aduan::with('users')->where('status','Selesai')->get();
return view('admin.admin_dashboard',[
'belum_dikerjakan' => $belum_kerjakan,
'dalam_proses' => $dalam_proses,
'selesai' => $selesai,
'ipsrs' => $ipsrs,
]);
}
public function change_aduan($id)
{
$aduan = Aduan::findOrFail($id);
if (!$aduan)
abort(404);
return view('admin.admin_dashboard',[
'aduan' => $aduan
]);
}
this route . ( but i dont know where i used this route ?
Route::get('admin_dashboard', 'AdminController#index')->name('admin_dashboard'); // this route for view table
Route::get('change/{id}','AdminController#change_aduan')->name('change_aduan'); // this route "will" showing data on this modals
my View
<div class="card-body" align='center'>
<div class="card-body p-0">
<table class="table table-condensed">
<thead align="center">
<tr class="satu">
<th style="width: 3%">#</th>
<th style="width: 10%">Nama Unit</th>
<th style="width: 15%">Tanggal Aduan</th>
<th style="width: 8%">Nama Pengadu</th>
<th style="width: 8%">Tujuan Aduan</th>
<th style="width: 30%">Isi Aduan </th>
{{-- <th>Label</th> --}}
<th style="width: 5%">Status</th>
<th style="width: 5%">Action</th>
</tr>
</thead>
<tbody>
#php
$no=0;
#endphp
#foreach ($belum_dikerjakan as $i)
<tr>
<td> {{++$no}} </td>
<td> {{$i->users->nama_unit}}</td>
<td> {{$i->created_at}} </td>
<td> {{$i->nama_pengadu}} </td>
<td> {{$i->ipsrs->nama_bagian}} </td>
<td> {{$i->aduan}}</td>
<td><span class="badge bg-danger"> Belum Dikerjakan</span></td>
<td><button type="button" class="btn btn-default" data-toggle="modal" data-id="{{$i->id}}" data-target="#modal-lg" > // modals button
Action
</button></td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
<div class="modal fade" id="modal-lg">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title"> Change Status </h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{{-- Here this Form --}}
{{-- {{$aduan->nama_pengadu}} --}} // this Line is failur
</div>
<div class="modal-footer justify-content-between">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
i dont know how to next step , on another tutorial this data is can showed using {{ $data->name }} , but in my view cant do this . whats wrong ,and how i can solved this ?
I think you are not far off. I believe the issue you are having is that you are trying to pull the name field from a collection instead of an object.
In your Blade file, this line:
<td> {{$i->users->nama_unit}}</td>
is essentially saying: for this iteration ($i) of $belum_dikerjakan, give me ALL the users and tell me the name of the collection of users. The collection doesn't have a name field. Because you have many users for this $belum_dikerjakan, you will either need to loop on all of them, identify the specific user by id (example $i->users->where('id', 1)->first()->nama_unit), or take the first one randomly:
$i->users->first()->nama_unit
What these examples do, is it pulls a single object user instead of a collection, and thus you have the field name on that object.
This line:
<td> {{$i->ipsrs->nama_bagian}} </td>
doesn't look like a relationship at all, and you may need to refactor this into either a relation on $belum_dikerjakan, or remove it from the loop and use it independently, but this is a separate issue I think.
Hope this helps.

datatable shows blank spaces below the paginator links

I'm using larashop admin panel.The datatable shows blank spaces below the datatable..The height blank spaces increases with increase in datatable entries.I don't know what to do..
I tried some css.but none of them helped me.
#extends('templates.admin.layout')
#section('title', 'All Courses')
#section('content')
<div class="">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>Courses <i class="fa fa-plus"></i> Create New </h2>
<div class="clearfix"></div>
</div>
<div class="x_content">
<table id="datatable-buttons" class="table table-responsive">
<thead>
<tr>
<th>Course Name</th>
<th>Action</th>
</tr>
</thead>
<tfoot>
<tr>
<th>Course Name</th>
<th>Action</th>
</tr>
</tfoot>
<tbody>
#if(count($courses))
#foreach ($courses as $row)
<tr>
<td>{{$row->name}}</td>
<td>
<i class="fa fa-pencil" title="Edit"></i>
<i class="fa fa-trash-o" title="Delete"></i>
</td>
</tr>
#endforeach
#endif
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
#stop
The screenshot of the issue is provided..please check...
https://i.stack.imgur.com/avqf5.png

Ajax Get Data on Laravel

I'm really new to MVC hope you can give me a detailed instructions on this.
I have a query in my repository that returns pending users who have a certain role_id. Now my issue is this I when the administrator clicks on the anchor tag of id idMessenger below
<li> Messenger<span class="label label-danger pull-right">{{$messenger->count()}}</span> </li>
I want to show the pending messengers only in the
<div class="col-md-2 left-aside">
<div class="scrollable">
<ul class="inbox-nav capitalize-font">
<li>All Pending Applications </li>
<li>Clients<span class="label label-danger pull-right">{{$elderly->count()}}</span></li>
<li> Messenger<span class="label label-danger pull-right">{{$messenger->count()}}</span> </li>
</ul>
</div>
</div>
<!-- /.left-aside-column-->
<div class="col-md-10 right-aside">
<div class="scrollable">
<div class="table-responsive">
<table id="datable_1" class="table display table-hover contact-list" data-page-size="10">
<thead>
<tr>
<th>Appication ID</th>
<th>Name</th>
<th>Email</th>
<th>Senior Citizen Number</th>
<th>Role/Submitted as</th>
<th>Date of Submission</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
#foreach($allPending as $user)
<tr>
<td>{{$user->id}}</td>
<td>{{$user->name}}</td>
<td>{{$user->email}}</td>
<td>{{$user->scn}}</td>
<td><span class="label label-danger">{{$user->roles->name}}</span></td>
<td>{{$user->created_at}}</td>
<td>
<i class="fa fa-check"></i>Approve
</td>
<td>
<i class="fa fa-trash"></i>Delete
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
Can you please teach me how to do it in ajax.

Resources