Jawelo

Jawelo

Member Since 1 Year Ago

Béziers

Laravel Developer at my home

Experience Points 4,030
Experience Level 1

970 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 27
Lessons
Completed
Best Reply Awards 2
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

11 Feb
6 months ago

Jawelo left a reply on Multiauth - Login And Reset Password

As I managed to get what I wanted, I still post my answer. It may not be the best thing, but it seems to work well. Hopefully it will help !

I kept Laravel Auth logic (routes and controllers) and added guards :

LoginController.php :

<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;

class LoginController extends Controller
{
    use AuthenticatesUsers, SendsPasswordResetEmails;

    protected $guards = ['user', 'pro'];

    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function redirectTo(){
        foreach($this->guards as $guard) {
            if(Auth::guard($guard)->check()){
                return route($guard . '.dashboard');
            }
        }
    }

    public function login(Request $request)
    {
        $this->validateLogin($request);

        $credentials = $request->only('email', 'password');

        foreach($this->guards as $guard) {
            if (Auth::guard($guard)->attempt($credentials)) {
                return $this->sendLoginResponse($request);
            }
        }
        return $this->sendFailedLoginResponse($request);
    }

    protected function validateLogin(Request $request)
    {
        $request->validate([
            'email' => 'required|string',
            'password' => 'required|string',
        ]);
    }
}

And ResetPasswordController :

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Support\Str;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Auth\ResetsPasswords;
use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Support\Facades\Password;
use Illuminate\Http\Request;

class ResetPasswordController extends Controller
{
    use ResetsPasswords;

    protected $guards = ['user', 'pro'];

    public function __construct()
    {
        $this->middleware('guest')->except('logout');
    }

    public function redirectTo(){
        foreach($this->guards as $guard) {
            if(Auth::guard($guard)->check()){
                return redirect()->route($guard . '.dashboard');
            }
        }
        return redirect()->route('home');
    }

    public function reset(Request $request)
    {
        $request->validate($this->rules(), $this->validationErrorMessages());

        // Here we will attempt to reset the user's password. If it is successful we
        // will update the password on an actual user model and persist it to the
        // database. Otherwise we will parse the error and return the response.
        $response = $this->broker()->reset(
            $this->credentials($request), function ($user, $password) {
                $this->resetPassword($user, $password);
            }
        );

        if($response == Password::PASSWORD_RESET) {
            return $this->redirectTo();
        }

        return $this->sendResetFailedResponse($request, $response);
    }

    protected function resetPassword($user, $password)
    {
        $user->password = $password;
        $user->setRememberToken(Str::random(60));
        $user->save();

        if(get_class($user) == 'App\Models\User') {
            Auth::guard('user')->login($user);
        } elseif(get_class($user) == 'App\Models\Pro') {
            Auth::guard('pro')->login($user);
        }
    }
}

(Of course, the $user->password = $password;uses a setter that Hash the password) It works well but the best is probably to use a package already made for this (for example https://github.com/Hesto/multi-auth).

09 Feb
6 months ago

Jawelo started a new conversation Multiauth - Login And Reset Password

Hi everyone, After a lot of research, I’m still looking for help with multiauth on a Laravel 5.7 project, thank you in advance for your help ! :)

I have two tables users and pros (with emails, password and remember_token fields) where email addresses are unique. I would like to use what is provided by Laravel, but with two different guards: "user" and "pro" on the same Login and Reset Password forms and use the same password_resets table if it’s possible.

For the moment, I can connect as a "pro" or as a "user" thanks to this overload in my Controllers/Auth/LoginController.php (it works, but it’s looks like a bad way…) ` public function login(Request $request) { $this->validateLogin($request);

    if ($this->hasTooManyLoginAttempts($request)) {
        $this->fireLockoutEvent($request);

        return $this->sendLockoutResponse($request);
    }

    $credentials = $request->only('email', 'password');

    // Check Users by default, then Pros
    if ($this->attemptLogin($request)) {
        return $this->sendLoginResponse($request);
    } elseif(Auth::guard('pro')->attempt($credentials)) {
        return $this->sendLoginResponse($request);
    }

    $this->incrementLoginAttempts($request);

    return $this->sendFailedLoginResponse($request);
}

public function redirectTo(){
    if(Auth::guard('user')->check()){
        return route('user.dashboard');
    } elseif(Auth::guard('pro')->check()) {
        return route('pro.dashboard');
    }
}

`

