danielcoker

danielcoker

Member Since 1 Year Ago

Experience Points 500
Experience Level 1

4,500 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 1
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

14 Mar
1 month ago

danielcoker started a new conversation Modify Headers Before Authentication

I want to modify the header of an incoming request to add the authorization header. I've created a middleware already, but it's not working. Here's my code.

public function handle($request, Closure $next)
    {
        $response = $next($request);

        $response->header('Authorization', 'Bearer ' . $request->cookie('token'));

        return $response;
    }

I've also tried this, I still get the same result

public function handle($request, Closure $next)
    {
        $response = $next($request);

        $response->headers->set('Authorization', 'Bearer ' . $request->cookie('token'));

        return $response;
    }

I've also added the middleware in the kernel.

After all this, it's not still authenticating the user. Is there a way to change the headers before the user gets authenticated.

12 Mar
1 month ago

danielcoker started a new conversation Send Access Token On Every Request

I'm using the token based authentication for authenticating users using React and Laravel Passport.

So, I'm saving the access token in an httpOnly cookie, but I don't know how to send this token already stored in the cookie in the authorization header.

Since the httpOnly cookie sends the token on every request, does it mean there's no point in setting the Authorization: Bearer {Token} in the request header?

08 Mar
1 month ago

danielcoker left a reply on How Secure Is Laravel Passport

Okay. @ejdelmonico If I understand, for more security; I'll need to encrypt the tokens before saving them in a cookie?

danielcoker started a new conversation How Secure Is Laravel Passport

I'm new to Laravel Passport.

I want to use. Laravel Passport for my API and user authentication, but I want to know how secure it is.

After returning the User access token from the login method that can be stored in a cookie or local storage, can this token be used by any other application to access a user account - because I learnt this token is like the password in plain text.

What I mean is: can the security of a user account be compromised if the access token is gotten.

29 Jan
2 months ago

danielcoker left a reply on Disable Exception Handling In Laravel Tests

@XTREMER360 - Tried this just now, still the same generic error I'm getting.

danielcoker started a new conversation Disable Exception Handling In Laravel Tests

I've been trying to disable exception handling in my test so I can see the errors, but it's not working even if I intentionally break the code.

I'm just getting this generic response and it's not helping much.

Invalid JSON was returned from the route.

I've tried all solutions I can find online, but none of them is working.

I tried $this->disableExceptionHandling(), it didn't work. I also tried the tutorial from Adam Wathan, [https://gist.github.com/adamwathan/125847c7e3f16b88fa33a9f8b42333da] that didn't work also.

Please I need a way out.

Any help would be appreciated.

Thanks.

16 Jul
9 months ago

danielcoker started a new conversation Redirect To Different Views Based On User Roles

I have four user roles in my application and each of them have different views. I want after registration or login, each different user should be redirected to their own view. If a user access a view that isn't for them, they should be redirected to their default page.

I have tried creating a middleware to check for user roles and redirect appropriately but it's always returning the error: too many page redirects.

Here's my code:

       public function handle($request, Closure $next)
    {
        $user_role = $request->user()->role();

        switch ($user_role) {
            case 'admin':
                return redirect()->route('admin/home');
                break;

            case 'regular':
                return redirect()->route('account/home');
                break;

            case 'resturant':
                return redirect('restaurant/home');
                break;

            case 'delivery':
                return redirect('delivery/home');
                break;

            default:
                return redirect('account/home');
                break;
        }
        return $next($request);
    }
}

Thanks in anticipation!

05 Jun
10 months ago

danielcoker left a reply on Laravel Relationship Between Three Tables

Thanks for the replies..

I was able to get the data successfully with this code. Only had to change the all() method to get() before it worked.

Thanks for your help.

04 Jun
10 months ago

danielcoker left a reply on Laravel Relationship Between Three Tables

I've just tried this your solution.

I have problem retrieving the data from the tables. I get this error: "Method Illuminate\Database\Eloquent\Collection::event does not exist."

Here's the code I'm using to the get the data:

$registration = Registration::all()->event()

danielcoker started a new conversation Laravel Relationship Between Three Tables

I'm creating an event registration site, so I have three tables. Events Table, Users Table, Registrations Table. I want to create a relationship between these tables.

Events Table (id, name, date, venue) Users Table (id, firstname, lastname, email, gender) Registrations Table (id, location, duration, accommodation)

I've tried creating a pivot table that would have (event_id, user_id, registration_id). But I don't know how to link them using eloquent.

Any help would be appreciated, thanks.

27 Apr
11 months ago

danielcoker left a reply on Send Laravel Validation Errors As JSON To Ajax Post Response

@cronix Thanks for the reply. It really worked!

danielcoker started a new conversation Send Laravel Validation Errors As JSON To Ajax Post Response

I'm trying to implement logging in with ajax. It's working fine without ajax, but now I'm using ajax it's returning a 422 error in the console. I tried checking the response in the error via y browser and I'm seeing the validation errors. My problem now is how to send the error to the AJAX response.

Here's my code

protected function sendFailedLoginResponse(Request $request)
    {
        if ($request->ajax() || $request->wantsJson()) {
            return response()->json([
                $this->username() => Lang::get('auth.failed'),
            ], 422);
        }

        return redirect()->back()
            ->withInput($request->only($this->username(), 'remember'))
            ->withErrors([
                $this->username() => Lang::get('auth.failed'),
            ]);
    }

JS Code

$.post('login', $(this).serialize(), function(data) {
        console.log(data.errors);
    });