Laravel change status on Date after 90 days - php

I am making a blood donation system where user donates blood on a date, The specific date is saved in the DB now after 90 days I want to enable his status so that user can donate blood again, How can I compare the saved date compare it with today so that exactly user can donate blood again.
I already tried
#if ($donationDate == \Carbon\Carbon::now()->subMonths(3))
<div class="alert alert-success" role="alert">
<strong>Donate Now</strong>
</div>
#else
<div class="alert alert-danger" role="alert">
<strong>Sorry you cannot donate blood</strong>
</div>
#endif
and also
#if ($donationDate >= \Carbon\Carbon::now()->subMonths(3))
<div class="alert alert-success" role="alert">
<strong>Donate Now</strong>
</div>
#else
<div class="alert alert-danger" role="alert">
<strong>Sorry you cannot donate blood</strong>
</div>
#endif
and other $donationDate->greaterThanEqual(\Carbon\Carbon::now())
nothing is working

You can do it like this.
#if ($donationDate >= date('Y-m-d', strtotime('-90 days')))
<div class="alert alert-success" role="alert">
<strong>Donate Now</strong>
</div>
#else
<div class="alert alert-danger" role="alert">
<strong>Sorry you cannot donate blood</strong>
</div>
#endif

Don't know but this is working for Now! 😅
#if(\Carbon\Carbon::today()->subDays(90) >= $donationDate)
<div class="alert alert-success" role="alert">
<strong>Donate Now</strong>
</div>
#else
<div class="alert alert-danger" role="alert">
<strong>Sorry you cannot donate blood</strong>
</div>
#endif

Related

How to show messages on Laravel 9?

Application doesn't show messages as it should.
I tried returning back with message in RoleController. Redirecting works fine, but I can't see any messages. There is multiple functions like this, none of them show messages.
public function store(Request $request)
{
$validated = $request->validate(['name' => ['required', 'min:3']]);
Role::create($validated);
return back()->with('message', 'Role created successfully.');
}
And this code below is in admin.layout blade.
#if (Session::has('message'))
<div class="alert alert-warning alert-dismissible fade show" role="alert">
{{ Session::get('message') }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
#endif
I googled this many many times but can't find a solution. This worked fine month ago, but when I continued with this yesterday, it suddenly stopped working. Php version hasn't changed, it's 8.0.2. I also tried flash-messages with no help.
Sorry, not a native english speaker.
edit / I have also cleared cache with php artisan.
try this
In Controller
return redirect()->route('admin.listing')->with('message', 'Role created successfully.');
In Blade file
#if (Session::has('message'))
<div class="alert alert-warning alert-dismissible fade show" role="alert">
{{ Session::get('message') }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
#endif
I think you can try this...
#if ($message = Session::get('message'))
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
<strong>{{ $message }}</strong>
</div>
#endif
Please try one time with this one
return redirect()->back()->with('message', 'Role created successfully.');
Now it's working. I needed to modify Kernel.php and remove \Illuminate\Session\Middleware\StartSession::class, under the protected $middlewareGroups.

the success green box did not appear in Laravel 8

Hye everyone! I want to make success message, the message appear but the green box did not appear as shown below.
blade.php:-
#if(Session::has('success'))
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert">
<i class="fa fa-times"></i>
</button>
<strong>Success!</strong> {{ session('success') }}
</div>
#endif
<br>

Laravel 8 Redirect back with message not working in blade template

I am using Laravel v8.16.1 and PHP v7.3.1 when I am trying to get a message in the blade template.
#if(session('error'))
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h5><i class="icon fas fa-ban"></i> Success!</h5>
{{ session('success') }}
</div>
#endif
Using the below code, it's working for me.
$req->session()->flash('error', 'Invalid Username or Password');
return view('admin.views.login');
However, it's not the right way, and when I am trying to redirect back using the below code, then it's not working
return redirect()->back()->with('error', 'Invalid Username or Password');
Please help what is missing or what is wrong?
You can use to show errors
#if(count($errors) > 0 )
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<ul class="p-0 m-0" style="list-style: none;">
#foreach($errors->all() as $error)
<li>{{$error}}</li>
#endforeach
</ul>
</div>
#endif
And the redirect code would be
return redirect()->back()->withErrors(['errors' => 'There is some error in the details.']);

Block registration if email already exists in mysqli database

Users can use the same email address for different registration.
Tried using different solutions from developers on Stack Overflow who have experienced the same problems that I have, including making the emailUsers column a UNIQUE KEY in the database table, and implementing some sort of jQuery, but not successful. Think the problem is I am missing an 'else if' block for duplicate email, but all the various ways I tried to implement this, it does not do anything.
<div id="signup">
<div class="container">
<div class="row">
<div class="col-sm-6 offset-sm-1">
<div class="signup-left position-fixed text-center">
<img src="img/200.png">
<br><br><br>
<?php
if(isset($_GET['error']))
{
if($_GET['error'] == 'emptyfields')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Fill In All The Fields
</div>';
}
else if ($_GET['error'] == 'invalidmailuid')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Please enter a valid email and user name
</div>';
}
else if ($_GET['error'] == 'invalidmail')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Please enter a valid email
</div>';
}
else if ($_GET['error'] == 'invaliduid')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Please enter a valid user name
</div>';
}
else if ($_GET['error'] == 'passwordcheck')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Passwords donot match
</div>';
}
else if ($_GET['error'] == 'usertaken')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> This User name is already taken
</div>';
}
else if ($_GET['error'] == 'invalidimagetype')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Invalid image type
</div>';
}
else if ($_GET['error'] == 'imguploaderror')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Image upload error, please try again
</div>';
}
else if ($_GET['error'] == 'imgsizeexceeded')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Error: </strong> Image too large
</div>';
}
else if ($_GET['error'] == 'sqlerror')
{
echo '<div class="alert alert-danger" role="alert">
<strong>Website Error: </strong> Contact admin to have the issue fixed
</div>';
}
}
else if (isset($_GET['signup']) == 'success')
{
echo '<div class="alert alert-success" role="alert">
<strong>Signup Successful</strong> Please Login from the login menu
</div>';
}
?>
<form id="signup-form" action="includes/signup.inc.php" method='post' enctype="multipart/form-data">
<input type="submit" class="btn btn-light btn-lg" name="signup-submit" value="Signup">
<br><br>
<a href="login.php">
<i class="fa fa-sign-in fa-2x social-icon" aria-hidden="true"></i>
</a>
<a href="contact.php">
<i class="fa fa-envelope fa-2x social-icon" aria-hidden="true"></i>
</a>
</div>
</div>
I want to be able to block a user from registering with the same email, and to generate an error message when the user tries to do this.
EXTRA INFO: Can post further, detailed methods of me trying to make the emailUsers column a UNIQUE KEY, but when I do this, new users can no longer register, even if they use a different email.

Redirect with flash data in laravel 5 does not work

When I submit a form I want to redirect back to the current view/blade with some data:
here is my redirect:
return redirect('configbeacon')->with('requirement', 'req');
here is my blade where I check if 'requirement' is set:
#if(Session::has('requirement'))
<div class="alert alert-success" role="alert">
<span class="sr-only">Error:</span>
Dit tilbud blev gemt
<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
</div>
#endif
But it does not show the elements inside the if loop... Thank you.

Categories