how to hit an api on button click using laravel - laravel

i am new to working with API ,i have 2 buttons in my view file and i want to print the sheet which is available as an API ,
<div class="card">
<div class="card-body">
#include('admin.inc.messages')
<div class="row justify-content-center">
<div class="col-md-4">
<button type="button" class="btn btn-primary btn-block">Back</button>
<button type="button" class="btn btn-primary btn-block">Print Airway Bill</button>
<button type="button" class="btn btn-primary btn-block">Print Invoice</button>
</div>
</div>
</div>
</div>
i have got the path , i want to ask where should i define the path for that , in the web.php or api.php
and second thing how should i give the path in the buttons
any help will be appreciated !

You will need to consume your own api, most likely, or use ajax request. This can be done via passport, seen here in the documentation. If you want you can always bypass, however you will not have the ability to utilize middleware with those requests. Meaning, that your project will be subjected to potential security risk as the request will not be subjected to route middleware. Which protect and assist you in some regards.
For example, if you cannot authenticate against a middleware you will not have the ability to determine which/what user is requesting data. Another comparison one might make would be the ability to login against a user, but then not have the ability through out the application pages to know which user was authenticated. This is comparable to when you log in to stackoverflow you can obviously see you user information/profile in the top right with your picture etc... If you by pass you will not have that ability.
Therefore, I would highly recommend visiting the link posted above and consider consuming your own api or creating a service to do so.

Related

Laravel Livewire + Firefox: wire:submit.prevent not working, form submitted as GET request

I have a problem when submitting form in Laravel Livewire and when using Firefox. It works well in Chrome. In Firefox - it sometimes works correctly and submits the form through livewire, but mostly it gets submitted as GET request - https://example.com/?formResponse=...
Here's a short snippet of my code.
<form wire:submit.prevent="update" class="d-flex">
<textarea name="formResponse" wire:model.defer="formResponse" id="response" class="form-control h-50"></textarea>
<button class="btn btn-primary">Uložiť</button>
</form>
try :
<button type="button" class="btn btn-primary">Uložiť</button>

How to Implement Pusher Note for Laravel 5 project.?

Hello Laravel vue.js Developers, please help me, i try to implement Laravel note sharing with others by Pusher but when i try to edit the note i cant retrieve my olders on, juste FYI i want to create a note and share it with another user for correction.
Please i have implement this package from this site: https://pusher.com/tutorials/collaborative-note-app-laravel.
Thank you a lot for your help.
Edit.blade.php
#extends('layouts.admin')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<edit-note :note="{{ $note }}"></edit-note>
</div>
</div>
</div>
#endsection
My problem is when i click to edit the note i can't call the EditNote.vue.

Laravel if condtition with two buttons

i am using Ajax with laravel, i have two buttons, Add and Update, what i am trying to achieve is, if i click on Update button,
Laravel #if statement should run,
#if(isset($teacher))
if i click on add button Laravel #else statement should run,
Complete Code:
<button class="btn btn-secondary" id="add" > </span > ADD NEW</button>
<button class="btn btn-secondary" id="update"> UPDATE OLD</button>
#if(isset($teacher))
#foreach($teachers as $teacher)
#endforeach
<button class="btn btn-secondary" id="update-t"> UPDATE Teacher</button>
#else
<button class="btn btn-secondary" id="add-t" > ADD Teacher</button>
#endif
You are misunderstanding the way Laravel Blade templates work.
Blade template is rendered into PHP, than executed to render HTML, which is sent to your browser to render it client-side. This is the moment when your JavaScript functions will start working, and they cannot interfere with what was previously rendered, as JavaScript will only 'see' the final HTML render.
Solution to your problem if you want to use AJAX, is to create some kind of API, which will be processed in AJAX's success function.

My Laravel 5.4 Logged in User Sessions wont persist

I'm having this weird issue with my app, it can't persist logged in user session using the Auth facade. Example, in my header view I put logged in user data as :
#if (Auth::check())
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
<img src="{{route('getphoto', Auth::user()->image)}}" alt="" />
{{ Auth::user()->name }}
<span class="caret"></span>
</button>
</div>
#else
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
Not Logged In
</button>
</div>
#endif
At the first time after login the logged in user data in the header like photo and name will be displayed correctly, but after I refresh or moving to another page they disappear and indicate that the user is not logged in. I don't know what I did wrong, all I did with user login related function is just changing the email to username. How do I solve this ? I'm using Laravel 5.4
You need to set correct permissions for the storage directory:
chmod -R 755 storage
After installing Laravel, you may need to configure some permissions. Directories within the storage and the bootstrap/cache directories should be writable by your web server.
https://laravel.com/docs/5.4/installation

How to auto refresh a page on an embedded google form submit

