Laravel if condtition with two buttons - ajax

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.

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 do I target the InnerText of a custom PowerAutomate Desktop Selector

I am trying to understand the custom selector function for a web ui button. I essentially just want to target a button that has "Add to account" as the value. That should be just the InnerText right? It's not in the VIsual Editor so I am trying to do with the custom. Is it button[innerText="Add to Account"]? Struggling to get that to work right now.
Here is the markup
<button data-ng-if="vm.userPermissions.accountOnly" data-ng-disabled="!vm.canFinish || !vm.hasFeeSchedule" class="btn btn-primary ng-scope" data-ng-click="vm.accountOnly()"><i class="fa fa-plus" aria-hidden="true"></i> Add to Account</button>
Ok figured it out. button:contains("Add to Account")

how to hit an api on button click using 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.

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

twitter bootstrap popover within a dropdown menu not working

<div class="btn-group">
<button class="btn dropdown-toggle" data-toggle="dropdown"> Reviews </button>
<button class="btn dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></button>
<ul class="dropdown-menu">
<li>testuser 2012/08/12 12:25:42:836 PM</li>
<li>testuser11 2012/08/13 12:25:42:836 PM</li>
</ul>
</div>​
I am using bootstrap.min.js v2.0.4 and jquery 1.7.2, tried with jquery 1.8.0 and 1.7.1 with same results
I have this js code in tbspopover.js -
jQuery(function(){
$('a[rel=popover]').popover();
});
Script Order
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="/vendor/bootstrap.min.js"></script>
<script src="/js/views/tbspopover.js"></script>
The js function to enable popover was called before the element was added to DOM. The DOM element wasn't added until after ajax call was done. Found a tip here
With an older Version (2.0.2) of Bootstrap it should work.
You can find a working example here.
Older Versions of Twitter Bootstrap can be found on Github here.
I had a similar issue, it was because font-size of .btn-group was set to ZERO!!

Resources