canfiax

canfiax

Member Since 4 Years Ago

CTO at Athliit

Experience Points 5,470
Experience Level 2

4,530 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 68
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.

25 Feb
1 year ago

canfiax left a reply on Error Running PostgreSQL In Terminal - SQLSTATE[08006] [7] FATAL: Password Authentication Failed For User "myusername"

Current workaround:

Route::get('/migrate', function () {
    dd(\Artisan::call('migrate'));
});

Then go to browser: https://laravelapp.test/migrate

Very weird.....

canfiax started a new conversation Error Running PostgreSQL In Terminal - SQLSTATE[08006] [7] FATAL: Password Authentication Failed For User "myusername"

When using PostgreSQL on my local laravel installation, running php artisan migrate results in the following error:

SQLSTATE[08006] [7] FATAL:  password authentication failed for user "myusername"

However, I don't provide myusername anywhere in my app. Inside my .env file credentials are admin. Perhaps this could be an error message from my database provider (https://compose.io), as my username on the web-platform is myusername. Or, for some strange reason, laravel could be taking myusername which also happens to be my username on my local OS user, running the artisan command.

Either way, I don't seem to know why it doesn't work. If I visit my application in the browser, I see error message: SQLSTATE[42P01]: Undefined table: 7 ERROR: relation \"users\" does not exist\nLINE 1: select * from \"users\" where \"email\" = $1 limit 1\n ^ (SQL: select * from \"users\" where \"email\" = [email protected] limit 1), so it seems as though the credentials in .env is correct, we just need to run the migrations.

24 Feb
1 year ago

canfiax started a new conversation Using "Compose.io" Connecting To PostgreSQL Via TLS

I'd like to connect to a host running PostgreSQL via Compose.io.

I have found the following thread describing how to activate TLS on MySQL: https://laravel.io/forum/06-18-2014-connecting-mysql-over-ssl?page=1, but I haven't been able to find anything for PostgreSQL.

My questions:

  1. How do I activate TLS on PostgreSQL?
  2. How do I properly connect to the host? Currently I get error could not translate host name "aws-eu-west-1-portal.2.dblayer.com/compose" to address: nodename nor servname provided, or not known
10 Jan
1 year ago

canfiax left a reply on Best Way To Load Javascript On A Per Page Basis?

And what if you're using Require? E.g. in your app.js do:

 var Login = require('./Login');

And then on login.blade.php, you would like to do something with the Login variable.

E.g.:

<script>
    window.deferAfterjQueryLoaded.push(function() { 
        $(function() {
            Login.initialize({

            });
        });
    });
</script>

Then it would complain that Login is not defined.

23 Dec
1 year ago

canfiax left a reply on Why Does Laravel Elixir With Gulp Remove Some Of My CSS?

I have the same issue.

In my bootstrap theme, when compiling through Laravel Exlixir, it converts:

