Laravel 9 : Date data null or not - laravel

I'm here to ask you a question for my Laravel 9 project if it's possible please :) !
I made an authentication with a user table. There is a column where you can check if the user verified his/her email or not. If he/she does, there is a datetime. If not, the column is null.
I would like to make a div in the profile section where there is an information for the user about the verification. If the verification is done, green information with the message "Good your email is verified", if not there is a red information with "Email not verified".
I tried this but it doesn't work, it stays on "NOT VERIFIED" however there is a datetime in this session user.
Do you know why ? Or how can I fix it ?
Thanks a lot !
Code
Data structure

#if(Auth()->user()->isVerified)
<div style="color:green">Good email is verified</div>
#else
<div style="color:red">Email not verified</div>
#endif

Please try using this
{{ auth()->user()->isVerified == null ? 'Not Verified' : 'Verified' }}

Try following
#if(Auth::check())
#if(Auth()->user()->isVerified)
<div style='color:green'>Good your email is verified</div>
#else
<div style='color:red'>Email not verified</div>
#endif
#endif
In Laravel there is a default method to determine if an email is verified or not. isVerified field is not necessary to check it.
checkout this answer Laravel check if user email verified

Related

OR and AND operators not working in laravel

A user can set any one cookie on their browser. One that will be set if the submits the their email for subscription and another if they don't want to see the pop up again.
#if(Cookie::get("english")!=1 and Cookie::get("stop_popup")!=1)
//my html code here
#endif
The user should see the subscription popup if they don't have both cookie above. They should not see the subscription box if they have english or stop_popup cookie set in their device.
#if(Cookie::get("english")!=1)
#endif
Only single condition works not both. Why is that? Have I done anything wrong in the above code?
You can use Cookie::has(...) to see if the cookies exists at all as an alternative:
#if (! Cookie::has('english') && ! Cookie::has('stop_popup'))
If the 'english' cookie does not exist and the 'stop_popup' cookie does not exist.
You can try this :
#if (empty(Cookie::get("english")) && empty(Cookie::get("stop_popup")))
// html code here
#endif

My web developer is struggling to integrate SagePay into my Wordpress website

