brunitosessa

brunitosessa

Member Since 3 Months Ago

Experience Points
300
Total
Experience

4,700 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
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

Level 1
300 XP
Apr
07
1 month ago
Activity icon

Replied to Resource API Data

Hi @a4ashraf . Thanks again for your help. I understand perfectly what you are saying, but I need to return that "distance" in BarResource to Ionic App. That's the part that I don't know how to join.

Thanks a lot!

Activity icon

Replied to Resource API Data

Hi @a4ashraf ! Thanks for your help.

This is my User Controller:

class UserController extends Controller
{
    public function show($user_id)
    {
        return new UserResource(User::find($user_id));
    }
........

And this is my Bar Controller, where the Ionic App send the request with "lat" and "lng"

class BarController extends Controller
{
    public function index(Request $request) {
        $lat = $request->input('lat',0);
        $lng = $request->input('lng',0);

        return [
        	'estado' => 1,
        	'bares' => BarResource::collection(Bar::All()),
        ];   
    }

So, my Ionic App is sending to my laravel backend "lat" and "lng" and I should return with a Bar Resource like this:

class BarResource extends JsonResource
{
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'city' => $this->city->id,
            'address' => $this->address,
            'distance' => *?????????????????*,
        ];
    }
......

So I really don't know where to put the method to calculate distance between user (Ionic App) and the bar. Should I put it into User's Model? Should I put it into Bar's Model? Should I put it into User Controller? Should I put it into Bar Resource calling an Action?

Apr
04
1 month ago
Activity icon

Replied to Resource API Data

Thanks for your answer @a4ashraf . I already have the code to calculate the distance. I just don't know where to put it to user it (according best practices of laravel). I need to send that information to an app (json) using an API resource.

Thanks a lot.

Activity icon

Started a new Conversation Resource API Data

Hi, I'm trying to send data to an App using Api resources. I have "Bar resource", that has to include the distance (using latitude and longitude) from an User to that Bar. I really don't know how to (or where to) send that latitude and longitude to calculate that distance.

Could someone help me?

Thanks a lot

Mar
05
2 months ago
Activity icon

Replied to Api Resources

Thanks for the replay @sti3bas. I need to return data about two diferents models. For example, I need to send information about a Bar (Bar model) and also, in the same response, data about if the logged user can or can't use bar's promotions.

Activity icon

Started a new Conversation Api Resources

Hi, I'm trying to create an api resource to return data to an ionic project. I need to include in one response information about two models. Following best practices, which would be the best approach to do this?

Mar
03
2 months ago
Activity icon

Started a new Conversation Socialite Facebook Login

Hi everyone. I'm working on a backend for an Ionic APP. I need that all request made to that backend become from a logged in facebook user (Using Socialite). Has anyone some experience with this?

Mar
02
2 months ago
Activity icon

Started a new Conversation Defining Models

Hello. I'm trying to understand how to exactly use models in Laravel, following the best practices. I have this example: Model Bar, Model Promotion and Model User.

A Bar can have a lot of Promotions.
A Promotion can only be in one Bar.
A user can use a promotion only one per day.

From my User Model, I have to check if this user has already used a promotion (Using relation between them). But before that I need to check if that Bar Has any promotion. Should I call the Bar Model inside my User Model to check that?

Thanks a lot.

Feb
28
3 months ago
Activity icon

Replied to Laravel Api Resources

@sti3bas Thanks a lot! That worked very good.

Activity icon

Started a new Conversation Laravel Api Resources

I'm having problems understanding API resources in laravel 5.8. Supose I have a model called "Bars", and an API resource called BarResource:

class BarResource extends JsonResource
{
    public function toArray($request)
        return [
            'id' => $this->id,
            'name' => $this->name, 
        ]
    }
}

Ok. That works fine. Now I need to pass to every call, if the bar is opened or not (I can easeily calculate that). Where should I put the function that check if the bar is opened or closed?

class BarResource extends JsonResource
{
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name, 
            'is_opened' => ??????
        ]
    }
}

Thanks a lot!