Mithrandir

Mithrandir

Member Since 2 Years Ago

Copenhagen

CTO at Chainintra / ZiiK

Experience Points 156,440
Experience Level 32

3,560 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 1483
Lessons
Completed
Best Reply Awards 11
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.

20 Feb
3 months ago

Mithrandir left a reply on What Is Going On?

try

/** @test */
    public function a_project_requires_a_title() {
        $attributes = factory('App\Project')->raw(['title' => '']);
dd($attributes);
        $this->post('/projects', $attributes)->dump();
    }

Run it once, then remove the dd() and run it again - let's see what you are actually providing to the route and what you are actually getting back.

08 Feb
3 months ago

Mithrandir left a reply on Belongs To Many Not Attaching Data Laravel

$guest needs to be either a Model object, the ID of a Model object, a collection of Model objects, or a collection of Model object IDs

25 Jan
3 months ago

Mithrandir left a reply on Localisation With Auth:routes

You must include the {locale} parameter in your controller function

Route::group(['prefix' => '{locale}'], function ($locale) {

    Auth::routes();
    
});
24 Jan
3 months ago

Mithrandir left a reply on Testing An Event Listener With Model Factories

$this->assertEquals('default', $businessUnit->roomTypes->first()->type); // or however you may determine that a RoomType is the default
16 Jan
4 months ago

Mithrandir left a reply on Laravel Do One Query

Also, you should look up what the $appends property does as it is not eager loading.

Mithrandir left a reply on Laravel Do One Query

You are not using the views attribute, you are calling the views relationship.

return $this->views()->count();

performs a query every time it is called

return $this->views->count();

does not.

But the solution by @manelgavalda is better

Mithrandir left a reply on Can Middleware

How about some code?

10 Jan
4 months ago

Mithrandir left a reply on Why Isn't Data Updating?

Do not use {{ this.students }} in your template. Just {{ students}}

07 Jan
4 months ago

Mithrandir left a reply on Oauth - How Do They Do It?

Yes, I understand the process, I just wonder how.

Oauth requires the consumer (Jira in this case) to know the client ID and secret of the provider (Intercom) and to give a redirect_url that is whitelisted in the client configuration. So, are these values already set and preconfigured in the Jira plugin, do you reckon?

I am mainly perplexed by the fact that when I set up Laravel Passport, the process is described as the user creating a new client on the laravel side that can then be configured in other services - but I don't have to do that for Jira-Intercom, I just click some buttons and I'm all set.

Mithrandir left a reply on Oauth - How Do They Do It?

Bumping this to hopefully intrigue someone to chip in

05 Jan
4 months ago

Mithrandir started a new conversation Oauth - How Do They Do It?

I am setting up Laravel Passport in my application and look to other Oauth implementations which makes me wonder a bit.

Example: In Jira, I can integrate the Intercom helpdesk application simply by adding a plugin to Jira and setting up the connection. This is done by clicking a button in Jira that sends me to Intercom - where I am already logged in - that asks me if I want to allow the connection. Click yes and it is done.

My question is: How do they do that when Oauth requires a client ID and a redirect URL to be configured? Do you think that Intercom already has set up a Jira Oauth client and that Jira knows about this, so they don't have to ask the user (me) about it?

Or is there some sort of auto-discovery feature of Oauth, I have not yet figured out?

29 Dec
4 months ago

Mithrandir left a reply on Release() Job Back To Queue After Triggering Own Exception

Actually - why are you even doing it like this? The standard implementation is to (re-)try for a number of times.

https://laravel.com/docs/5.7/queues#max-job-attempts-and-timeout

Mithrandir left a reply on Release() Job Back To Queue After Triggering Own Exception

what is the full code for the job class?

25 Dec
4 months ago

Mithrandir left a reply on Laravel-Echo-Server With A Node-balancer Setup In Production

Solution is to put a haproxy in front of the echo servers and make sure that it has sticky sessions so subsequent requests are sent to the same echo server (as long as it is up)

22 Dec
5 months ago

Mithrandir left a reply on Mailing Inconsistency

@BINIYAM20 - Considering that you don't use $queryMessage - and that it doesn't actually relate to the current user - I would just remove that part and simply return only the renters.