I have 3 questions as of now, please consider and reply point wise, thank you..
I understand the use of Encryption Password (56071ba432970392) and i'm using it to construct the "crypt" field.
But please let me know if the "Encryption key" and "Integration Password" are necessary in the "Form method", as i do not see it's reference in the Form integration protocol guide (https://www.sagepay.co.uk/file/25041/download-document/FORM_Integration_and_Protocol_Guidelines_270815.pdf?token=xecgCPxo3AAFu8UiqobWCsfHOZwMz44crX7lYbBHdvM)
2. In the above guide, in page no. 10 / annex. 3.0 / Step 2 > There are 4 hidden fields to be sent to sagepay in url and below is the exact data which is sent but with 5080 error code.
include("lib/sagepay.php");
$key = '56071ba432970392';
$paymentString = "VendorTxCode=abc123&Amount=$amount&Currency=GBP&Description=$description&BillingSurname=$lname&BillingFirstnames=$fname&BillingAddress1=$address&BillingCity=$city&BillingPostCode=$zip&BillingCountry=$country&DeliverySurname=$lname&DeliveryFirstnames=$fname&DeliveryAddress1=$address&DeliveryCity=$city&DeliveryPinCode=$zip&DeliveryCountry=$country&SuccessURL=https://www.life-changing-adventures.com/success&FailureURL=https://www.life-changing-adventures.com/failure";
<input type="hidden" name="VPSProtocol" value="3.00">
<input type="hidden" name="TxType" value="PAYMENT">
<input type="hidden" name="Vendor" value="lifechangingadv">
<input type="hidden" name="Crypt" value='<?php echo SagepayUtil::encryptAes($paymentString, $key); ?>'>
------------------------------
In the sagepay online support page (https://www.sagepay.co.uk/support/error-codes/5080-error-form-transaction-registration-failed)
for 5080 error, it says "You will need to log into your Sage pay account. Once you have logged in select the transactions tab, and then the Invaild sub screen from the options on the left."
But as attached, the "invalid" tab screen is empty from the start, so i cannot figure out the reason.
The encryption key is accessed via your MySagePay admin user (uses the same username as your vendorname).
5080 error - https://www.opayo.co.uk/support/error-codes?keyword=5080
If your encryption is not being done as expected you will receive this error. If you are encrypting correctly you will reach the Opayo payment process. The invalid tab only populates when you have done this and have then passed an invalid character in a field for example.

Request data from database after select in a form has been used

I am really sorry that I bother you again with my question, but this time I am asking about a kind of best practice. I found already various articles/posts about the topic and followed this article: https://makitweb.com/auto-populate-dropdown-with-jquery-ajax-in-laravel/ how to fill a second select based on the choice of a first select. As far as I can see, I have to use javascript and create new route.
My question would be is a new route the best idea because I also can also just call it by itself in the URL bar, eg. URL /getEmployees/1
How can I archive that I still get the required information but at the same time avoid that the URL can be used. Do I have to fetch all required data in the controller itself before I return the view and then filter them?
Thanks
Stephan
Update:
Another approach/try,
What is if I pass directly both tables to my view:
return view ('test')->with(compact('stuff_types'))->with(compact('positions'));
By the way, it really does not matter to select all data in the first instance, both tables will only have a couple of rows.
However, is it now possible to put a filter on the second table in the select view?
{{Form::select('position2', $positions, null, ['class'=>'form-control', 'id'=>"positions2"]) }}
I already tried $positions->where(‘id’, ‘1’), searched the internet for other ways but it always filles the select with the complete table information.
Later on I would love to put a filter with a javascript on the second table, based on the result of the first select, but at first it would be really nice just to see a where condition on it.
Update 2
Ok, another update / question:
Instead of using laravel collectives with
{{Form::select('position2', $positions::pluck('name', 'id'), null, ['class'=>'form-control', 'id'=>"positions2"])}}
I can use html and add an if condition, which I guess can be modified through javascript (will check tomorrow)
<select name="categories" id="categories" class="form-control">
#foreach($positions as $sector)
#if ($sector->id == 2)
<option value="{{ $sector->id }}">{{ $sector->name }}</option>
#endif
#endforeach
</select>
But now I am struggling with my controller. Before I was using this:
$ positions = DB::table('positions')->pluck('name','id');
But this does not seem to work with a standard select so I had to change the pluck to get, but now the larabel collective is not working anymore
$positions = DB::table('positions')->get();
Can anyone explain we why get() works with html, but not with laravel collectives, and vice versa?

Laravel show page only to signed in user

How do I show a page only to a specific person that's signed in. For example if I've localhost/public/article/4 that's only allowed for James, how do I make sure that Harry can't see this?
the correct way of do this is associate all users to a Role model. This way you could differenciate one user from others. But if you dont want this way you could use the ID of the user to validate this.
How validate this?
when you make a session in laravel you can access to the user data using
Auth::user()->id, Auth::user()->name, Auth::user()->last_login, etc...
in the controller's function the make the view you could do this (James ID's = 1)
if(Auth::user()->id == 1):
return View::make('path_to_view.show');
else:
return View::make('path_to_view.error');
endif;

Magento contact form customizations

I'm trying to add a couple fields to the contact form so that my customers can indicate the year make and model of their vehicle when writing.
I have just upgraded my Magento installation from 1.4.3 to 1.7.0.1. My previous contact form was a hack job and this time I'm trying to get it working the right way. Reading all around, I tried adding <input type="text" size="15" value="" id="model_ext" name="bike_model_ext" class="required-entry input-text"> to the form.phtml in my template and then in the transaction email template in admin, {{var data.model_ext}}. But that doesn't work. I ensured that the template in the back end is correct by manipulating the text. I also know the form.phtml is correct, as I see elements when they change.
So then I overloaded the controller handling the contact form. I confirmed my controller is handling it (it came with a echo "it works"; die();) And in there, I'm looking for the POST data of the extra form element names, but here, too, I'm having troubles getting access to the data. Looking around the net, I tried this:
$comment = $this->getRequest()->getPost('comment');
$extras=Array( "year","make","model","model_ext" );
foreach($extras as $field)
$comment .= "\n$field:\t".$this->getRequest()->getPost($field);
$this->getRequest()->setParam('comment', $comment);
parent::postAction();
But again, it is like my variables do not exist. Here, again, I know my code is being executed, because when I get anything wrong in there, the contact form crashes to an error message.
I'll be on it again in the morning, but hope that there is something easy I'm missing that someone here with more experience can help me with.
EDIT: ANSWERED I was using the ID to key in for the variables, needs to instead be the name.
An answer for those interested by this fix.
The $_POST and $_GET value generated by a form use name and not id.
In this situation you have to use bike_model_ext instead of model_ext.
Kind Regards,

Resources