oten

oten

Member Since 2 Years Ago

Experience Points 570
Experience Level 1

4,430 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-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.

10 Nov
9 months ago

oten started a new conversation Best Approach To Handle Third Party API Responses

What would be the method of choice for handling responses coming from a REST API?

For example consider the following response:

[
  "name": "John Doe",
  "username": "john",
  "posts": [
     0: => [
       "title" => "First Post",
       "body" => "This is the first post."
     ]
     1: => [
       "title" => "Second Post",
       "body" => "This is the second post."
     ]
  ]
]

Basically what I'm trying to do is to have a separate object for each post returned by the API. I assume that one way would be to create two classes (not Eloquent models since I don't want the response to be stored in my database) "User" and "Post" and loop through the array to create objects accordingly.

According to this article I could use Laravel Resources to consume the response but that doesn't seem to work in my case.

01 Jul
1 year ago

oten started a new conversation Laravel Collection Values To Vue Array

I'm experimenting with Vue.js and I came across a problem that I can't solve. I have a collection returned from Laravel that I pass as a prop in my Vue Component:

<custom-component :posts="{{ json_encode($posts) "}}></custom-component>

In my CustomComponent.vue I want to populate an array for each record of the collection like so:

var array = [
  {
    'post_name' => this.posts.name,
    'other' => 'random stuff'
  }
]

so in the end the array will be something like:

[
  {
    'post_name' => 'Post 1',
    'other' => 'random stuff'
  },
  {
    'post_name' => 'Post 2',
    'other' => 'random stuff'
  }
  [...]
]

What is the correct way to loop through the "posts" object and populate the array?

19 Dec
1 year ago

oten started a new conversation Guzzle Requests Default Values

Is it possible to include default options in multiple Guzzle requests? Basically what I'm looking for is to inject the following config in every Client instance instead of writing it down for every API call.

$client = new Client([
    'base_uri' => 'https://api.example.com/',
    'query' => [
        'api_key' => 'myApiKey'
    ]
]);
14 Sep
1 year ago

oten left a reply on Integrate Bootstrap Template Assets In Laravel Application

What have I done right now:

  • Copied the whole project to /resources/assets/modular-theme
  • Ran "npm install" & "bower install" inside this directory

The step I'm missing is what to write in the webpack.mix.js file, so the scss and javascript files can be compiled to regular css in the public directory of my application.

oten started a new conversation Integrate Bootstrap Template Assets In Laravel Application

I'm having a hard time integrating the ModularAdmin template (https://github.com/modularcode/modular-admin-html) assets in a Laravel application.

Specifically I can't find the assets I should copy to my Laravel application and also what to write in the webpack.mix.js in order for the template to work properly.

Any ideas?

24 Jul
2 years ago

oten started a new conversation Extend Spatie/laravel-analytics Package

Has anyone experience with extending the spatie/laravel-analytics ? I'm looking to add functionality for real time queries but I can't extend the package properly. This is my first try to extend a vendor package, so every time I try something I end up with errors. Any help would be appreciated!

16 Jul
2 years ago

oten left a reply on Use Two Foreign Keys Pointing To The Same Table And Retrieve With One Relationship

@shez1983 I agree with the naming but I just asked out of curiosity, right now it doesn't need to be implemented in a real project.

Anyway, I'm think that the best approach would be to get the relationships separately and then either combine them in the controller or send them separately in the view.

15 Jul
2 years ago

oten started a new conversation Use Two Foreign Keys Pointing To The Same Table And Retrieve With One Relationship

I have two tables that describe trades between users

User:

  • id
  • name

Trades:

  • id
  • user1_id (foreign key to User.id)
  • user2_id (foreign key to User.id)
  • object

What I'm trying to do is to return all trades for a specific user using one Eloquent Relationship. No matter what I have tried I never managed to do something like this:

$user = User::with('trades')->first();

The best result I could achieve was to define two different relationships, for example:

public function trade1 () {
    return $this->hasMany('App\User', 'user1_id');
}