But yes, it is what I meant with moving the data fetching part into handle() since that is executed after the job is taken from the queue.

So as far as I can see, your handle() method could be like this:

public function handle()
    { 
      $service = new RentedListingService();
      $renters = $service->getActiveRentals(); // Assuming getActiveRentals() returns a collection of renters

      $renters->each(function($renter) {
          \Mail::to($renter->email)
                    ->cc('[email protected]')
                    ->send(new ReturnReminder($renter, $renter->active_rented_listings));
      });
    }
21 Dec
5 months ago

Mithrandir left a reply on Mailing Inconsistency

I would suspect that it has to do with the serialization of the SendReminderEmail object.

I assume you in the constructor of SendReminderEmail pass the renters, but are active_rented_listings also loaded at this point?

When SendReminderEmail is queued, it is serialized (basically, the class and ID is stored) and then it is unserialized (basically load the object with the given ID and class from database) when the job runs.

If active_rented_listings is not a relationship or other dynamic (re-)loading property, this will be empty when SendReminderEmail is unserialized and will have to be re-loaded.

Considering that you have the renter and active_rented_listings is a property on the renter, is it possible to load active_rented_listings from inside the handle() of SendReminderEmail? I think that would solve your issue.

Note that I am not commenting on your for-loop... ah bugger, I have to: Why not just use a foreach ($this->renters as $renter) instead of a(n endless) loop?

20 Dec
5 months ago

Mithrandir left a reply on Purpose Of $commands In Kernel.php (Task Scheduling)

In general, we don't want output of cron jobs to go to the console - most include a > /dev/null or similar in the crontab to route output to nowhere. Or a log file.

Usually, we would want our cron jobs to log what they are doing rather than output it to the console.

Are you sure your crontab command is not sending the output to nowhere?

The $this->info() in Commands is usually to provide output when the command is run through Artisan.

18 Dec
5 months ago

Mithrandir left a reply on Filesystem Disk Per User

Try

return \Auth::user()->getStorageInstance()->files();

Mithrandir left a reply on Undefined Variable: JobDetail

public function recruitment()
    {

        $JobDetail = JobDetailModel::get();      
    
        return view('recruitment', compact($JobDetail));
    }

Or more explicit

public function recruitment()
    {

        $JobDetail = JobDetailModel::get();      
    
        return view('recruitment', ['JobDetail' => $JobDetail]);
    }

Mithrandir left a reply on A Nested Query

So you want a list of Category objects that are connected to products for a specific user?

In other words, you want all Category objects that have products for a specific users. Or in Eloquent:

$categories = Category::whereHas('product', function($query) {
  $query->byUser();
});

And - as @palak27 suggests - I would consider adding the ID of the user as a parameter to scopeByUser() to make it more usable in contexts where you want to use another user

12 Dec
5 months ago

Mithrandir left a reply on Extend Core App (Events/Hooks/Actions/Filters)

I am at a loss as to what you are trying to accomplish and with what. I understand the words, but not their meaning...

You have "upgraded your single entity CMS to a centralised core"... I don't know what that means to your code.

"Deploy page permissions in our ACL"... Is that a Policy that determines whether the user can access a specific page?

"Individual pages need to somehow render within the permissions page"... I don't know where the rendering comes into play and why they need to render within the permissions page (what IS the permissions page in this context?) just because they have a key

"I know that events shouldn't really be used in this way"... I don't know what "this way" means to you. Usually when using events in Laravel, you would create individual listeners for the actions you want to perform when a certain event happens. A "page.pages.OnGet" event is really not very descriptive - unless it means "A page was served" in which case I would argue that this is Controller logic? Reacting to the incoming request (be it GET or POST) is Controller domain...

Where in the code are these events triggered?

very confused about pretty much every sentence in your post :)

Mithrandir left a reply on How To Get Record Based On Type?

I cannot explain it better than the existing documentation.

Maybe if you give some more information about your Project, Webdetail and AppDetail classes and how they are connected, it may be easier to point you in the right direction.

Mithrandir left a reply on How To Get Record Based On Type?

