have a look
vuejs
data() {
return {
url: '/api/client/document/upload',
}
},
computed
attachment() {
return {
slug: 'testing',
test_type[enter image description here][1]: (this.individual === 1)? 'transfer_individual': 'transfer_corporate',
application_id: this.client_investment_id
};
upload method
upload: function () {
if(!this.validateForm()) {
Message.warning({ message: 'Complete the form and proceed' });
return;
}
if(!this.$refs.upload.uploadFiles[0]) {
Message.warning({ message: 'Upload the form and proceed' });
return;
}
console.log('data', this.attachment);
this.$refs.upload.submit();
},
controller side laravel
public function uploadDocument()
{
$input = request()->all();
dd($input);
}
there is a file am uploading to the given url;
when i dd from the controller i get an application_id of null but if i console.log before the submittion am able to view my data. what may i be doing wrong.
console.log output
dd output
Pass the request as parameter to the function and call the all() method on the request instance.
public function uploadDocument(Request $request)
{
$input = $request->all();
dd($input);
}
To take and save file with its name concatenated with a timestamp in public/images folder try
//Assuming you have the file input name as `photo`
if ($file = $request->file('photo')) {
$name = time() . $file->getClientOriginalName();
$file->move('images/', $name);
}
this is the form ...note its taking with it the attachment data from computed property..
<el-upload
class="upload-demo"
drag
:action=url
ref="upload"
:data=attachment
:headers="defaultHeaders"
:on-error="errorOnUpload"
:on-success="showUploadSuccess"
:accept=extensions
:thumbnail-mode="false"
:auto-upload="false">
</el-upload>
<el-button type="success" size="mini" #click="upload" class="el-icon-upload">upload</el-button>
i have noted that i set the application_id to be set to the store when client applies, but now am dealing with edit, its taking the default state of the application_id which is null
Related
With Laravel 9/Inertiajs 3 I have page under adminarea with checking that user is logged as admin:
My vuejs page is container vue file and I read data using axios(that gives me possibility to run filter without all page reloading) :
axios.post(route('admin.currencies.filter'), filters)
.then(({data}) => {
currencyRows.value = data.data
})
.catch(e => {
showRTE(e) // custom error
console.error(e)
})
and :
<?php
class CurrencyController extends Controller
{
public function index()
{
if ( ! auth()->user()->can(ACCESS_APP_ADMIN_LABEL)) {
return redirect(route('admin.dashboard.index'))
->with( 'flash', 'You have no access to currencies listing page')
->with('flash_type', 'error');
}
return Inertia::render('Admins/Currencies/Index', []);
}
public function filter()
{
\Log::info( varDump(-9, ' -9 filter::') );
if ( ! auth()->user()->can(ACCESS_APP_ADMIN_LABEL)) {
\Log::info( varDump(-98, ' -98 INSIDE filter::') );
return redirect(route('admin.dashboard.index'))
->with( 'flash', 'You have no access to currencies filter method')
->with('flash_type', 'error');
}
...
$currencies = Currency
::getByName($filter_name)
->orderBy($order_by, $order_direction)
->paginate($backend_items_per_page, array('*'), 'page', $page);
return (CurrencyResource::collection($currencies)); // collection of resources
} // public function filter()
...
php>
The problem is that when in filter method invalid access code is run(I check it in file) app is not redirecred to dasboard page, but is run next
and I got javascript error as filter method did not return valid data which are expected on client...
Looks like redirect can not be run from axios code... How that can be done?
Thanks!
You may change axios to this.$inertia : [https://inertiajs.com/manual-visits]
this.$inertia.post(this.route('...'),{},{
only:['...']
});
Preview Your File
here link click to open pdf its fine but i want to insert some data when click this link how to insert and how to pass data laravel
You can do this in two methods
1: Using Ajax:
First insert your data then in the success redirect to your file .
2: using controller to redirect you to the file
use form to submit the data you want to controller then via controller redirect it to your file after adding data to database
something like this
public function AddDataToDatabase(Request $request)
{
$datas=New DataModal();
$datas->name = $request->name;
$datas->address = $request->address;
$datas->lastName = $request->lastName;
$datas->email = $request->email;
$data->save();
$items=Attachments::where('id',1)->get();
return redirect('Attachments/'.$items[0]->attachmentName);
}
or Using Ajax
$.ajax({
type: "POST",
url: your_URL,
data: {
'name':'your_name',
'id':'your_id',
'email':'your_email',
},
success: function(data) {
window.location = 'https://localhost/sample.pdf';
},
error: function(e) {
console.log(e);
}
});
then in your controller create a new method like this:
public function AddDataToDatabase(Request $request)
{
$datas=New DataModal();
$datas->name = $request->name;
$datas->address = $request->address;
$datas->lastName = $request->lastName;
$datas->email = $request->email;
$data->save();
return response()->json(['msg' => 'added successfully'],200);
}
Instead of a link, create form that contains the fields that you want to store in database. Make the fields hidden if they won't be filled by the user. Then submit the form to a controller. Store the data, redirect to a new path that will display the pdf.
When I click submit I get this message.
ReferenceError: input is not defined
How to get last id number in console.log when I create a new data and click on save or submit button?
Controller
public function store(Request $request)
{
if($request->ajax()) {
$school = new SchoolsList();
$school->user_id = auth()->user()->id;
$school->province_id = $request->province_id;
$school->city_id = $request->city_id;
$school->center_id = $request->center_id;
$school->save();
return response()->json(['data_school' => $request->all(), 'id' => $school->id]);
}
}
Ajax
<script type="text/javascript">
$("#schools").submit(function (event) {
event.preventDefault();
data_school = input.value;
province_id = $('#province_id').val();
city_id = $('#city_id').val();
center_id = $('#center_id').val();
$.post("{{ route('schools-list.store') }}", {province_id:province_id, city_id:city_id, center_id:center_id}, function (data_school) {
console.log(response.data_school.id), function (response) {
console.log(response.data_school.id);
}
});
});
</script>
In your JavaScript you have "data_school = input.value;"
input is not defined and also not needed.
just remove that.
Also the last line of code console.log(response.data_school.id) is wrong. You set your own data structure, which is response.id
Currently, i am on the show page that is i am running the function show as in my controller so my url is showing like dashboard/1/people in the url address bar. Now, when i click on a person, it routes to a different page and that is where getPeople is called.
How can i get the id of the person i clicked which is 1 from the ajax request in the scripts and pass to my controller?
PS: At the moment, i have hardcoded 1 in the ajax request but i want it to be dynamic please
How do i get this done?
Script
datatable = $('#table').DataTable({
"ajax": "{{ route('dashboard/1/people') }}",
"columns": [
{data: 'check', name: 'check'},
],
Controller
public function show($id)
{
$class = Class::whereId($id)->first();
return view('show');
}
public function getPeople($id)
{
$get_id = $id;
$class = Class::whereId($get_id)->first();
$people = $class->peoples()->get();
return Datatables::of($people)->addColumn('action', function ($ppl) {
//return
})->make(true);
}
This should work:
In your getPeople method store the id in a session variable:
public function getPeople($id)
{
$get_id = $id;
//using session helper method
session(['show_id' => $id]);
$class = Class::whereId($get_id)->first();
$people = $class->peoples()->get();
return Datatables::of($people)->addColumn('action', function ($ppl) {
//return
})->make(true);
}
and then access it in you ajax code:
datatable = $('#table').DataTable({
"ajax": "{{ route('dashboard/'.session('show_id').'/people') }}",
"columns": [
{data: 'check', name: 'check'},
],
DataTable ajax allows yo to pass extra parameters in object format just like this:
datatable = $('#table').DataTable({
"ajax": {
"type": "GET",
data:{id: my_id_var},
"url": "my_route"
}
}
And in your function just get the Request var
public function getPeople(Request $request){
$get_id = $request->id;
$class = Class::whereId($get_id)->first();
$people = $class->peoples()->get();
return Datatables::of($people)->addColumn('action', function ($ppl) {
//return
})->make(true);
}
More Information in Sorce Page
I am unable to load select box value when I want to update the value. The same code perfectly working when I am going to save value.
My controller code is:
public function listwardByCircle($category = "") {
$this->layout = 'ajax';
$this->beforeRender();
$this->autoRender = false;
$ward=$this->Ward->find('list',array(
"fields" => 'id, wardname',
"conditions" => array('Ward.circle_id' => $category)
));
//$this->set('ward',$ward);
print_r($ward);
foreach($ward as $key => $val) {
echo "<option value=$key>$val</option>";
}
}
And this is my js code :
$("#AreaCircleId").change(function() {
alert("testing....");
$.post('../Admins/listwardByCircle/' + $(this).val(), function(data) {
alert( data);
$("#AreaWardId").empty().append(data);
}, 'html');
});
In js file
Url in Controller Like
`\../../Admins\/listwardByCircle`
You may need to update your URL post location in the ajax from:
$.post('../Admins/listwardByCircle/'
to
$.post('/admins/listwardByCircle/'
This is if the controller name is admins.