Return to homepage



Hi! Does anyone now how the User Model ist connected to the Users table? Looked up in the Laravel Documentation but the suggested answer does not match the project. (video 3) That would be cool. Thanks

  • 0

I'm at Lesson 16 with using laravel 7 and API resource.

return $this->morphToMany(Like::class, 'likeable');

doesnt work (got an error of likeable table not exist) so had to change

return $this->morphOne(Like::class, 'likeable');

instead. Hope this solution is ok

  • 0

You have a slight error in there. It's not 'morphToMany' but instead 'morphMany'. The goal is an one to many relationship. Alex has it correctly.

If it was a many to many relationship, it would indeed require an intermediate table - as the error message was saying.

Hope it helps.

  • 0

For video 19: Apparently Laravel 5.3 has the response() method inside FormRequest class.

For those who are using the latest versions of Laravel should override this method instead:

1 /**
2* Handle a failed validation attempt.
4* @param \Illuminate\Contracts\Validation\Validator $validator
5* @return void
7* @throws \Illuminate\Validation\ValidationException
9protected function failedValidation(Validator $validator) : void
11 if ($this->expectsJson()) {
12 throw new HttpResponseException(response()->json(
13 ['data' => $validator->errors()]
14 , 422));
15 }
17 throw (new ValidationException($validator))
18 ->errorBag($this->errorBag)
19 ->redirectTo($this->getRedirectUrl());

This is working for me and i think is the correct approach.

  • 0

Hi Christos

I'm working my way through this series and am using Laravel 5.8.36. There have been a few hiccoughs but, in general, my experience has been similar to that displayed by Alex in the videos. I came to 19 and also saw that response() isn't in FormRequest.php any longer. I have tried the approach you suggested but it gave an error that HttpResponseException wasn't found. I added it but then another error cropped up. Has anyone else had better luck with this? The error format I have with Laravel 5.8.36 is

2 "message": "The given data was invalid.",
3 "errors": {
4 "body": [
5 "The body field is required."
6 ]
7 }
  • 0

Is it my idea or video 18 at the end is broken?

  • 0

For people watching this course now, you can use the build in API resources (php artisan make:resource UserResource) instead of Fractal.

  • 2

Does Fractal still make sense?

  • 0

How can I get the password grant auth to work with "CreateFreshApiToken" as mentioned here so I don't have to pass in the token with every request making the API vulnerable to attacks?

  • 0

Lesson 18: There's only the first 7:55 :-( I tired in Firefox and Google Chrome.

  • 5

yeah you're right. same

  • 0

This is great! Anyone knows what is the best practice to create an endpoint to return the current user details?

  • 0

Hi, I got stuck in lesson #4. I created a fresh laravel 5.7 project and when I tried to login to the endpoint /oauth/token I am sending the same data as you:

2 "grant_type": "password",
3 "client_id": "2",
4 "client_secret": "BsUKWr9kYFDX1PcbywK3uuCWjbQmnrCjx2uav0aT",
5 "username": "",
6 "password": "ilovecats",
7 "scope": "*"

But for some reason I am not getting the token as you showed

2 "error": "invalid_credentials",
3 "message": "The user credentials were incorrect."

Also, why do you send the email as username? I tried to change username for email as parameter but it seems passport specifically requires a username, and in this case it must be the email, which causes confusion because in the example you are using a username field but with a different purpose.

I hope you can help me with this error.

  • 0

I'm also using laravel 5.7 and work fine.

Did you chang name column as username (users table)? If not it may causing the error...

  • 0

Hi! Anyone can explain me why in this tutorial are we using Laravel Passport rather than JWT tymondesigns?

  • 0

Well, creators are free to decide whether to use JWT or Laravel Passport.

There's another course with JWT Auth and laravel:

Have a nice coding day!

  • 0

Thank you very much for your reply Ache. My questions is more about the benefits or when using one vs other. For instance, in one of the first videos Alex says that Passport is not suitable for SPA.

  • 0

Hi Alex, what is the best way to validate if the post belongs to the last topic in the url?

is it possible to do this using policy?

I tried something like this:

1public function update(UpdatePostRequest $request, Topic $topic, Post $post)
3 if ($topic->id !== $post->topic->id) {
4 throw new \Exception("message", 1);
5 }
7 $this->authorize('update', $post);
9 $post->body = $request->get('body', $post->body);
10 $post->save();
12 return fractal()
13 ->item($post)
14 ->parseIncludes(['user'])
15 ->transformWith(new PostTransformer)
16 ->toArray();

Any suggestion?

  • 0

Hi Alex

how we can get all posts that liked by one user

  • 2