I think that if you have such logic in your relationship defining methods, it is a clear smell that something may not be as it should be.

I also think that you should probably use Morphs rather than "normal" relationships. That way, you have one "detail" relationship, but it relates to a different model depending on the value of a field.

Check out https://laravel.com/docs/5.7/eloquent-relationships#polymorphic-relationships

11 Dec
5 months ago

Mithrandir left a reply on Illuminate\Database\Eloquent\ModelNotFoundException: No Query Results For Model [App\Models\Model_name] Inside Laravel JOB

In your constructor, you instantiate two services. These are serialized and will be attempted to be unserialized by the SerializesModels trait - but it will not know how to unserialize this:

$this->dbase = new Colorado_voter();

since what the SerializesModels trait does is save the model primary key on serialize and fetch it out of the database on unserialize. However, your Colorado_voter() does not have a value for its primary key since it is not yet saved to the database.

So I think my question should be: Why do you instantiate these classes in the constructor when you could do it in the handle method as they do not rely on parameters sent to the constructor.

Mithrandir left a reply on API To Store Data Of Two Models

Are you debugging the requestING or the requestED service? Because it seems the Guzzle requests receive error 500's.

Mithrandir left a reply on API To Store Data Of Two Models

What error message does your log show?

Mithrandir left a reply on Illuminate\Database\Eloquent\ModelNotFoundException: No Query Results For Model [App\Models\Model_name] Inside Laravel JOB

Why do you use SerializesModels trait when you are not using models in your job?

10 Dec
5 months ago

Mithrandir left a reply on Refactoring

Depends on the definition of "clean".

I wouldn't get the vacuum out for those two lines as they seem pretty clean.

Mithrandir left a reply on All Problems With The New Laracasts Design

@JEFFREYWAY - Where is the "What's New" option on mobile? I only have Watchlist Favorites Questions Profile Settings

in my avatar menu on Chrome/Android

27 Nov
5 months ago

Mithrandir left a reply on Sending Variables To Controller From Vue Component

What if you send it as an object?

axios.post('/api/v1/customers/pricing/make-paypal-payment/', { paymentId: data.paymentID, cost: self.cost, duration: self.duration, payment_title: self.payment_title, payment_type: self.payment_type})
26 Nov
5 months ago

Mithrandir left a reply on Querying Foreign Table In Model.

setting up the relationship and using accessors is a builtin solution.

I wonder about the why, though - what are you trying to accomplish (in broader terms - like "I want to return a JSON object directly from the attributes" rather than "I want to build a query that returns this")

I guess you could do a Product::select() where you join the colors table once for each color attribute and use SQL aliases to get the color name into the attribute name - but there is still the "why" as to why that is a better solution than an accessor.

Mithrandir left a reply on Polymorphic Many-To-Many Only Working In One Direction

"Exception with message Property [faculties|academicyears] does not exist on this collection instance"

You get an error message regarding a collection instance, but you say that you get a Teacher object - that does not really compute, so can you confirm what kind of object $teacher is with a dump() or similar?

Mithrandir left a reply on Polymorphic Many-To-Many Only Working In One Direction

Can you give more of the stacktrace than just the error message?

Mithrandir left a reply on Crodjob Php Script

According to http://id1.php.net/manual/en/msql.installation.php in order to use this mSql extension, it needs to be compiled into PHP and there are special steps for Windows users.

(apart from that, I - like @globals - initially thought you had misspelled mysql_connect)

22 Nov
6 months ago

Mithrandir left a reply on How Do You Pass Constructor Parameters When You're Instantiating An Interface Through A Bind?

I would use the first part, but let the Auth::id() be settable with a method on ShopManagerEloquent (and - of course - the interface)

so in your controller

$this->middleware(function ($request, $next) {
        $this->repo = resolve(ShopManagerRepository::class);
        $this->repo->setUser(Auth::id());
        return $next($request);
    });
20 Nov
6 months ago

Mithrandir left a reply on Logging Mailables

You can respond to the events raised in the mail sending.

see https://laravel.com/docs/5.7/mail#events

17 Nov
6 months ago

Mithrandir left a reply on Pipelining Laravel Jobs

What is unclean about it?