The problem I am having concerns the reset password system. On the same form, I would like to be able to enter my "user" or "pro" email address, receive the email with the token, create my new password and be connected as a "user" or "pro". Does anyone know a way to tell the ResetsPasswords Trait to use two guards (like override the guard() method or something…) ?

(I'm not used to posting, I hope I haven't forgotten anything) Thank you in advance for your time and help !

29 Jan
6 months ago

Jawelo left a reply on Permission Denied When Delete Image From File Path

Hi sanjayacloud,

Have you checked that the rights on the pages folder and on its content were 777 or 755?

Jawelo left a reply on Append Additional Data To Request

Hi matttonks11,

The easiest way I know of for that is to write :

$request->merge(['key' => value]);

I hope it help !

28 Jul
1 year ago

Jawelo left a reply on AJAX Post: MethodNotAllowedHttpException No Message Laravel 5.4

Hi,

I think @Cronix is right to talk about the csrf token. The last time I met this issue, it fixed it. You should add it anyway.

27 Jul
1 year ago

Jawelo left a reply on Call To Undefined Method App\Custom\DataModel::blogData() Yet The Method Exists

Hi,

The structure seems correct... Maybe you need to run composer dump-autoload in order to refresh defined classes ?

Take a look : https://getcomposer.org/doc/03-cli.md#dump-autoload-dumpautoload-

Jawelo left a reply on Carbon- InvalidArgumentException Data Missing

Hi,

This kind of error throws when the format you try to insert in your database is incorrect. You should check if your column "start_date" for example has a "d F Y - H:i" format (it is probably "yyyy-mm-dd" or something like that...)

24 Jul
1 year ago

Jawelo left a reply on Route [cart.index] Not Defined ERROR

He's probably talking about the caps locks key :)

In order for us to help you, you would have to post the entire content of your web.php file framed by three " ` ", and same thing for the output of your php artisan route:list

23 Jul
1 year ago

Jawelo left a reply on Retrieving Category Name Belonging To Post

Hi,

I think you could use something like ->with('category'), so maybe $posts = Post::with('category')->all(); if you have this relation in your Post model, and your object will contains the relation.

Then, in your JS script, you should be able to use something like item.category.name

Jawelo left a reply on How To Add An Anchor Link Leading To Partial In Laravel

Hi,

Why don't simply write href="#anchor" class="btn btn-primary">Subscribe and create your anchor in your partial ?

22 Jul
1 year ago

Jawelo left a reply on Updating Multiple Many To Many Relationships

Hi,

Maybe you're looking for the ->sync() relationships method. Take a look here : https://laravel.com/docs/5.6/eloquent-relationships#updating-many-to-many-relationships

It should do the job, instead of a foreach loop.

Jawelo left a reply on Laravel 5.6 CSRF Token Not Validating / Checked

Hi,

I think you could check if you have the

\App\Http\Middleware\VerifyCsrfToken::class,

line enabled in your App\Http\Kernel.php and if you have this middleware correctly defined.

Jawelo left a reply on Possible To Use An Additional Domain/TLD With Valet?

Hi,

If you're talking about adding subdomains, I think you have nothing more to do than type this kind of url : subdomain.my-domain.dev

I'm not a Valet expert, but I recommand you to take a look at the following link : https://laracasts.com/discuss/channels/general-discussion/valet-sub-domain

Jawelo left a reply on Passing Data Through Return Redirect Back To Update Request

Hi Almost_pitt,

You could try changing

return redirect()->back()->with('message','sign up')->withInput($request->all)->with($leads->email, $request->get('email'));

by

return redirect()->back()->with('message','sign up')->withInput($request->all)->with('email', $request->get('email'));

So, in your view, you can get the session variable

session('email')

And you should not have your error anymore.