sirhxalot

sirhxalot

Member Since 3 Years Ago

Zurich

Experience Points
38,870
Total
Experience

1,130 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
351
Lessons
Completed
Best Reply Awards
4
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 8
38,870 XP
Jun
06
4 months ago
Activity icon

Replied to Nested Resource Controllers

The only remaining idea I have is to clear the cache: php artisan cache:clear otherwise I will need to play with your code.

Activity icon

Replied to Nested Resource Controllers

And its still not working? Thats strange:

If a matching model instance is not found in the database, a 404 HTTP response will be automatically generated.

Is there a possibility that you share your code on github?

Activity icon

Replied to Nested Resource Controllers

@CTYLER - Is your class within the namespace App? And is there a id column within your migration?

Activity icon

Replied to Nested Resource Controllers

@CTYLER - It would be a problem if you didn't set the table attribute within your model.

Please add the following to your model:

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'course_categories';
Activity icon

Replied to Nested Resource Controllers

@CTYLER - Hi @ctyler.

If have updated my comment.

Activity icon

Replied to Nested Resource Controllers

Hi @ctyler

Did you tell the resource which model to use as described here: https://laravel.com/docs/5.8/controllers#resource-controllers.

Like so: php artisan make:controller PhotoController --resource --model=Photo

If not the type hinting propably wont work.

Jun
05
4 months ago
Activity icon

Replied to How To Pass Only Form Data Not The Html From One Component To Another On Submit

Hi @saurabh.kackar!

I am not sure if I understand your request - where do you stuck?

If I interpret your title you are looking propably for FormData: https://developer.mozilla.org/de/docs/Web/API/FormData

If you dont know how to pass data in please checkout events: https://vuejs.org/v2/guide/events.html or properties: https://vuejs.org/v2/guide/components-props.html.

And if you are not sure how to post data to a route checkout axios: https://github.com/axios/axios.

Hope I could help you.

Activity icon

Replied to Laravel Dusk - SweetAlert - AssertDialog

From Dusk till dawn - @bobbybouwmann is there for us!

Thank you again you are right!

My final assertion looks like the following:

        $this->browse(function (Browser $browser) use ($user) {
            $browser->loginAs($user)
                    ->visit('/order/create')
                    ->assertDontSee("An error occurred we couldn't proceed. Please checkout your form inputs.")
                    ->type('@first_name', '')
                    ->press('.preview-button')
                    ->waitFor('.swal-overlay--show-modal')
                    ->assertSee("An error occurred we couldn't proceed. Please checkout your form inputs.")
                    ->logout();
        })

It asserts that the text will only be seen if the modal is shown - I am happy ;)

It was my first attemp that a sweet alert is not a dialog - but I was hoping since the role="dialog" attribute has been set that it can detect as a dialog - I was wrong.

I am little bit confused whats a dialog than?

Am I correct that the following elements are dialogs? Are there any more?

Thanks again and keep on going.

Jun
04
4 months ago
Activity icon

Started a new Conversation Laravel Dusk - SweetAlert - AssertDialog

Hi Folks!

I would like to write a Laravel Dusk Test in Laravel 5.8 in order to test dialogs.

So far I have made a Vue Component that contains a button. When the button is clicked it sends a post request to a controller method. If we had a failure e.g. invalid input (validation) a 422 stauts code will be thrown and a sweet alert modal pop ups.

Everything is working as expected. However I wanted to create a Dusk test to check if the modal has been opened so I tried:

        $this->browse(function (Browser $browser) use ($user) {
            $browser->driver->manage()->deleteAllCookies();
            $browser->loginAs($user)
                    ->visit('/order/create')
                    ->type('@first_name', '')
                    ->press('.preview-button')
                    ->waitForDialog(1)
                    ->assertDialogOpened("An error occurred we couldn't proceed. Please checkout your form inputs.")
                    ->logout();
        });

The test seems to be fine since the modal will be opened. However it respond with: Facebook\WebDriver\Exception\TimeOutException: Waited 1 seconds for dialog.

When I open the screenshot in Browser/screenshots/ I see the message!