Sending an event when something happens and have listeners react to it... that doesn't sound all that awful to me

16 Nov
6 months ago

Mithrandir left a reply on It Could Be More Simple To Change The Nova Logo Image

I have not yet had use for Nova, but isn't changing the logo against the terms of service?

All copyright and proprietary notices and logos in the Control Panel and within the Software files must remain intact.

Mithrandir left a reply on Encrypting Database Data

Assuming that your webserver can decrypt the data (in order to show it to the user) and that your webserver is more exposed to the outside world (since it is actively executing code and can be accessed by anyone) I would say database encryption is futile.

The only benefit, I see, is if someone gains access to your database - but not your webserver - they cannot get the personally identifiable information. How likely is it that your database can be compromised but not the webserver at the same time? If very likely, encrypt. If not very likely, don't (but do whatever you can to tighten security at the "front door", i.e. webserver)

Mithrandir left a reply on All Problems With The New Laracasts Design

I miss the old design's easy way to see if there is new content just by going to the catalog.

Now from the front page, I have to go to "browse courses" (that goes to the series listing...) then on "browse", wait for it to load, then uncheck the preselected "series" filter

Mithrandir left a reply on Where Does Parameters From Queue Job Handle Come From?

It is type hinted dependencies and the service container.

See https://laracasts.com/series/laravel-from-scratch-2018/episodes/21 for how those work, but basically in a service provider, the class or interface is mapped to a concrete class to instantiate - or a Closure that will build the actual object. When you type hint the class or interface in certain methods (such as Controller constructors) the concrete class is built and passed by the service container functionality.

Mithrandir left a reply on Pipelining Laravel Jobs

I'm thinking that maybe the Decorator pattern could be of help to you?

https://laracasts.com/lessons/decorating-your-models

You could also dispatch the RequestShip job at the end of ProcessOrder and SendMail at the end of RequestShip, even though that would tie the jobs together, which you perhaps don't want.

05 Nov
6 months ago

Mithrandir left a reply on Scheduled Tasks Duplicating

Just to take out the obvious: Do you have multiple servers running the cron jobs?

03 Nov
6 months ago

Mithrandir left a reply on Echo On Production

If you don't have node on the server, how do you start the Echo server?

How do you run Echo locally?

Mithrandir left a reply on Can't Query Json Field When Testing With Sqlite (:inmemory)

It is somewhat troublesome. From what I can tell, the JSON1 extension is not enabled by default in PDO Sqlite - and I have not found a way to enable it at runtime when using PDO.

I believe the only way to get this is to compile your own PHP/PDO with json1 enabled, but I have not done so - I simply use a different query when driver is sqlite - this is suboptimal for testing, but it gets the (rest of the) job done

Mithrandir left a reply on Show Total Count And Filtered Count Of Relations

True, @tykus but since he has just called $product->comments->count() the line before, the records have already been loaded.

I felt that going into efficiency would be unnecessarily expanding the scope of the question, but now that you have opened that can of worms :)

  1. You should not do these operations in Blade templates - prepare the data in the controllers and only display, loop etc. in the templates
  2. You should eager load the (relevant) comments
  3. You can add a relation in your Product class that can eager load just the count of recommended comments

But again - I think this is out of scope of this question.

02 Nov
6 months ago

Mithrandir left a reply on BadMethodCallException: Method AssertDatabaseHas Does Not Exist.

$this->post() returns a response object that has assertResponseOk() and other response related assertions.

assertDatabaseHas() is a method on your TestCase class and therefore has to be run in that context.

Mithrandir left a reply on Show Total Count And Filtered Count Of Relations

{{ $product->comments->where('recommended', 'Yes')->count() }}
31 Oct
6 months ago

Mithrandir left a reply on Should Policies Be Used In The Controllers Or Models' Boot Methods?

If you want to be able to test that your policies are working, I would suggest that you hit your controllers.

Your policies should be checked before input validation, thus not requiring any parameters.

Alternatively, you can test the policies directly with a unit test.

function can_create_article_fails_for_user()
{
   $user = $this->actAsUser();
   $article = factory(Article::class)->create();
   $this->assertFalse($user->can('create', $article));
}