Im following the Laravel 4 docs in regards to the password reset functions.
The first bit seems to be working, except for the fact that im not seeing any error or success messages in my view.
I have used the controller that comes with laravel .. This is what i have in the controller.
switch ($response = Password::remind(Input::only('email')))
{
case Password::INVALID_USER:
return Redirect::back()->with('error', Lang::get($response));
case Password::REMINDER_SENT:
return Redirect::back()->with('status', Lang::get($response));
}
and the following is what i have in my view.
#if (Session::has('error'))
{{ trans(Session::get('reason')) }}
#elseif (Session::has('success'))
An email with the password reset has been sent.
#endif
Also, can anyone tell me how to see what validation rules the password reminder has.
change
return Redirect::back()->with('status', Lang::get($response));
to
return Redirect::back()->with('success', Lang::get($response));
and change
{{ trans(Session::get('reason')) }}
to
{{ trans(Session::get('error')) }}
Related
I'm using Gate for permissions and redirect the user to the home if he doesn't have enough permission with an error message
if(Gate::denies('manage-users')){
return redirect(route('home'))->withErrors('You don\'t have enough permissions!');
}
But when the user navigates to another route with correct permission the page displays correctly but with an error handler in the view saying the same message "you don't have enough permissions"
How can I clear errors session once the error get displayed in home to hide it from other views?
Don't know if this is the best solution so please correct me. I Changed the validation to be this
if(Gate::denies('manage-users')){
return redirect(route('home'))->withErrors(['permission_error' => 'You don\'t have enough permissions!']);
}
In the home view
#if(session()->has('permission_error'))
{{session('errors')->get('permission_error')}}
#php session()->forget('permission_error') #endphp
#elseif( !session()->has('permission_error') && $errors->any())
<div class="alert alert-danger">
{{ $errors->first() }}
</div>
#endif
How can i redirect with success or error message without using sessions in laravel
Currently I am using the following code for redirect :
return redirect('dashboard')->with('status', 'Profile updated!');
But this code Need session to display the success message.
You can set another variable status type along with the status like below,
return redirect('dashboard')->with(['status'=>'Profile updated!','status_type'=>'success']);
And in your dashboard blade file use
#if(isset($status))
<p class="alert alert-{{ $status_type }}" >{{ $status }}</p>
#endif
In blade, If we want to check that the current route matches with a route or not, we can simply use:
#if(Route::currentRouteName() == 'parameter')
{{ 'yes' }}
#else
{{ 'no' }}
#endif
But what if we want to match it with a wildcard like:
#if(Route::currentRouteName() == 'parameter.*')
{{ 'yes' }}
#else
{{ 'no' }}
#endif
Is there any solution for that?
I have tried "*" and ":any", but it didn't work.
Note: I want to check route, not URL.
Any help would be appreciated.
Thanks,
Parth Vora
Use Laravel's string helper function
str_is('parameter*', Route::currentRouteName())
It'll return true for any string that starts with parameter
I had the same problem. I wanted to toggle an active class based on a URI.
In blade (Laravel 6x), I did:
(request()->is('projects/*')) ? 'active' : ''
You can also make use of Blades Custom If Statements and write something like this in your AppServiceProvider.php:
public function boot()
{
Blade::if('route', function ($route) {
return Str::is($route, Route::currentRouteName());
});
}
then you can use it in a blade view like this:
<li #route('admin.users*') class="active" #endroute>
Users
</li>
Everything is fine, Login, Validation, and Username/Password combination mismatch, except for the mismatch, it does not send back the data that I'm sending.
This is my code, and I've tried different login techniques, and same issue.
This is my blade page errors section:
<div id="formErrorDiv">
#if ($errors->has())
<h2>* Please check your errors.</h2>
#endif
#if (isset($mismatch))
<h2>* {{ $mismatch }}</h2>
#endif
</div>
while the $errors-has() for the fields' validation works perfectly, the $mismatch variable always turns out empty.
This is my controller login section:
if($auth){
return Redirect::intended('/');
} else {
//dd('auth else');
$mismatch = 'Login Credentials Error.';
return Redirect::route('account-sign-in')
->with('mismatch', $mismatch);
}
although when I use the dd('auth else') it does work, and so it enters the else section but always sends nothing with the redirection.
You need to use Session::get() to retrieve the value you pass with with():
#if(Session::has('mismatch'))
<h2>* {{ Session::get('mismatch') }}</h2>
#endif
errors is the exception here. Because it's very common to pass that to the next view, Laravel built it in so the errors variable from the session is automatically available in your views...
i have the following route:
Route::get('notes/main', function(){
$destinations = Destination::where('show', '=','1')->get();
$notes = Destination::find($destination->id)->notes()->get();
return View::make('notes.main')
->with('destinations', $destinations);
});
//the relationship models:
<?php
class Destination extends Eloquent {
public function notes()
{
return $this->has_many('Note');
}
}
<?php
class Note extends Eloquent
{
public function destination()
{
return $this->belongs_to('Destination');
}
}
//View:
#foreach( $destinations as $destination)
{{ $destination->name}}<br>
{ $notes->destination->text }} // this isn't echoed
#endforeach
what's the correct way to filter this and define $destination->id
thanks
How would i Filter the notes in an if statement inside the loop ?
#if (isset($note->title) != 'shorttext')
#else
<p> {{ $note->text }} </p>
#endif
#endforeach
You use $destination->id in your Route but it seems to be not defined yet. The question is, what do you want to achieve with your code?
With:
$destinations = Destination::where('show', '=','1')->get();
$notes = Destination::find($destination->id)->notes()->get();
you are getting only the Notes of one specific destination (so far, $destination is not defined. You could use Destination::all()->first() to get the first, or Destination::find(id), with ID being replaced with the primary key value of the destination you need).
But I guess you don't want it that way. From your Output it seems like you want to have an output with each destination and below each destination the corresponding Notes.
Controller:
//gets all the destinations
$destinations = Destination::where('show', '=','1')->get();
return View::make('notes.main')
->with('destinations', $destinations);
View:
#foreach( $destinations as $destination)
{{ $destination->name}}<br>
#foreach($destination->notes as $note)
{{ $note->text }} <br>
#endforeach
<hr>
#endforeach
Didn't test this, but this way your View would show you all your Destinations and for each Destination all the Notes.
In your route, your not sending $notes variable to the view.
How I would do it:
$destinations = Destination::where('show', '=','1')->get();
$destinations->notes = Destination::find($destination->id)->notes()->get();
Then in view:
#foreach( $destinations as $destination)
{{ $destination->name}}<br>
{{ $destination->notes->text }}
#endforeach
So first you asked a question, I gave you a correct answer.
You marked my answer as accepted, but later on you edit your initial question to add another question (for which you should create a new thread instead).
Then you create your own answer which is only answering part of your initial question and mark that as the good solution?
I could tell you why your isset and empty did not work, but why should I if you don't value my help at all?
OK
for the last part this worked out at the end
function isset and empty didn't work , strange:
#if ($note->title == 'shorttext')