Besides the deleteAllCookies() has been added just for testing purposes it works neither with or without the code.

Does somebody has a clue?

Thank you in advance.

May
22
4 months ago
Activity icon

Replied to Laravel Authentication Using Form Request Instead Of Array Validation.

@FTIERSCH - 😣 You are right this will improve the code.

This was because I was not being able to see the forest for the trees!

In a perfect world it would be cool to remove the validator method.

However the solution is good enough for me.

Thank you @

Activity icon

Started a new Conversation Laravel Authentication Using Form Request Instead Of Array Validation.

Hi Folks!

I am using Laravel 5.8 and enabled the authentication php artisan make:aut. Everything is working as expected.

But when dealing with user informations that will be stored within the register route I would be also able to reuse the validation for other requests e.g. if I would like to update the data (we call it profile storage for simplicity ;))

So a form request seems to be the solution and I have done it:

App\Http\Requests\StoreUser.php:

    public function rules()
    {
        return [
            'first_name' => ['required', 'string', 'max:255'],
            'last_name'  => ['required', 'string', 'max:255'],
            'title'      => ['max:255'],
            'function'   => ['max:255'],
            'phone'      => ['max:255'],
            'mobile'     => ['max:255'],
            'location'   => ['required', 'exists:locations,id'],
            'email'      => ['required', 'email', 'string', 'max:255'],
            'password'   => ['required', 'string', 'min:8', 'max:255', 'confirmed'],
        ];
    }

But how can I use the form request within the registration controller (App\Http\Controllers\Auth\RegisterController)?

It seems that I can't remove the validator method? I also could not pass in the Form Request instead of an array? And even the create method doesn't allow this!

