pawelmysior

pawelmysior

Member Since 3 Years Ago

Gdańsk

Experience Points 65,390
Experience Level 14

4,610 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 512
Lessons
Completed
Best Reply Awards 23
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.

17 Mar
1 month ago

pawelmysior left a reply on Saving Array To DB - Grammar::parameterize() Error

Oh, that's a very interesting problem to solve with collections, have a look at this post from Adam Wathan: https://adamwathan.me/2016/04/06/cleaning-up-form-input-with-transpose/

pawelmysior left a reply on Saving Array To DB - Grammar::parameterize() Error

The create() method that you used expects an array with key => value pairs, with the keys corresponding to the column names. The array that you're sending is not in the correct format. If you're trying to save a single rule, it should look like this:

$data = [
    'field' => 'fieldName',
    'operator' => '=',
    'value' => 'Oliver',
];

$this->rules()->create($data);
03 Mar
1 month ago

pawelmysior left a reply on 404 (Not Found) In Using Ajax

Is district_id being passed to the ajax call? Add a console.log(district_id); before the ajax call and check. Also, go to the /getSchools/{id} route just in your browser and see if you can access it.

25 Jul
8 months ago

pawelmysior left a reply on Laravel 5.6 - How To Easily Send Mail Not Using Smtp Authentication

Have you considered using Mailgun? You get 10 000 emails for free every month and the integration with Laravel is super easy.

17 Oct
1 year ago

pawelmysior left a reply on This Action Is Unauthorized - Even Though User Should Be Authed.

You should pass and Address to your authorize method.

pawelmysior left a reply on Check Teams Slug With Custom Validator

Oh, I didn't see that this was a Spark question. Sorry about that.

pawelmysior left a reply on Check Teams Slug With Custom Validator

If you're saving the slug in the database, you can just use the unique rule on the slug column.

16 Oct
1 year ago

pawelmysior left a reply on Lets Build A Forum Tests, Why $response.

Yes, this is a 5.4 thing.

pawelmysior left a reply on Return Relationship IDs

You don't need to define a global scope to include the types in every query, you can use the $with protected property instead, like so:

class Partner extends Model
{
    protected $with = ['types'];

    // ...
}

pawelmysior left a reply on If $post Is Authenticated User's Post?

= is an assignment operator, == is a comparison operator.

pawelmysior left a reply on Twitter OAuth Keep Redirect To Same Page With Laravel Socialite

Ok, paste more code. You're routes/web.php file, and your whole controller in which the redirectToTwitterProvider method is defined.

pawelmysior left a reply on Twitter OAuth Keep Redirect To Same Page With Laravel Socialite

Socialite needs two methods, that correspond to routes, redirectToProvider and handleProviderCallback.

In the redirectToTwitterProvider you should put code that looks something like this:

return Socialite::driver('twitter')->redirect();
14 Oct
1 year ago

pawelmysior left a reply on How To Add NULL Condition On Auth::attempt

That should work, what do you mean it's "bouncing you back"?

pawelmysior left a reply on Class "classname" Not Found In DB:SEED

Use full namespace in the relationship declaration. So instead of $this->belongsToMany('Picnic', ...) write $this->belongsToMany('App\Picnic', ...).

13 Oct
1 year ago

pawelmysior left a reply on How To Validate&debug A Controller?

No sure what you're trying to do, maybe look at the documentation regard http testing?

pawelmysior left a reply on [5.5] Is There A Way To Turn Rendering Of HttpExceptions Off?

Try this then:

public function render($request, Exception $exception)
    {
        if ($exception instanceof TokenMismatchException) {
            throw $exception;
        }
        
        return parent::render($request, $exception);
    }

Don't forget to import this exception at the top of the file.

pawelmysior left a reply on [5.5] Is There A Way To Turn Rendering Of HttpExceptions Off?

Right, that wont work because the TokenMismatchException gets converted to a HttpException with status code 419 in the original Hanlder's render method.

pawelmysior left a reply on How To Validate&debug A Controller?

