dani94

dani94

Member Since 8 Months Ago

Experience Points
290
Total
Experience

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

Level 1
290 XP
Jan
14
3 days ago
Activity icon

Started a new Conversation Help With Service Container

Hey guys!

I am helping to develop a laravel opensource package, but Im a bit confused trying to auto solve dependency inyection.


class MyBaseClass extends FormRequest
{
    protected $model;
    protected $overflow_column;

    public function __construct(Model $model, $overflow_column = "properties")
    {
        $this->model = $model;
        $this->overflow_column = $overflow_column;
    }

   //methods
    ....
}


class MyCustomClass extends MyBaseClass
{
    public function __construct(TestModel $model)
    {
        parent::__construct($model);
    }
}

Im dont know how to auto inyect in custom class which extends from MyBaseClass a laravel Model. (Yes, I read binding doc).

I would like to do something like that:

class UserFormRequest extends MyBaseClass
{
    public function __construct(User $user)
    {
        parent::__construct($user);
    }
}
public class UserController
{
    public function show(UserFormRequest $request)
    {
       // here I can use MyBaseClass methods 
    }
}

I tried (didnt work) manually binding, but I need an auto binding.


public class CustomServiceProvider
{

   public function register()
   {
      $this->app->bind(MyCustomClass::class, function ($app) {
            return new MyCustomClass($app->make(TestModel::class));
        });
   }

}

Thanks!!!

Sep
18
3 months ago
Activity icon

Started a new Conversation Help With Eloquent Query With A Calculated Field

Hey guys,

I got a model Event which has a Report and this report has many Workers. Well, im trying to get all workers with reports in a date ($year + $month) with the time than they spend in this reports, this is calculated field:

    public function getMinutesAttribute()
    {
        $start = Carbon::parse($this->start_at);
        $end = Carbon::parse($this->end_at);

        return $start->diffInMinutes($end);
    }

With next eloquent query, I get reports where has events in a date and counter. But i need also get the time spend. I know I cant use my minutes accessor because it doesnt exists in database. Just I need how to do the callback in the eloquent query to calculated it.

$workers = Worker::whereHas('reports', function ($query) use ($year, $month) {
            $query->join('events', 'reports.event_id', '=', 'events.id')
                ->whereYear('events.date', '=', $year)
                ->whereMonth('events.date', '=', $month);
   })->withCount(['reports' => function ($query) use ($year, $month) {
            $query->join('events', 'reports.event_id', '=', 'events.id')
                ->whereYear('events.date', '=', $year)
                ->whereMonth('events.date', '=', $month);
   }])->with('media.model')
   ->get();

I've only managed to get the reports but not a sum of their start_at and end_at diffeference.

        $workers = Worker::whereHas('reports', function ($query) use ($year, $month) {
            $query->join('events', 'reports.event_id', '=', 'events.id')
                ->whereYear('events.date', '=', $year)
                ->whereMonth('events.date', '=', $month);
        })->withCount(['reports' => function ($query) use ($year, $month) {
            $query->join('events', 'reports.event_id', '=', 'events.id')
                ->whereYear('events.date', '=', $year)
                ->whereMonth('events.date', '=', $month);
        }])->with(['media.model', 'reports' => function ($query) use ($year, $month) {
            $query->join('events', 'reports.event_id', '=', 'events.id')
                ->whereYear('events.date', '=', $year)
                ->whereMonth('events.date', '=', $month);
        }])
            ->get();

Any idea?

Aug
16
5 months ago
Activity icon

Started a new Conversation Problem Creating Factory From A Model With Custom Constructor

Im created few unit testing, they works! But after refactor my Order Model creating custom constructor.

This is my Order Model constructor:

public function __construct()
{
    parent::__construct();
    $this->status()->associate(OrderStatus::PENDINGACCEPTANCE); // this is 1
    $this->user()->associate(Auth::user()->id);
}

My factory class:

$factory->define(App\Order::class, function (Faker $faker) {
    return [
        'user_id' => function () {
            return factory(App\User::class)->create()->id;
        },
        'order_status_id' => function () {
            return factory(App\OrderStatus::class)->create()->id;
        },
        'cart_id' => function () {
            return factory(App\Cart::class)->create()->id;
        },

    ];
});

And once simple example test

public function test_order_has_correct_price_whit_not_disscount()
{
        $products = factory(Product::class, 10)->create();
        $order = factory(Order::class)->create();

        $expectedPrice = 0.00;

        foreach ($products as $product) {
            $this->cartAction->addProducts($product->id, $order->cart);
            $expectedPrice += $product->currentPrice();
        }

        $this->assertEquals($expectedPrice, $order->cart->price());
}

If I try to create order factory instance I get error. "I can understand auth error", but i tried with out this line $this->user()->associate(Auth::user()->id); and still error cause status asosation. Maybe factory create empty object then set attributes? I have no idea how to solve this... Any idea? Thanks guys!

Aug
06
5 months ago
Activity icon

Replied to Issue DUSK Terms Checkbox

The problem was boostrap (I think). I solved the test clicking checkbox with javascript.

->script("document.getElementById('customCheck1').checked = true;")

Activity icon

Replied to Issue DUSK Terms Checkbox

this is not working, I get this error: "element click intercepted: Element is not clickable at point (1176, 709). Other element would receive the click: ..."

Im clicking in label because I have read this trick on stackoverflow. The problem is that this clicking into href.

Aug
05
5 months ago
Activity icon

Started a new Conversation Issue DUSK Terms Checkbox

Hey guys, im trying to click typical terms of use checkbox.

But I cant do it because, the error is

"element click intercepted: Element is not clickable at point (1176, 709). Other element would receive the click: ..."

I found trick on stackoverflow to select instead of checkbox. So i tried and its works if my label has not a href.

My label is like

    <label class="custom-control-label" for="customCheck1">He leído y acepto la <a class="terminos"
        href="/legal">Política de Privacidad de datos</a>.</label>

The problem with this is that if I try to click into the label, it will redirect to /legal, so my test wont works. (I tried removing href and its works).

My code:

    public function elements()
    {
        return [
            '@register-name' => 'input[name=name]',
            '@register-email' => 'input[name=email]',
            '@register-password' => 'input[name=password]',
            '@register-password-confirmation' => 'input[name=password_confirmation]',
            '@register-code' => 'input[name=code]',
            '@register-button' => '.btn-login',
            '@register-terms' => '#customCheck1' //issue, i tried label and checkbox selector
        ];
    }

    public function SignUp(Browser $browser, $name, $email, $password, $code)
    {
        $browser->visit($this->registerUrl())
            ->type('@register-name', $name)
            ->type('@register-email', $email)
            ->type('@register-password', $password)
            ->type('@register-password-confirmation', $password)
            ->type('@register-code', $code)
            ->check('@register-terms')
            ->press('@register-button')
            ->assertPathIs($this->redirectUrl());
    }

do you have any idea how I can do it? Thanks you guys!!

Jul
21
5 months ago
Activity icon

Started a new Conversation Any Pretty Solution For This?

I have Order Model, which has products relationship and products have category relationship. I need to get a function in my model to get single product with a static category.

Im doing the next code in Order.php, my model, but i dont like it.

`` public function mainProduct() { foreach ($this->products as $product) if ($product->category_id == 1) return $product; }