So my first attemp was to use the rules within the methods:

 /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        $formRequestRules = app(StoreUser::class)->rules();

        return Validator::make($data, [
                'first_name' => $formRequestRules['first_name'],
                'last_name'  => $formRequestRules['last_name'],
                'title'      => $formRequestRules['title'],
                'function'   => $formRequestRules['function'],
                'phone'      => $formRequestRules['phone'],
                'mobile'     => $formRequestRules['mobile'],
                'location'   => $formRequestRules['location'],
                'email'      => $formRequestRules['email'],
                'password'   => $formRequestRules['password'],
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array $data
     * @return \App\User
     */
    protected function create(array $data)
    {
        $user = User::create([
            'first_name'     => $data['first_name'],
            'last_name'      => $data['last_name'],
            'academic_title' => $data['title'],
            'function'       => $data['function'],
            'phone'          => $data['phone'],
            'mobile'         => $data['mobile'],
            'location_id'    => $data['location'],
            'email'          => $data['email'],
            'password'       => Hash::make($data['password']),
        ]);

        $user->assignRole('customer');

        return $user;
    }

It works but I am not a fan!

Is there a better solution where I can use one method to validate and store the user?

Thank you in advance for any possible solutions.

Cheerio!

Activity icon

Replied to Check If Element Has Attribute With Laravel Dusk

Hey @bobbybouwmann

Thank you so much for your hint - it worked out as expected.

The final assertion looks like this:

$browser->assertSourceHas('<input name="email" dusk="email" id="i-email" type="email" maxlength="255" value="[email protected]" required="required" readonly="readonly" class="input ">');

What a mess!

I am not happy with this solution since it doesn't subscribe what I am expecting and its difficult to get the expected source code (had to use pause within the test open chrome console, search the element and copied the outer HTML - too much steps anyhow ;).

In a perfect world I would like to have something like the following:

$browser->assertHasAttribute($field, $expectedAttribute);

If I have time I maybe going to open issue (enhancement request) for this.

Anyhow: Bedankt!

Activity icon

Replied to Auth::user() Returns Null Using Custom Login

@adrock I thought so? I am glad you made it work it out!

Just to improve this you may extract it to the authenticated method as described here: https://laravel.com/docs/5.8/authentication#authenticating-users

May
21
4 months ago
Activity icon

Replied to Auth::user() Returns Null Using Custom Login

If you call the login and removed all dd's i dont see why it should not workout I will test this asap. But for now I have to leave you there.

Activity icon

Replied to Auth::user() Returns Null Using Custom Login

And you call the login (/login)? Correct

Activity icon

Replied to Auth::user() Returns Null Using Custom Login

And if you dd the user object its an instance off app/user? Than remove the dd and you should be logged in?

Activity icon

Replied to Auth::user() Returns Null Using Custom Login

All what it does in the turial is to fetch a user using a where statement. Give the user object to login and you should be done?

Activity icon

Replied to Auth::user() Returns Null Using Custom Login

If your code looks like the posted one I dont get it the tutorials code is different?

Activity icon

Replied to Auth::user() Returns Null Using Custom Login

Did you left the dd?

Activity icon

Replied to Auth::user() Returns Null Using Custom Login

Regarding to dd() method causes null on authentication:

This should be expected - dd means die and dump.

Activity icon

Replied to Auth::user() Returns Null Using Custom Login

Allrigthy you just want to change the useres identifier.

I have not tested what is written within the article - but the instructions seems to be correct!

Your posted code looks slightly different?

Activity icon

Replied to Auth::user() Returns Null Using Custom Login

Hi @adrock

I am not sure how you made your custom login?

My guess is that there is your own authentication service provider? So you may register the provider and its guards: https://laravel.com/docs/5.8/authentication#adding-custom-user-providers

But it seems like an issue with the guards - please checkout: https://laravel.com/docs/5.8/authentication#adding-custom-guards

Greetings Sirthxalot

Activity icon

Started a new Conversation Check If Element Has Attribute With Laravel Dusk

Hi Folks!

I am using Laravel 5.8 in combination with Laravel Dusk.

How can I check if an element has an attribute?

For example I would like to check if an input field has the readonly attribute or not.

I have tried to use assertSee but it does not work?

I double checked if the attribute isset in the HTML code using a pause and opened the console - its there!?

This is the HTML rendered by Laravel:

<section id="email-form-section" class="field" wfd-id="32"><label for="i-email" class="label " wfd-id="37"><span wfd-id="39">E-Mail Address</span> <span class="is-mandatory" wfd-id="38">*</span></label> <div class="columns is-multiline is-vcentered" style="margin-bottom: 0px;" wfd-id="33"><div class="column" wfd-id="34"><div class="control has-icons-left" wfd-id="35">

<input name="email" dusk="email" id="i-email" type="email" maxlength="255" value="[email protected]" required="required" readonly="readonly" class="input " wfd-id="115">

 <span class="icon is-small is-left" wfd-id="36"><i class="far fa-envelope"></i></span></div></div></div></section>

And this is the test case related to this issue:

namespace Tests\Browser;

use App\User;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Spatie\Permission\Traits\HasRoles;
use Symfony\Component\Debug\Tests\Fixtures\TraitWithInternalMethod;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
use Illuminate\Foundation\Testing\DatabaseMigrations;

class ProfileTest extends DuskTestCase
{
    use DatabaseMigrations;

    /** @test */
    public function its_profile_form_is_up()
    {
        $user = factory('App\User')->create([
            'first_name' => "Aegon",
            'last_name' => "Tagaryen",
            'academic_title' => "King",
            'function' => "Torture",
            'phone' => "+414444444",
            'mobile' => "+41788888888",
            'location_id' => 1,
            'email' => "[email protected]",
            'password' => bcrypt('secret')
        ]);

        $this->browse(function (Browser $browser) use ($user) {
            $browser->loginAs($user)
                    ->visit('/profile')
                    ->assertValue('@first_name', 'Aegon');

            $browser->with('@email', function ($emailInput) {
                $emailInput->assertSee('readonly');
            });
        });
    }
}

And finaly the console output:

Time: 21.51 seconds, Memory: 26.00 MB

There was 1 failure:

1) Tests\Browser\ProfileTest::its_profile_form_is_up
Did not see expected text [readonly] within element [body [dusk="email"]].
Failed asserting that false is true.

I have tried to use another selector e.g. #i-email but it didn't worked out.

Does somebody have an idea what I do wrong?