background-image: -moz-linear-gradient(0deg, #3e69fe 0%, #4cd4e3 100%);
background-image: -webkit-linear-gradient(0deg, #3e69fe 0%, #4cd4e3 100%);
background-image: -ms-linear-gradient(0deg, #3e69fe 0%, #4cd4e3 100%);

To:

background-image: -ms-linear-gradient(0deg, #3e69fe 0%, #4cd4e3 100%);

And that does for some reason not work in latest version of Google Chrome.

@JeffreyWay what do?

31 Aug
2 years ago

canfiax left a reply on Running `npm Install` On Server Deploy Using Forge

I have found a way to do this on Envoyer (run npm install on builds). Let me know if you would like me to share the solution.

27 Aug
2 years ago

canfiax left a reply on L5 - Request To A Subdomain Is Causing The Session To Be Regenerated

@valeryan I face this exact problem now. Your repo is down.

I tried telling xhr to send withCredentials I don't know if this was your fix, but I've read that somewhere. However, it does not fix my problem.

Can you help?

15 Aug
2 years ago

canfiax left a reply on Running `npm Install` On Server Deploy Using Forge

I have made some additional thoughts to this subject, and I'd really argue that having the deployment server do the minification is a plus, however, I do have some obstracles in mind, that I'd like to find a creative solution to.

Upside:

  • Avoid having the developer to run gulp --production and npm run prod locally. = Higher developer efficiency
  • Avoid stupid merge conflicts with autogenerated files
  • Avoid having github contributions data clustered with auto generated files (currently stats are very inrelaible because it does not ignore the autogenerated files)
  • Lower github data usage

Downside:

  • Running gulp --production and npm run prod takes a lot of time on server, and will cause a higher downtime when upgrading server. I am thinking how we could reduce deployment time to zero, e.g. with Envoyer. Eg duplicate folder, pull down, run gulp & npm, then change symlink. Is this possible? Anyone?
  • Installation of a project might be a bit more complicated (you have to run npm start, gulp, etc before project is fully working). This could also be a smaller problem if you switch a lot between very different branches. Maybe you could avoid this problem on staging and local environments only, so that the gulp/npm processes are only required on production? (however, the github contribution data should also be considered into this).

I'll let you know of my progress.

Also, feel free to chip in if you have some ideas/suggestions as to how I can fix some of above struggles.

09 Jun
3 years ago

canfiax left a reply on Running `npm Install` On Server Deploy Using Forge

True @JoeDawson, but that is just a hotfix to the problem. Having to gulp every time is what we are currently doing but that takes up valuable time.

Also, using versioning on your assets, you'll often have to delete your rev-manifest.json file because it is corrupted due to merge conflicts.

canfiax left a reply on Running `npm Install` On Server Deploy Using Forge

@JoeDawson your suggestion does not help prevent merge conflicts

08 Jun
3 years ago

canfiax left a reply on Running `npm Install` On Server Deploy Using Forge

@JoeDawson Whats important is: merge conflicts when working in teams.

canfiax left a reply on Running `npm Install` On Server Deploy Using Forge

@JoeDawson Because of merge conflicts with autogenerated files (like minified files, soruce maps, etc). This is very annoying when merging branches (when you work in a team).

Also these auto generated files takes up unnecessary space on github, and technically it makes no sense to store these on github (as they are generated).

canfiax started a new conversation Running `npm Install` On Server Deploy Using Forge

I would like to run npm install on the actual forge server, but I have heard that this will cause a timeout on the forge deploy script. Any advise? Is it tottaly stupid to run npm install on the server? It would be prefered because we are dealing with a lot of merge conflicts from autogenerated files every time we merge.

I imagine the deploy script something like this:

cd /home/forge/myapp
git stash
php artisan down
git pull origin production
composer install --no-interaction --no-dev --prefer-dist
php artisan migrate --force
npm install
webpack --p
gulp --production
php artisan up
11 May
3 years ago

canfiax left a reply on What Do You Think About Webpack And Elixir

I have some issues with it as well

03 May
3 years ago

canfiax left a reply on Weird Behavior Between $model->load('relation') And $model->relation

Ok well, then how can I tell Eloquent to reload a relation that is already loaded? I use to use ->load to accomplish this.

canfiax started a new conversation Weird Behavior Between $model->load('relation') And $model->relation

When using where on a hasMany relation like this:

 return $this->hasMany('App\PaymentMethod', 'user_id')->orWhereIn('payment_methods.user_id', $this->sharedAccounts->pluck('id'))->whereNull('deleted_at');

If I run

 $user->paymentMethods

It produces this query:

select * from `payment_methods` where (`payment_methods`.`user_id` = '13' and `payment_methods`.`user_id` is not null or `payment_methods`.`user_id` in ('1', '2', '13') and `deleted_at` is null) and `payment_methods`.`deleted_at` is null

Which is correct IMO. BUT, if I run:

$user->load('paymentMethods')

It produces this query:

 select * from `payment_methods` where (`payment_methods`.`user_id` in ('1', '2', '13') and `deleted_at` is null and `payment_methods`.`user_id` in ('13')) and `payment_methods`.`deleted_at` is null

Notice the difference, where in the first query it correctly adds "or", but in the second, it doe snot.

What is causing this?

canfiax left a reply on Log In With Username Or Email In Laravel 5...

I have used this approach and it is fine.

However, what about handling password resets, etc? I see that there is a contract called UserProvider, here: Illuminate\Contracts\Auth\UserProvider. Maybe there is a smart way to change the approach once, and it will be reflected everywhere.

20 Apr
3 years ago

canfiax left a reply on Why Use TinyInteger Over Boolean For Migrations?

But why not use Boolean? It looks cleaner and he built it after all.

19 Apr
3 years ago

canfiax left a reply on Why Override ToArray() Instead Of Using Accessor

@premsaurav Would love to have that skill, would be easier than asking here. But I guess you are right, only solution is to get @TaylorOtwell own words about it. @spekkionu well, if you call ->tax_rate nothing will happen, since it is not an attribute that exists

canfiax started a new conversation Pull Requests For Spark

Since the git repo is private, how can we contribute to the project? That's a bigger downside to Spark IMO.

canfiax started a new conversation Why Override ToArray() Instead Of Using Accessor

I curiously peeked around the code, and saw that Taylor did the following:

/**
 * Convert the model instance to an array.
 *
 * @return array
 */
public function toArray()
{
    $array = parent::toArray();

    $array['tax_rate'] = $this->taxPercentage();

    return $array;
}

But I wonder why he would override the toArray() method like he did above, and not just define an accessor like this:

public function getTaxRateAttribute() {
    return $this->attributes['tax_rate'] = $this->taxPercentage();
}

Then, when you call ->toArray(), tax_rate would be included.

canfiax started a new conversation Why Use TinyInteger Over Boolean For Migrations?

I noticed Taylor uses tinyInteger instead of boolean. Why would he not use the built in boolean?

As seen in create_users_table.php in Spark: $table->tinyInteger('uses_two_factor_auth')->default(0);

canfiax left a reply on Git / Elixir: Avoiding Merge Conflicts (using Forge)

@dib258 I really like your answer, and used it for quite some time, until we starting using more complex JS that depended on NPM install. Because before you run gulp, you should run npm install, and this gives us some issues.

Are there any other workarounds? I guess there must be at least a thousand people having this issue.

14 Mar
3 years ago

canfiax left a reply on Laravel $dates, From Carbon, Does Not Use App Language

@vandyczech timezones and locale are two different things

@aarondfrancis nice approach in regards to customizing Eloquent. However, in this case it was irrelevant. Eloquent seems to respect the locale set with php's setlocale().

My approach is to use Carbons ->formatLocalized(), and then ensure that locale is installed on server and locally (check by writing locale -a). Follow instructions here: https://github.com/briannesbitt/Carbon/issues/430

11 Mar
3 years ago

canfiax started a new conversation Laravel $dates, From Carbon, Does Not Use App Language

When I change my application locale to danish, it does not change Carbon language.

If I do:

app()->getLocale(); // da (danish)
$mymodel->created_at->getLocale(); // en

How can I get Laravel to set its Carbon instance to the current locale? I have tried setting Carbon::setLocale('da') in a middleware, but that only works if I do Carbon\Carbon::now()->getLocale(), but not for eloquent models.

10 Mar
3 years ago

canfiax left a reply on Prevent Using ->with() When Relationship Is Already Fetched

@thomaskim not sure if that is what I am asking, since they talk about updating etc. But let me show another use-case like @JarekTkaczyk wanted as well.

Say I have a PostTransformer (to make consistent outputs throughout an api):

<?php
    namespace App\Transformers;


    class PostTransformer extends Transformer {

        public function __construct() {
            $this->commentTransformer = new CommentTransformer($this);
        }


        public function transform($post) {
            $return = [
                'id' => (integer) $post->id,
                'text' => (string) $post->text
            ];

            if($post->relationLoaded('comments'))
                $return['comments'] = $this->commentTransformer->trasnformCollection($post->comments);

            return $return;
        }
    }

And a CommentTransformer:

<?php
    namespace App\Transformers;


    class CommentTransformer extends Transformer {

        public function __construct(PostTransformer $postTransformer) {
            $this->postTransformer = $postTransformer;
        }


        public function transform($comment) {
            $return = [
                'id' => (integer) $comment->id,
                'text' => (string) $comment->text,
                'post_id' => (integer) $comment->post_id
            ];

            if($comment->relationLoaded('post'))
                $return['post'] = $this->postTransformer->trasnformCollection($comment->post);

            return $return;
        }
    }

Say I use my PostTransformer like this:

$post = Post::with('comments')->whereId(1)->first();

return app()->make('PostTransformer')->transform($post);

That would output the Post along with the Comments, however, inside each Comment, the "Post" would not be added to the output, since the relation is not loaded.

However, if I do:

$post = Post::with('comments', 'comments.post')->whereId(1)->first();

return app()->make('PostTransformer')->transform($post);

It would. But it would also require an extra query (the n+1 query), but I that would cause the application to make two queries, for the same Post (i.e. select * from posts where id = 1 twice).

canfiax left a reply on Prevent Using ->with() When Relationship Is Already Fetched

I wish you took your time to read and understand my posts. We're on the wrong track here. I know the n+1 rule, I know how eager loading works, and I am not here to discuss the basics of Eloquent.

In above example I don't load multiple models of $post. I load comments from $post, and I don't see why it has to load it every loop iteration since I retrieve comments from the same $post.

What I am asking, anyway, is for laravel to have a parent relationship in a child relation, which it obliviously don't have now. I think I clearly stated an example of where this is not possible in my original answer, and I don't see why I should post different use cases like that, when one should be enough. The core is simple: when dealing with a relation like $comment, you don't always have directly access to $post (e.g. If it is passed into a function,method,etc) so you would only be able to use $comment->post. Since $comment is retrieved through $post->comments I find it very natural that $post should be injecected with $comment, so no database refetch is needed.

09 Mar
3 years ago

canfiax left a reply on Prevent Using ->with() When Relationship Is Already Fetched

@JarekTkaczyk yes in regards to caching that is true. I.e::

$comment = Comment::first();

$comment->post; // query
$comment->post; // using above cached query
$comment->post; // using above cached query
$comment->post; // using above cached query
$comment->post; // using above cached query

However, when using inside a loop of comments, it is not smart enough to cache it:

foreach($post->comments as $comment) {
    $comment->post; // retrieved once, and cached. But in next loop, it will refetch $post
}

canfiax left a reply on Prevent Using ->with() When Relationship Is Already Fetched

@ohffs no I wish it did. That's what I hope Laravel will introduce in a future update.

canfiax left a reply on Prevent Using ->with() When Relationship Is Already Fetched

Thanks @JarekTkaczyk but that did not help my question. I ask because I don't have access to $post->name in my specific example (say a Transformer where I only have the $comment model, and wish to retrieve the $post, that is already loaded in the "stacktrace" further behind).

canfiax left a reply on Prevent Using ->with() When Relationship Is Already Fetched

This is not what I am asking. As a side note, there is no need to eager load using ->with() when you are only fetching ONE posts comments. If I had multiple posts, and then fetching multiple comments, it would make sense to use with.

canfiax started a new conversation Prevent Using ->with() When Relationship Is Already Fetched

I find it strange that I'll have to use ->with() on relationships that is already fetched, to prevent a lot of queries. Let me give you an example:

/**
 * A lot of queries
 * @var [type]
 */

    $post = Post::find(1);

    foreach($post->comments as $comment) {
        echo $comment->text . ' on post ' . $comment->post->name; // calling $comment->post will cause an extra query
    }

I know I can eager load, but that still feels unnecessary since I already have the $post data above.

/**
 * Prevent a lot of extra queries
 */

    $post = Post::find(1);

    foreach($post->comments()->with('post')->get() as $comment) {
        echo $comment->text . ' on post ' . $comment->post->name; // using eagerloading. Still, this will cause to fetch the post 1 twice (since it is loaded using Post::find(1))
    }

This example is extremely simplified. In above example, I could just do:

echo $comment->text . ' on post ' . $post->name;

However, there are many situations, where you don't have directly access to $post (i.e. when using Transformers, or other more complex situations).

What I would like to achieve is for the $post->comments to inject the original $post.

03 Mar
3 years ago

canfiax left a reply on Using Validator With Ajax Requests

@GM good call. Can you reference the github issue you talked about? i'd like to upvote it. I ahve same struggle:

$acceptable = [true, false, 0, 1, '0', '1','true','false'];
29 Feb
3 years ago

canfiax started a new conversation Laravel Says Application Is In Production, Even Though It Is Not.

When I run php artisan env it says my current environment is production even though it is not. I have edited my .env file to APP_ENV=local.

If I run env('APP_ENV') it says LOCAL. But if I var_dump $_ENV the APP_ENV is not present in the array, however all other ENV variables are. However, this behavior is the same for my other project that works fine, so I guess its meant to be hidden from the $_ENV array.

  • I have tried clearing all caches (config:clear, cache:clear, route:clear, view:clear).
  • I have tried restarting my local machine

canfiax started a new conversation Using An Optional Subdomain For Routes, With Default Fallback (for I18n)

I'm working on preparing our Laravel 5.2 application for multilanguage.

I am thinking about sticking with subdomains to differ each language, i.e:

http://en.domain.com (english - default)
http://fr.domain.com (french)

But I'd like our default locale, i.e. english, to exclude the subdomain from the address, so I'd only be:

http://domain.com (english - default)
htttp://fr.domain.com (french)

Any ideas on how to do this?

18 Feb
3 years ago

canfiax left a reply on Has Model Through Relation

So this ended working for me:

/**
 * Get company
 * @return [type] [description]
 */

    public function company() {
        return $this->belongsToThrough(Company::class, Plan::class);
    }
17 Feb
3 years ago

canfiax left a reply on Has Model Through Relation

Yeah, that would work, but then I would not be able to do stuff like:

Subscription::with('company')->get();

canfiax started a new conversation Has Model Through Relation

Say I have the following relationships:

   A Company has many Plan
   A Plan belongs to one Company
   A User has many Subscription
   A Subscription belongs to one Plan

How can I get the Business from a Subscription? I could do something like this:

  $subscription->plan->company

But I would like to do:

 $subscription->company

But I wonder if I could use something like hasOneThrough (even though that does not exist).

15 Feb
3 years ago

canfiax left a reply on Laravel Socialite FB: 400 [reason Phrase] Bad Request

Yeah @bobbybouwmann I just verified my .env files.

services.facebook.client_id
services.facebook.client_secret
services.facebook.redirect

All match rules + developer settings.

canfiax started a new conversation Laravel Socialite FB: 400 [reason Phrase] Bad Request

I am getting the following error using Socialite. After I have authed my app at Facebook, I get redirected back to my app the with code parameter. However, then on the page, I get the following error:

 Client error response [url] https://graph.facebook.com/oauth/access_token?client_id=<my_client_id>&client_secret=<my_secret>&code=<my_code>&redirect_uri=<my_redirect_uri> [status code] 400 [reason phrase] Bad Request

This is the line I use if I have the code parameter:

$user = Socialite::driver('facebook')->user();

Anyone knows why?

11 Feb
3 years ago

canfiax left a reply on Assert Content Equals

This is it:

$response = $this->visit('/');
$this->assertEquals($response->getContent(), 'something');

canfiax started a new conversation Assert Content Equals

In Laravels unit tests, using

->visit('something')

How can I check if content matches something exactly? I know there is ->see('Laravel 5'), but I wish to do something like: ->assertResponseEquals('this-string') to match the response content exactly

canfiax left a reply on Class Log Does Not Exist

Fixed the issue. @LichtAnd

Delete the file

/bootstrap/cache/compiled.php

and run composer install it should work

10 Feb
3 years ago

canfiax left a reply on Class Log Does Not Exist

I Can confirm it is not the env file

canfiax left a reply on Class Log Does Not Exist

Interesting. Seems like a bug that could be related to a recent update.

canfiax left a reply on Append Object To A String Variable In Eloquent

haha @bobbybouwmann you are right. wrong thread

canfiax started a new conversation Class Log Does Not Exist

I have just pulled down my codebase on another OSX El Capitan and I get the following error:

Error Output: PHP Fatal error:  Uncaught ReflectionException: Class log does not exist in /home/vagrant/Projects/myproject/bootstrap/cache/compiled.php:1088

Stack trace:

image

Strange thing is, that the codebase is up-to-date as the other machines, and they do not experience this issue.

I have installed a fresh version of homestead, vagrant and virtualbox on the machine.

I have checked that it is not the .env files. In fact, I did copy and paste the .env files from another computer, so they match.

I am unable to debug this issue further. Tried running:

composer install
composer dumpautoload -o

Still same issue.

canfiax left a reply on Append Object To A String Variable In Eloquent

@bobbybouwmann I think you misunderstand my question.

Another example is this piece of code that actually has same error:

Posted <span class="date"><?php echo e($post->created_at->format('d.m.Y')); ?></span> by <span class="author"><?php echo e($post->author->fullname); ?></span>

How can you tell which of the variables that is undefined since they are on the same line?