larel_b

Experience

380

0 Best Reply Awards

  • Member Since 8 Months Ago
  • 0 Lessons Completed
  • 0 Favorites

9th February, 2018

larel_b left a reply on How Do You Send A First Time User A Password Reset Link? ( • 3 months ago

@Snapey My UserRegisteredNotification is called as a class like this:

$user->notify(new UserRegisteredNotification($user, $this->reset_token));

Notice that the reference to the user is inside the calling class and if you don't pass it in, then you have to get the reference some other way. This appears to be how it's done in the Laravel docs too. In my notification class, I'm actually using the user object to print details in the e-mail. I just didn't post the code because it wasn't relevant to the problem.

Thanks again for the help.

larel_b left a reply on How Do You Send A First Time User A Password Reset Link? ( • 3 months ago

@Snapey Thanks I voted your answer as the correct one. I did it like this before, but I wasn't hashing the token correctly.

I used this in the RegisterController:

public $reset_token;

    $this->reset_token = hash_hmac('sha256', Str::random(40), $key);
    DB::table('password_resets')->insert([
       'email' => $request->email,
        'token' => Hash::make($this->reset_token),
        'created_at' => Carbon::now(),
    ]);

Then I passed the token to my notification class like so:

protected function registered(Request $request, $user) { $user->notify(new UserRegisteredNotification($user, $this->reset_token)); }

In the Notification class:

public $token;

public function __construct($user, $reset_token) {
    $this->user = $user;
    $this->token = $reset_token;
}

From there, I send the e-mail to the user with a link to

url(config('app.url').route('password.reset', $this->token, false))

It all works now!

8th February, 2018

larel_b left a reply on How Do You Send A First Time User A Password Reset Link? ( • 3 months ago

@BezhanSalleh Initially, I was going to do it that way, but I didn't want to send a plain text password through email. Do you think you can help me accomplish this in the way I intend?

larel_b left a reply on How Do You Send A First Time User A Password Reset Link? ( • 3 months ago

@Snapey There is only 1 admin - the site owner - this person can create accounts without passwords - the new user will get an email link to set/reset the password.

larel_b left a reply on Use Same Views For Multiple Controllers • 3 months ago

Agreed. What happens when there are 100 languages?

larel_b left a reply on How Do You Send A First Time User A Password Reset Link? ( • 3 months ago

Thanks for that! What is the context of this in $this->app?

larel_b left a reply on How Do You Send A First Time User A Password Reset Link? ( • 3 months ago

I'm really sorry that happend to you.

larel_b left a reply on Use Same Views For Multiple Controllers • 3 months ago

In the controller:

return view('langs.index')->with('words', $spanish_words)->with('language', 'spanish');

{!! Form::open(['route' => $language.'store']) !!}

larel_b left a reply on How Do You Send A First Time User A Password Reset Link? ( • 3 months ago

Yeah, I traced it back to the PasswordBrokerManager in vendor/laravel/framework/src/Illuminate/Auth/Passwords.

Look in the createTokenRepository method.

larel_b left a reply on Use Same Views For Multiple Controllers • 3 months ago

The data array is different every time you send it to the view. I think your logic is not correct for what you want to do. You only need to send what you need. If you are sending words for just a single language using the same view, the view at that time only needs the words for that language. I wouldn't send it as an array with everything in it. Send it as I wrote above.

For example:

In the controller:

$spanish_words = Spanish::query()->get();

return view('langs.index')->with('words', $spanish_words);

In the view (It knows what controller called it, so the $words collection will have the right words in it):

@foreach($words as $word) {{ $word->name }} @endforeach

larel_b left a reply on Use Same Views For Multiple Controllers • 3 months ago

@dsml You could just specify only the languages you need to pass to the view when you display it. For example if you are the Spanish controller and you only need spanish words, just only include:

$data = [
    'spanish' => Spanish::query()->get()
];
return view('langs.index')->with($data);

You don't have to pass it all to the view at once, only what you need at that point in the controller.

Glad to see that it's working bud!

larel_b left a reply on How Do You Send A First Time User A Password Reset Link? ( • 3 months ago

@Snapey The select query works just fine and it finds the entry used in the link.

larel_b left a reply on Use Same Views For Multiple Controllers • 3 months ago

@dsmI I think either you are overcomplicating this or maybe I just don't understand. You can use the exact same view for multiple controllers. Just return the same view for different controllers as a response. In the view, use the same variable name such as $words and/or $translated_words. Just specify the the from and to:

Look at this:

In the controller:

return view('same.view')->with('$words, $whatever_language_you_want)->with($translated_words, $whatever_language_yo_want);

In the view:

@foreach($words as $word)
    {{ $word->name }}
@endforeach

@foreach($translatedWords as $tWord)
        {{ $tWord->name }}
@endforeach

larel_b left a reply on How Do You Send A First Time User A Password Reset Link? ( • 3 months ago

@Snapey Yep, it is exactly the same and the same in the hidden input field of the view.

larel_b left a reply on Use Same Views For Multiple Controllers • 3 months ago

@dsml Just pass in the correct words from the controller and the view will display them. Make sure you use the same variable name when passed to the view as I wrote above.

larel_b left a reply on Use Same Views For Multiple Controllers • 3 months ago

Why not just call them $words (since they're all words) and pass them to the view?

larel_b left a reply on How Do You Send A First Time User A Password Reset Link? ( • 3 months ago

@Snapey Thanks for the fast reply. I tried that as I mentioned at the bottom of the post.

larel_b left a reply on Use Same Views For Multiple Controllers • 3 months ago

Hmm, this is hard to follow. Are you saying that you need to create links in the view with different locations based on the language?

larel_b started a new conversation How Do You Send A First Time User A Password Reset Link? ( • 3 months ago

I followed @bashy on this post: https://laracasts.com/discuss/channels/laravel/reset-password-manually-without-email

I am generating a token like this:

$reset_token = hash_hmac('sha256', Str::random(40), $user);

I am inserting a record in the password_resets table like this:

    DB::table('password_resets')->insert([
       'email' => $request->email,
        'token' => $reset_token,
        'created_at' => Carbon::now(),
    ]);

The user gets an e-mail sent through a custom notification with the correct token (it matches on the link and in the hidden input field on the view).

I keep getting this after following the link, filling in the form, and clicking on reset password:

This password reset token is invalid.

I have also tried this to generate the token (same error):

$reset_token = strtolower(str_random(64));

larel_b left a reply on Reset Password Manually Without Email • 3 months ago

@bashy I know this is an old post, but I used your code for sending the password reset link and I get that "This password reset token is invalid" when attempting to reset the password. It works when generated by the framework.

29th August, 2017

larel_b left a reply on InvalidArgumentException: Driver [file] Is Not Supported • 8 months ago

I do use Git, but this was before an initial commit.

larel_b left a reply on Controller Functions • 8 months ago

You could also use 1 controller and create 2 actions/functions

For example:

Suppose both uses have a home page for a dashboard, so you create a HomeController

Then, in the HomeController, you have an userIndex action and an adminIndex action.

If the views are identical except for the content and it makes logical sense to, you could just create partials and conditionally show one based on what type of account is signed in.

larel_b left a reply on ErrorException-Trying To Get Property Of Non-object • 8 months ago

@Imamul.Hossain

This is a suggestion and something that helps me when attempting to print a string in blade. If you have an object with many levels of nesting, start by getting the object in the controller and sending the exact string you are looking for to the view.

For example: $product = new Product($name,$image,$price,$location); $products = [$product];

So instead of sending $products to your view, send $products[0]->name to your view. This will help you figure out whether or not there is an issue with the data or the way you are attempting to access the data.

If there is no issue with the way you are accessing the data, then see if the data actually exists for each item. You can try putting all of the last images in an array using a foreach or for loop such as:

$images = []; foreach($products as $product) { array_push($images, $product->image); }

return view('myView')->with('images',$images);

Then, print the images in the view. See if any data is null or throwing something off.

larel_b started a new conversation InvalidArgumentException: Driver [file] Is Not Supported • 8 months ago

My system: Windows 10, PHPStorm, Laravel 5.4

For some reason after changing the name of a sub-folder in the view (not the view folder itself) and refactoring my code, I am getting a weird caching error:

InvalidArgumentException: Driver [file] is not supported

NO ARTISAN commands will work. If I attempt to run any artisan command, I get the same error. It appears that the code is being parsed before artisan will execute a command. If I run php -v, it works. If I run artisan in any other Laravel project, it works; therefore, it's not a system issue.

Here is what I have tried:

  • Manually deleted the cache files in storage/framework (cache, sessions, views)
  • Changing the cache driver to one of the other options such as array, database, etc.
    • This changes the error to replace [file] with whatever I can it to
  • Ran composer dump-autoload followed by composer update, same error
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.