If you mean manual testing you can try (Postman)[https://www.getpostman.com/].

pawelmysior left a reply on [5.5] Is There A Way To Turn Rendering Of HttpExceptions Off?

You can override the render method in your app/Exceptions/Handler.php class.

11 Oct
1 year ago

pawelmysior left a reply on How Can I Set Relationships With Mass Insert?

You can use the createMany() method. Here an example from the documentation.

$post = App\Post::find(1);

$post->comments()->createMany([
    [
        'message' => 'A new comment.',
    ],
    [
        'message' => 'Another new comment.',
    ],
]);

pawelmysior left a reply on Package Development

Adding an event to the EventServiceProvider.php file is going to be tough, since it's just an array in a file. You can fire an event in your package, so that the package users can add listeners to it. Creating a listener shouldn't be a problem, you should be able to just use the php artisan make:listenercommand.

pawelmysior left a reply on Using Ajax With A Form

@sheldonscott cool, glad to help

10 Oct
1 year ago

pawelmysior left a reply on Using Ajax With A Form

I think what's happening is that you're submitting the form both "normally" through a POST request as well as using ajax. I imagine you only want to submit it using ajax (XHR), so try something like this:

$('#file-report').click(function(event) {
  event.preventDefault();

  $.ajax({
    ...

This event.preventDefault(); will stop the browser from submitting the form "normally".

You can also use the submit() jQuery listener, which you would bind to the form, rather than the button.

$( "#report" ).submit(function(event) {
  event.preventDefault();

  // submit the form through XHR
});

This way is kind of better because it will also work if the user uses the "enter" button to submit the form.

09 Oct
1 year ago

pawelmysior left a reply on Problem In Code After Upgrade To Laravel 5.4

Yeah, I get that you have relationship defined on your model, but for a specific order, lets say with an id = 5 you might not have have the column user_id defined. Or the user_id is equal lets say 21, but the user with id 21 doesn't actually exist.

pawelmysior left a reply on Problem In Code After Upgrade To Laravel 5.4

It appears that you have an Order which doesn't have a Customer. So $order->customer doesn't exists and that why you're getting the "Trying to get property of non-object" error when accessing the firstname or lastname property of $order->customer.

pawelmysior left a reply on User Relation:morphMap Entries And Get A Model From A String

The morph map is used for polymorphic relations.. Are you those in your project?

Please give more info on your project and what you're trying to accomplish.

pawelmysior left a reply on How To Force JSON Response?

You can return something like this from your controller:

return response()->json($arrayOfDataToBeSerializedToJson);

It will set the response header for you and convert the data to json. Read more here.

08 Oct
1 year ago

pawelmysior left a reply on Routing The "href"

Add http:// to the beginning of the url.

07 Oct
1 year ago

pawelmysior left a reply on DRY Related

You won't have access to the auth user in the controller constructor.

pawelmysior left a reply on After Middleware

Should the users be able to log into the application if they're not activated?

Because maybe you could just include this requirement in the login process.

pawelmysior left a reply on Runtime Override Config

First things first: you won't have access to Auth::user() in your controller constructor. The reason is that the controller constructor executes before any middleware so there's no http request yet, so there's no user yet.

A middleware is a good place to do this, but you need to make sure it's registered after the auth middleware, so that you'll have access to the user.

Make sure that the custom middleware that you created is registered at the end of the $routeMiddleware property in your app/Http/kernel.php file.

pawelmysior left a reply on Validating Based On Array Item In Another Field?

You can create your rules dynamically, like this:

$rules = [
    'data' => 'required|array',
];

if (in_array('O', request->input('data'))) {
    $rules['explanation'] = 'required';
}

And then use them in the validator:

$validator = Validator::make(request->only(['data', 'explanation']), $rules);

pawelmysior left a reply on Validating Based On Array Item In Another Field?

Have you tried just 'explanation' => 'required_if:data,0'?

03 Sep
1 year ago

pawelmysior left a reply on Laravel Route For Index Page Doesnt Work But The Route Exists!

Put this line:

Route::resource('admin/comments/replies', 'CommentRepliesController');

before this line:

Route::resource('admin/comments', 'PostsCommentsController');

16 Aug
1 year ago

pawelmysior left a reply on Show Non-authenticated Routes Regardless Of Authentication

First, I understand that Laravel's default functionality is that, no matter what, if the user is not authenticated, the user is redirected to the login page, and, after successful authentication, is redirected to "/home". I do not want this functionality at all.

That's not exactly accurate. The routes that you define in routes/web.php are be default accessible by anyone, authenticated or not.

pawelmysior left a reply on Access Facades In Session.php And Database.php

Not really. What are you trying to accomplish?

pawelmysior left a reply on Draft Posts With Laravel

Hey, it's a common thing that I need in my projects, so I've created a package for this: check it out here: https://packagist.org/packages/pawelmysior/publishable.

I haven't had a chance to create the documentation yet, but it's very simple to use. You just add a published_at timestamp to the database table and import the Publishable trait into the model.

07 Aug
1 year ago

pawelmysior left a reply on Set Country Code And Country Name On User Model

Yeah, so you can use array_flip() and convert them back when indexing :)

pawelmysior left a reply on Changing User Tables And Column For Authentication And Using Eloquent Driver

Remove this line from both controllers and the User model:

protected $encryptedPassword = 'encryptedPassword';

pawelmysior left a reply on Set Country Code And Country Name On User Model

It's not a good idea to store both the country code and the country name in the database. That an unnecessary duplication.

There are two ways to approach this. You can keep the country code in the database and convert it to the full country name when indexing your data to Algolia. Or you can keep the full name in the database from now on and also update all your existing records.

I like the first approach better. If you're using Laravel Scout you can customize how the models are indexed in Algolia, look here: https://laravel.com/docs/5.4/scout#configuring-searchable-data.

You can use this package: https://github.com/antonioribeiro/countries to convert the country codes to the full names.

pawelmysior left a reply on Validation And FormRequests

You could override the response() method on your FormRequest class.

pawelmysior left a reply on How To Show Data In The Login Form/view If The User Hasn't Login Yet.

You have a LoginController in your app/Http/Controllers/Auth directory. This controller uses the trait Illuminate\Foundation\Auth\AuthenticatesUsers which has the method that you mentioned.

You shouldn't change the trait itself, but you can override this method in your LoginController and it will be used instead of the one in the trait.

pawelmysior left a reply on Validation And FormRequests

Not sure exactly what you need, but if it's custom error messages, you can override the message() method on your FormRequest class.

https://laravel.com/docs/5.4/validation#customizing-the-error-messages

If you need some more specific things, look at the Adding After Hooks To Form Requests section from here: https://laravel.com/docs/5.4/validation#form-request-validation

14 May
1 year ago

pawelmysior left a reply on How To Continue To Submit A Form After Preventing It With JQuery?

I have a piece of code that looks like this:

$('.alpha-btn-delete').on('click', function (e) {
        e.preventDefault();
        let deleteUrl = $(this).attr('href');
        swal({
            title: 'Czy na pewno?',
            text: 'Tej operacji nie można cofnąć!',
            type: 'warning',
            showCancelButton: true,
            cancelButtonText: 'Anuluj',
            confirmButtonColor: '#f05050',
            confirmButtonText: 'Tak, usuń!',
            closeOnConfirm: false,
        }, function () {
            let form = document.createElement('form');
            form.setAttribute('method', 'post');
            form.setAttribute('action', deleteUrl);

            let csrfField = document.createElement('input');
            csrfField.setAttribute('type', 'hidden');
            csrfField.setAttribute('name', '_token');
            csrfField.setAttribute('value', $('meta[name="csrf-token"]').attr('content'));
            form.appendChild(csrfField);

            let methodField = document.createElement('input');
            methodField.setAttribute('type', 'hidden');
            methodField.setAttribute('name', '_method');
            methodField.setAttribute('value', 'DELETE');
            form.appendChild(methodField);

            document.body.appendChild(form);
            form.submit();
        });
    });

pawelmysior left a reply on Where Auth.login View Is Called From

The LoginController uses a trait called AuthenticatesUsers that has a method like this:

public function showLoginForm()
    {
        return view('auth.login');
    }

If you need to change it, you can can override in your LoginController.

pawelmysior left a reply on What Is The Right Way To "Remember" The User Without The Login Checkbox?

Did you import the Request class in your LoginController?

use Illuminate\Http\Request;

pawelmysior left a reply on App::setLocale Is Not Working As Expected In Multiple Route Groups?

Ok, so in the documentation you have an example like this:

Route::get('welcome/{locale}', function ($locale) {
    App::setLocale($locale);

    //
});

Which works because you're defining the route itself as a closure and setting the locale in the closure.

What you're trying to do will not work, because Route::group(function () {}); is pretty much just a dummy grouper. Any non-routing code that you define there will not be executed outside of function scope.

What you could do instead is set the locale in a middleware. Judging from the code you wrote I suggest using a package like this https://github.com/mcamara/laravel-localization or this https://github.com/ARCANEDEV/Localization.