Note upfront: I do not have any experience using scripts but only some basic HTML and PHP skills.
I would like a page on my google site to refresh automatically as soon as the embedded google form was submitted. This to instantly display the embedded and updated google form results after the button is clicked without the visitor having to reload the page manually. (like you would have for any online poll)
My form sheet is updating perfectly but I have not yet found an example or tutorial how to make a page refresh work for the google site with an embedded google form when the submit button is clicked. I hope someone can help me by providing an example on how to make this work. Preferably I would like to use an embedded google form rather than having to create a separate PHP form loading into google forms what could be an alternative. Thanks.
Below the HTML as I can see it on my Google page. I would need a trigger I guess from these embedded forms to refresh the page on submit. I just have no idea on how to get this done.
<div>
<div style="text-align:left">
<div><img src="https://www.google.com/chart?chc=sites&cht=d&chdp=sites&chl=%5B%5BSpreadsheet+form'%3D20'f%5Cv'a%5C%3D0'10'%3D499'0'dim'%5Cbox1'b%5CF6F6F6'fC%5CF6F6F6'eC%5C0'sk'%5C%5B%22test+int+sheet%22'%5D'a%5CV%5C%3D12'f%5C%5DV%5Cta%5C%3D10'%3D0'%3D500'%3D397'dim'%5C%3D10'%3D10'%3D500'%3D397'vdim'%5Cbox1'b%5Cva%5CF6F6F6'fC%5CC8C8C8'eC%5C'a%5C%5Do%5CLauto'f%5C&sig=5VZGSIULBu8sSdf833qiLWVDcx8" data-origsrc="1VACx4d2pJEZlvAezbO9Gnh_nX3nIPwSJ4iCNjEmCiUM" data-type="spreadsheet-form" data-props="align:center;borderTitle:test int sheet;doctype:freebird;height:400;objectTitle:test int sheet;showBorder:false;showBorderTitle:false;wrap:false;" width="500" height="400" style="display:block;margin:5px auto;text-align:center;"></div>
<br>
</div>
<div style="text-align:left"><img src="https://www.google.com/chart?chc=sites&cht=d&chdp=sites&chl=%5B%5BGoogle+Gadget'%3D20'f%5Cv'a%5C%3D0'10'%3D499'0'dim'%5Cbox1'b%5CF6F6F6'fC%5CF6F6F6'eC%5C0'sk'%5C%5B%22Include+gadget+(iframe)%22'%5D'a%5CV%5C%3D12'f%5C%5DV%5Cta%5C%3D10'%3D0'%3D500'%3D397'dim'%5C%3D10'%3D10'%3D500'%3D397'vdim'%5Cbox1'b%5Cva%5CF6F6F6'fC%5CC8C8C8'eC%5C'a%5C%5Do%5CLauto'f%5C&sig=t6_Deqv8rgMQCB28aqz1n9MoVTU" data-igsrc="http://164.gmodules.com/ig/ifr?mid=164&synd=trogedit&url=http%3A%2F%2Fhosting.gmodules.com%2Fig%2Fgadgets%2Ffile%2F106581606564100174314%2Fiframe.xml&up_iframeURL=https%3A%2F%2Fdocs.google.com%2Fspreadsheets%2Fd%2F1g2cGeavUciTy6po7_DXPXMNqC1fqTTROHRoTnsafFfM%2Fpubhtml%3Fgid%3D754672963%26single%3Dtrue&up_scroll=no&h=400&w=100%25" data-type="ggs-gadget" data-props="align:center;borderTitle:Include gadget (iframe);height:400;igsrc:http#58//164.gmodules.com/ig/ifr?mid=164&synd=trogedit&url=http%3A%2F%2Fhosting.gmodules.com%2Fig%2Fgadgets%2Ffile%2F106581606564100174314%2Fiframe.xml&up_iframeURL=https%3A%2F%2Fdocs.google.com%2Fspreadsheets%2Fd%2F1g2cGeavUciTy6po7_DXPXMNqC1fqTTROHRoTnsafFfM%2Fpubhtml%3Fgid%3D754672963%26single%3Dtrue&up_scroll=no&h=400&w=100%25;mid:164;scrolling:no;showBorder:false;showBorderTitle:null;spec:http#58//hosting.gmodules.com/ig/gadgets/file/106581606564100174314/iframe.xml;up_iframeURL:https#58//docs.google.com/spreadsheets/d/1g2cGeavUciTy6po7_DXPXMNqC1fqTTROHRoTnsafFfM/pubhtml?gid=754672963&single=true;up_scroll:no;view:default;width:100%;wrap:false;" width="500" height="400" style="display:block;margin:5px auto;text-align:center;" class="igm"></div>
<div style="text-align:left"><br>
</div>
<div style="text-align:center">
<div></div>
<br>
</div>
<div style="text-align:left">
<div style="text-align:center"><br>
</div>
<div style="text-align:center"><br>
</div>
<br>
</div>
</div>
I'm sorry to be the annunciator of a such bad news but that's impossible.
As your code show, you are actually using a google Site to display your google form. The line:
<img src="https://www.google.com/chart?chc=sites&cht=d&...
IS the way google tell you there is a google form in this page when you hit the button to get the source code.
In other words: google don't let you put whatever you want in a google site. It's impossible to add some JS code that will be fired when the user submit the form.
Even if you host your form in something else than a google Site, you won't have this ability, as the form himself will be displayed in an iframe that can't be modified by external scripts.
This is an hard limitation of Google Form, the only workaround that you may use is to write to the user in the confirmation message of the form that he now need to reload the page or go to an other link.

Resources