the success green box did not appear in Laravel 8 - php

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>

Related

Laravel change status on Date after 90 days

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

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.']);

Session Modal doesn't appear Laravel 5.2

Hi everyone! I am using Laravel 5.2 for a web application. Within this app, the user can upload files. When the user wants to upload a file, but hasn't selected one they are Redirect::to the upload page with the message status saying something about choosing a file to upload. The web page used to have this code to show the message:
#if (session('status'))
<div class="alert alert-warning">
×
{{ session('status') }}
</div>
#endif
Which works great! But due to CSS and JQuery mocking, I would like to have a pop up window with the message. I went to search a few things and I found that a Bootstrap Modal would be the best. I adjusted my code to:
#if (session('status'))
<div class="modal fade">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>{{ session('status') }}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
#endif
But now, nothing is shown! Could someone help explain to me why the modal isn't visualized?
So I have tried Mayank Pandeyz answer. And then inspected the browser. Which does show that the Modal is called with the right status message!
Consule error is: Uncaught ReferenceError: $ is not defined
try this:
#if (session('status'))
<div class="modal fade" id="myModal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
<p>{{ session('status') }}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$('#myModal').modal('show'); // You have to initialize it as a modal
</script>
#endif

Get the key of a flash message

I am working with Laravel and I am new. I jsut set a flash message by using this line of code: session()->flash('status', 'This is my flash message to display');
To retrieve the message I use session('status').
Now my question is, is there any possibility to get the key of the flash message? In my example, the key of the flash message is status
Set an array of data in session with type and message.
session()->flash('message', [
'type' => 'success',
'body' => 'This is my flash message to display'
]);
Then you can access the message type like
session('message.type')
In your blade view you can do this to have a dynamic alert message
#if (session()->has('message'))
<div class="alert alert-{{ session('message.type') }}">
{{ session('message.body') }}
</div>
#endif
You can get an array of all keys of newly flashed values using:
session('_flash.new');
Pass message like this
return redirect()->back()->with('success', 'Destination deleted successfully');
Use like this
#if(Session::has('success'))
<div class="alert alert-success alert-dismissable alert-box">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
{{ Session::get('success') }}
</div>
#endif
#if(Session::has('error'))
<div class="alert alert-danger alert-dismissable alert-box">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
{{ Session::get('error') }}
</div>
#endif

Using Language Class in Controller (CodeIgniter)

First of all, I made research but couldn't find anything about it.
I'm sending flash data to users when they update or add something. My controller file's related part is like this;
function hizmet_ekle()
{
if($this->mhizmetler->hizmet_ekle())
{
$this->session->set_flashdata('ok', 'hizmet sisteme eklendi!');
redirect('panel/hizmetler');
}
else
{
$this->session->set_flashdata('hata', 'Bir hata oluştu. Lütfen tekrar deneyin!');
redirect('panel/hizmetler');
}
}
And my view's related parts are like this;
<?php if($this->session->flashdata('ok')): ?>
<div class="alert alert-success fade in widget-inner">
<button type="button" class="close" data-dismiss="alert">×</button>
<i class="fa fa-check"></i> <?php echo $this->session->flashdata('ok');?>
</div>
<?php endif; if($this->session->flashdata('hata')): ?>
<div class="alert alert-danger fade in widget-inner">
<button type="button" class="close" data-dismiss="alert">×</button>
<i class="fa fa-times"></i> <?php echo $this->session->flashdata('hata');?>
</div>
<?php endif; echo validation_errors('
<div class="alert alert-danger fade in widget-inner">
<button type="button" class="close" data-dismiss="alert">×</button>
<i class="fa fa-times"></i> ', '
</div>'); ?>
My system has a few different languages, it means I have to send different notification messages(session flashdata's) for each language but I can't use lang key in my controller file. How can I handle it?
Thanks in advance.
I found it!
I have to use it like this;
$this->session->set_flashdata('ok', $this->lang->line("greek"));

Categories