public function trade2 () {
    return $this->hasMany('App\User', 'user2_id');
}

and then

$user = User::with(['trade1', 'trade2'])->first();

which of course return two relations (trade1, trade2). Is it possible to combine these two relationships into one?

30 Mar
2 years ago

oten started a new conversation Best Approach To Filter A Collection

What's your opinion for the best approach to filter a collection based on speed and efficiency terms. Let's say for example that we have a table that contains books. When the user navigates to /books/{slug} I want to print the corresponding book in a h1 tag and all the other books in h3 tags.

Right now my approach is something like this:

public function index($slug) {
    $books = Book::all();

    list($current, $others) = $books->partition(function ($book) {
        return $book->slug ==  $slug;
    });
}

This works pretty good but I was wondering if there is a more sufficient approach.

Also note that in order to get an attribute you need to first specify the index which is not very handy.

{{ $current[0]->name }}

oten left a reply on Localization Tips For Project With Dynamic Content.

Yes, I'm currenty writing a guide about the setup I made and the methods I used, stay tuned.

08 Feb
2 years ago

oten started a new conversation Localization Tips For Project With Dynamic Content.

I was wondering if anyone has worked with a big Laravel project that required localization. I have some questions as I have never made a project this way.

What's your opinion on the approach method? Is it better to first code the project in the default locale, then make the translation and go back to blade to change the corresponding fields or parallel work will be more suitable?

I came along this plugin (https://github.com/mcamara/laravel-localization) that seems to work perfectly with static translations from a json for example (https://laravel.com/docs/5.4/localization#defining-translation-strings) but what happens with dynamic translations? For example what if I want to display a blog post according to the locale set?

Any piece of advise or other plugins will be extremely useful. Thank you!

09 Dec
2 years ago

oten left a reply on Eloquent Relationships And Substring

@Indemnity83 I managed to get it working thanks to your answer. Seems that beside the methods you have suggested my model needed an $appends variable (https://laravel.com/docs/5.3/eloquent-serialization#appending-values-to-json).

People.php

class People extends Model
{
    public function getCountryAttribute() {
        return Country::where('code', $this->card_code)->first();
    }

    public function getCardCodeAttribute() {
        return substr($this->card, 0, 2);
    }

    protected $appends = ['country'];
}

PeopleController.php

    public function getPeople() {
        $people = People::all();
        return $people;
    }

Thank you all for the answers provided!

08 Dec
2 years ago

oten left a reply on Eloquent Relationships And Substring

@Indemnity83

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'countries.id' in 'where clause' (SQL: select * from `countries` where `code` = 0 and `countries`.`id` in (0))

Seems that this code have a couple of problems. First of all because we don't specify the countries table primary key it's searching for id column.

Second problem is that the card_code doesn't seem to do anything. It returns a value of 0.

oten left a reply on Eloquent Relationships And Substring

@clay As I said @sarathkumar 's solution throws an exception. And also this way requires a relationship.

oten left a reply on Eloquent Relationships And Substring

This code throws an exception

BadMethodCallException in Builder.php line 2448:
Call to undefined method Illuminate\Database\Query\Builder::country()

Even If I try to include the country() function in my model it returns 0 rows. That seems logical because the query is:

select * from `people` where exists (select * from `countries` where `people`.`card` = `countries`.`code` and `code` like DE)

I mean "people.card = countries.code" will always be false. That's the reason we substring at the beginning.

oten started a new conversation Eloquent Relationships And Substring

Hello, I'm facing a problem. Let's say we have two tables with example values.

People:

id: 1
name: John
card: DE123456

Countries:

code: DE
name: Germany

The "card" field of table "People" has a string that contains the country code and random numbers.

PeopleController.php


public function getPeople()
{
    $people = People::with('country')->get();
        return $people;
}

People.php


public function country() {
        return $this->belongsTo('App\Country', 'card', 'code');
}

Of course this returns null because the query search for 'DE123456' instead of just 'DE'. So my question is how to substring before passing the value.

Thank you.