nenads

nenads

Member Since 1 Year Ago

Experience Points 27,950
Experience Level 6

2,050 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 277
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.

28 Feb
1 year ago

nenads started a new conversation Inconsistent Laravel Documentation

I've found that Laravel Documentation is not consistent. For example, if you go to https://laravel.com/docs/5.2/authorization you can read about "Automatically Determining Policy Methods" but in version 5.3 (https://laravel.com/docs/5.3/authorization) and newer there is nothing about it, but it still works.

There are a lot of similar cases.

Why is that happening?

20 Feb
1 year ago

nenads left a reply on What Do You Think About Apiato?

Thank you for reply!

Yep, Apiato looks like a giant in compare to dingo. As I already said, it's more like Full-Stack API framework with everything you need to create functional API.

I'll go through Apiato documentation and see I and can switch to Porto SAP.

If someone else has experience with Apiato, I'd like to hear it as well.

nenads started a new conversation What Do You Think About Apiato?

Hello all,

I have a task to create API with Laravel. After some search I've found dingo/api and Apiato.

I'd like to hear your opinion about those two packages. Apiato is not just a Laravel package, it's more like framework for itself.

What are you using for creating API with Token based auth etc?

Thanks!

06 Nov
1 year ago

nenads left a reply on Find Results For Specified User If They Exists

I've created hasMany relationship between tests and test_user and not I can do something like this:

$tests = Test::with(['tests' => function($query) use ($user) {
  $query->with('user_id', $user->id);
}])-get();

With this relation I don't have to check ids on inner loop, I can simply iterate over both loops and just display results.

Thanks!

nenads left a reply on Find Results For Specified User If They Exists

@shez1983 That's exactly what I'm using right now but it requires two nested foreach loop, outer for the tests and inner for user's test results.

I think I'll leave it as is for now until I find some better solution.

Thanks to all!

04 Nov
1 year ago

nenads left a reply on Find Results For Specified User If They Exists

@andonovn If user didn't do some test I won't get get that test name. One user can do one test zero or many times.

For example:

User: John

Test Name: Test 1 Date: 4.11.2017. Date: 5.11.2017.

Test Name: Test 2 None

Test Name: Test 3 Date: 1.11.2017.

etc.

If there is no data in pivot table, I cannot associate user with tests.

nenads started a new conversation Find Results For Specified User If They Exists

Hi to all,

I have three tables in my database: users, tests and test_user. One user can have many tests, and one test can have many users.

I want to show list of all tests (even if user didn't do any test) and results for specified user if any record exist in pivot table.

class User extends Model
{
  public function tests()
  {
    return $this->belongsToMany(Test::class);
  }
}

class Test extends Model
{
  public function users()
  {
    return $this->belongsToMany(User::class);
  }
}

class TestController extends Controller
{
  public function index(User $user)
  {
    $tests = Test::with(['users' => function($query) use($user) {
      $query->where('users.id', $user->id);
    }])->get();

    return $tests;
  }
}

Index method in TestController works find but now a have $tests->users (plural) even if I have only one user and I don't like it.

@foreach($tests as $test)
  Name: {{ $test->name }}<hr>
  @foreach($test->users as $user)
    Date: {{ $user->pivot->created_at }}<br>
  @endforeach 
@endforeach 

Is there any better way to do this?

Thanks!

01 Nov
1 year ago

nenads left a reply on Pivot And Model At The Same Time

Hi @druc,

Thank you for your time. If I can have Pivot and Model at the same time, does it mean that I need two different Eloquent classes for that table, one which extends Pivot and another which extends Model?

Currently I change my code to overcome this problem. I don't need real Pivot model at this time, so I've removed using() method and created regular Model.

It was something like this:

class Package extends Model
{
  public function parameters()
  {
    return $this->belongsToMany(Parameter::class)->using(PackageParameter::class)->withTimestamps();
  }
}

class Parameter extends Model
{
  public function packages()
  {
    return $this->belongsToMany(Package::class)->using(PackageParamter::class)->withTimestamps();
  }
}

class PackageParamter extends Pivot
{
  public function customers()
  {
    return $this->belongsToMany(Customer::class)->using(PackageParamterCustomer::class)->withTimestamps();
  }
}

class Customer extends Model
{
  public function values()
  {
    return $this->belongsToMany(PackageParamter ::class)->withPivot('value')->using(PackageParamterCustomer::class)->withTimestamps();
  }
}

class PackageParamterCustomer extends Pivot
{
  //
}

What do you think about database design based on my story? Do you have any suggestion for improvements?

Thanks!

nenads started a new conversation Pivot And Model At The Same Time

Hi to everyone!

Is is possible for the Eloquent model to be Pivot and Model at the same time? Why I need this?

Please see the picture below:

(http://i68.tinypic.com/sgjrkl.png)

I have tables packages and parameters in many-to-many relationship. Pivot table is package_parameter. Next, I have clients table which has many-to-many relationship with pivot table package_paramter. Their pivot table is package_paramter_client.

As you can see on picture above, table package_paramter is Pivot for first relationship but it is also model for another relationship.

If that table extends Pivot, first relationship works fine (I'm using belongsToMany with using() method) but in another relationship when I try to attach package_parameter to client, I'm getting SQLSTATE[42S22]: Column not found: 1054 Unknown column '' in 'field list' error (there is no package_paramtere_id in SQL query. Once I change extends to Model, second relationship works but first don't.

How can I solve this problem? Maybe it is a problem with a database design?

What I want to achieve?

Different packages can have different set of parameters. For every user I can set concrete values for those parameters but which one I can set depends on selected package.

Thanks everyone!