0 Best Reply Awards

  • Member Since 3 Years Ago
  • 132 Lessons Completed
  • 4 Favorites

24th May, 2018

consil left a reply on JWT Authentication, Authorisation And Session, Without A User Table/model • 2 days ago

What a brilliant set of slides (you can tell Luís personally ;-)

Almost didn't need the presentation, but it helps:

23rd May, 2018

consil left a reply on JWT Authentication, Authorisation And Session, Without A User Table/model • 4 days ago

Hi @bobbybouwmann thanks for the tips.

The JWT token will contain an ID for some resources the [human] user will interact with. Those resources will have been pushed into the application via API from another system - the system that sent the user there in the first place, armed with the JWT.

What that user does will not be linked to any user account on the application. It's kind of like they get a temporary access to a locker in a locker room, and can leave stuff in it, take stuff out, and eat any snacks they find in it. Once they close the locker door, or the key self-destructs after 30 minutes, the locker is taken away and the user cannot see or do anything there again. So yes, the user does store state - they change stuff, authorise actions etc.

All the locker knows, is that the person with their browser has a key that is valid and working right now, so they have the authority to do what they like with the contents.

From what you are saying, it seems that tymon/jwt-auth is probably overkill for what I need, and I probably just need the underlying lcobucci/jwt and perhaps some certificate support, and a relatively simple guard that just checks the JWT validity on every page access (and provides details of the resource authorisation). Unraveling the bits of tymon/jwt-auth I don't need may turn out to be more involved. Would that be a fair assessment?

Do you know of any examples that show how a JWT would be used in a non-one page application? I'm guessing the token could just go into a cookie as the easiest way to handle it.

22nd May, 2018

consil started a new conversation JWT Authentication, Authorisation And Session, Without A User Table/model • 4 days ago

As usual, I can't find a channel that seems relevant to my question, so hopefully this channel is okay.

Now, I need to build a simple application, without users, but supporting JWT authentication and authorisation. There will be some simple GUI actions the user can perform, linked to some details in the JWT payment.

SInce the application has no users, it also has no login pages. The JWT will be generated by an external application and the user thrown over to this application with the token to do their stuff. I guess the session will also need to be based on the JWT too - I can't see a need for a second way to handle the user sessions while the JWT is available, with all the details the application needs to give the user access to carry out a few tasks.

Are there any packages that can handle this at a high enough level to just be configurable? Or do I need to build my own gates/auth classes to do this, based on low-level JWT packages? The tymon/jwt-auth package all seems to focus around users logging in, but then I'm not sure what it actually handles after that, so I'm not sure if it fits this use-case or not.

26th April, 2018

consil left a reply on Laravel Does Not Validate Queue Data • 1 month ago

Just a note about Azure queues, and I'm not sure if this is how other queuing systems work:

It looks like when you take a message from an Azure queue, it gets marked as locked, and is invisible to other workers. You then process the message, and when you have finished, you tell Azure whether you want that message permanently removed or not. The idea is that if a job fails for an unexpected reason while "holding the message" then that message is not lost. If the job dies, then Azure will put the message back onto the queue withing 30 minutes, assuming it still needs to be processed. That is reasonable, and puts the queue messages at the heart of the system - each message is assumed to be very important and cannot be lost.

Now, the Laravel Azure queue driver tells Azure that it has processed the queue message when it finishes. It does not matter whether the job "failed" and has been put on the failed table, or finished successfully - the point is that the queue worker has taken ownership for that message and moved it on to the next place of rest.

The big problem comes when the queue worker (artisan queue:work) dies unexpectedly. That's not the job itself, but the worker that listens to the queue and runs the jobs. That is where exceptions are not being handled. If that worker fails, unexpectedly, its end events are never run and the jobs are left in an intermediate state. Sometimes the queue message is left hanging, only to be put back on by Azure in half an hour. Sometimes it's put back on immediately, but the job failed count is not incremented, so it loops retrying forever, and very rapidly.

consil started a new conversation Laravel Does Not Validate Queue Data • 1 month ago

I'm not sure where to post this, and not quite sure what to do about it.. The bottom line is that Laravel takes data from the queues and handles it as though those queue messages are valid, correctly structured, contain job objects that can be unserialized without errors, and basically does a poor job of handling any kind of invalid data that may end up on the queue.

I am using Azure queues, and occasionally Azure will put its own message onto the queue, or it looks that way. I suspect it is the Microsoft library that acts like a message has been put onto the queue when connections time out, but the end result is that the MS Azure Queue Storage library tells Laravel, "here is a message". That message contains some timeout error details and a bit of XML. Laravel cannot cope with that, and ends up throwing all sorts of exceptions, instead of just failing the job and throwing it onto the failed heap.

I had a job put onto the queue for a job class that does not exist (it was another Laravel instance that put it onto the wrong queue). Again, Laravel tries unserializing that job payload, which throws an exception that is not handled in any sensible way. The job exits, but does not call its failed() method, so the queue worker does not know it has ended, the queue message remains locked in Azure for the half an hour that Azure will allow a process to lock it, then the message gets dumped back onto the queue by Azure and the process starts again - an error every half an hour, no completed jobs in that time, no failed jobs registered either, and messages checked out of the Azure queue and so not even visible through other means for debugging.

Then I thought, what if I just throw "xxx" onto the queue. Surely that will be handled correctly? On no, it throws Laravel into an endless loop, trying to process the "xxx" job about 50 times a second, failing each time, and retrying immediately. Again, it is not handled as a failed job, and so no retry count is kept.

So, IMO Laravel queue handling needs some serious fixes here. It is just the points at which it assumes the job details it has been given by an outside source (Azure, memory-based queues, Aamazon SQS etc.) are correctly formatted, valid, safe, and complete. Just one byte out and a production system can go into an overdrive endless loop, or just lose jobs completely.

Is this a common problem? Are there any issues that anyone here is aware of that covers these types of problems that I can add to? This is out-of-the-box Laravel 5.6 behaviour, and it's leaving me a bit nervous. When queues work, they are great, but when something goes wrong, they seem to be able to bring the system down.

20th April, 2018

consil left a reply on How Do I Add A Message To The List Detecting A Closed Database Connection? • 1 month ago

I've added the two "connection lost" messages I've seen to a PR, so hopefully that will go through at some point (hopefully to laravel 5.6).

I also found some strange connection issues with the Azure queue, and that does not have an auto-reconnect facility built in. When the connection to that drops (which happens apparently randomly) it sends an XML message to the Azure Queue library, which then passes it on to the queue worker as though it were a queued message (doh!). This starts a job with that data (doh!) which promptly dies as it attempts to JSON decode the message (doh!) and Laravel does not know it has died since it does not do so cleanly (doh!). The artisan queue worker then just hangs around for ten minutes, blocking doing nothing but waiting for the child process to finish (a child process that is already dead), before issuing an error telling me the job took too long, and then tries to read the next message from the queue - which is a DEAD LINK. DOH!

The result is, I'm telling the queue worker to restart every ten minutes (artisan queue:restart). Hopefully that will keep things up and running.

So, all around - bugs in Laravel, bugs in the MS queue handling composer package, bugs in the Azure network that is up and down like a yoyo. What a fun week :-(

18th April, 2018

consil left a reply on How Do I Add A Message To The List Detecting A Closed Database Connection? • 1 month ago

Yeah, I tried it, but it's using the core trait and not mine. Issue raised on the framework here, which I'll link to the PR:

Thanks for the tips.

consil left a reply on How Do I Add A Message To The List Detecting A Closed Database Connection? • 1 month ago

I've never dived into the ioc container like that before. The Illuminate\Database\Connections class is very specific about needing this trait, and I would have thought the composer autoloader would just load the original every time. Or does the ioc extend the autoloader so that scripts can be overridden?

consil left a reply on How Do I Add A Message To The List Detecting A Closed Database Connection? • 1 month ago

Oh, and does this mean Laravel only auto-reconnects database connections in English locales? Is everyone outside US/UK just hacking a workaround of some sort?

consil started a new conversation How Do I Add A Message To The List Detecting A Closed Database Connection? • 1 month ago

So, I'm using long-running queue workers and an Azure SQL Server database. On the whole it works great, except for when the workers have not processed a job in some time.

What happens is the database connection drops after some time unused, as you would expect, but Laravel does not detect this. Instead it blindly keeps trying to use the dead database connection for every new job that is dispatched.

Azure SQL Server PDO returns this error when the connection times out:

ERROR: SQLSTATE[08S02]: [Microsoft][ODBC Driver 13 for SQL Server]SMux Provider: Physical connection is not usable [xFFFFFFFF].

It seems that Laravel detects a database connection has been lost by comparing this message with a list of messages (all in English!) that it holds here in Illuminate\Database\DetectsLostConnections:

So here is my quandary: how do I fix this? If I add the Azure message "Physical connection is not usable" to this list, then my long-running jobs have a happy time. I can submit this as a PR, so other people's long-running jobs can be in the happy place too. But what do I do in the meantime? What do I need to configure/inject/extend/whatever to get more messages into this array? Overriding that one script in the autoloader is one way, but it's not very update-safe.


11th April, 2018

consil left a reply on Simple Homestead Without Messing With Vagrant? • 1 month ago

It doesn't like symbolic links - "protocol error" :-( I think this is because the filesystem is on the host machine (Windows) and shared with the VM. If the filesystem were on VM and shared with the host machine, this would not be a problem.

But I guess Homestead is configured with the idea that the host OS is always the true owner of the source code and not the VM, which can be destroyed and rebuild at any time. That's fine when the host machine happens to run a form of Unix, but not if it is running Windows.

I use symbolic links a lot when editing a composer package in an application. Well, composer sets up the symbolic links for me when I point the "path repository" for a package at the git clone for the package. Maybe there are other ways to develop a package withing an application that I could explore.

consil left a reply on Simple Homestead Without Messages With Vagrant? • 1 month ago

Okay, thanks for the explanation, I'll give it a go. It will be interesting to see how symbolic links work on Windows and then across the share when I'm editing a package.

consil left a reply on Simple Homestead Without Messages With Vagrant? • 1 month ago

I think it's about the source code being on my local machine. I'm not sure why it would be there. I'd like the code to be managed in the VM, with Linux properties, permissions, symbolic links, git command line in bash etc. That's kind of where I'm coming from.

consil started a new conversation Simple Homestead Without Messages With Vagrant? • 1 month ago

This is my understanding, so correct me if I am wrong: the Homestead VM can be built from scratch using Vagrant. This means your host machine must have Vagrant installed and stack of other stuff to support it.

What I am looking for, is a VM image that I can run in VirtualBox (on Windows 7) that contains the Homestead "stuff", and that does not involve messing around with Vagrant. Is there such a VM image available anywhere?

If there is no VM for this, then do I need to install (headless) Debian in the VirtualBox from an ISO then run some kind of Homestead provisioning in it to give me the VM I need? I have other server tools to install on top of that.

Is this a sensible thing to do, or is every VM install these days built locally using Vagrant, and something I cannot really avoid? I've just been going back and forth all day between incredibly complex sets of instructions. It feels like I want to buy a car, but have to set up a rubber and glass factory to manufacture windows and wheels before I can get my hands on a car. I just want the car :-)

10th April, 2018

consil left a reply on Can I Monitor Supervisord From Within Laravel? • 1 month ago

I'll explore this a little more over the weekend, and post back here with what I'm going to do about it. If it's a new wrapper package, then it will be open for additions/suggestions. I think all the pieces are there, some maybe needing a fresh coat of paint, but otherwise solid.

consil left a reply on Can I Monitor Supervisord From Within Laravel? • 1 month ago

@Helmchen horizon is pretty much just for redis at the moment. I'm using azure to service the queues, so redis isn't even in the picture here.

php artisan queue:restart is preferable to just killing the process, since it signals the process to die as soon as it has finished its current job. Ideally you don't want to kill a worker while it is in the middle of a job.

I've found a package that talks to supervisord really well (it worked for me straight away without any effort) so I might just create a Laravel wrapper for that (to handle the service provider and config settings) assuming it has not already been done. It uses XML-RPC to talk to supervisord, and get statuses, logs, process IDs, tell it to restart or signal processes etc.

Remember, this is just the supervisor. It sits there doing nothing for 99.999% of the time, just keeping an eye on the artisan processes, restarting them if they die. I could tell it to restart a process at any time, and would need to do that if any new code is released. However, I probably don't want to do that, as it will involve the jobs being killed. Instead I want to send the artisan worker(s) an event (something this package supports) to tell the artisan worker to die when it is good and ready. Then supervisord will kick in after noticing it gone and restart it.

Monitoring what is happening on the queues is another level, and there are good laravel packages to help with that. I've not worked out how to throw a failed job back on its original queue via the web interface though (it kind of works, then ends up trying to run a CLI command by invoking the full php executable path, which is protected since it is outside the permitted web root. But that's another problem for another day.

consil left a reply on Can I Monitor Suporvisprd From Within Laravel? • 1 month ago

Just found this:

Works like a dream, though has a big stack of zend dependencies. It probably needs a little expansion to cover some of the functions it does not cover yet (e.g. it can restart all processes, but not restart an individual process).

consil left a reply on Can I Monitor Suporvisprd From Within Laravel? • 1 month ago

Just found this standalone application written in PHP, which shows me it can be done:

I guess the guts of that application need to be ripped out into a separate package, so the communication with supervisord and the front end can be separated.

consil started a new conversation Can I Monitor Suporvisprd From Within Laravel? • 1 month ago

supervisord comes with a simple process monitor that serves pages on port 9100 from the server. Processes can be viewed, restarted, reloaded, logs read and tailed etc. from there, which is handy.

Does it also serve this underlying data and services through an API of some sort? Is there a library that Laravel can use to access the supervisord status, maybe view config and logs, and perhaps allow processes to be restarted?

I've not found anything to fit this requirement, but also not found anyone else asking for this. So I guess it's up in lights and I can't see it, or everyone is happy with the admin page that supervisord serves up now.

Anyone know of any way to do this?

27th March, 2018

consil left a reply on Any Examples Of A Custom Log Handler/driver/channel For Laravel 5.6? • 1 month ago

Thanks Martin, that certainly looks promising.

I wasn't going to write the log in a queue, as the log message links to multiple models too. With the models created in transactions (with the messages) I couldn't be sure the model instances exist in the queue worker database session by the time it runs. The queue worker would fail as it tries to unserialize the models. Your point about the timestamps is a good one to remember if I do end up going down that route.

I'm not logging everything through this channel, just some key blocks of processing, where I can log my database logger with contextual links, and to the standard file logger (as a backup because transactions). I'm hoping that using a channel means I can change my mind later about how it works without revisiting code all over the place.

consil started a new conversation Any Examples Of A Custom Log Handler/driver/channel For Laravel 5.6? • 1 month ago

I would like to add a logging channel that can log messages to a completely custom channel (it's in the database, and links the message to model instances in the $context array).

I'm unsure just where I need to hook into Laravel to do this. I would like as much of the code as possible to go into a package, though appreciate at least an entry in config/logging.php is needed.

What I don't understand is what else needs to be created, and how to tell Laravel about it. I guess I need a channel. Then that channel would need a driver. Is that a monolog driver? Or a custom driver? If it is a monolog driver, then do I create something else that hooks into monolog, some kind of handler? Or a writer? Or something else?

Any pointers would be appreciated.

19th March, 2018

consil left a reply on Update Child Records • 2 months ago

@phildawson from what I can see, and from some experimentation, this updates the child records directly in the database.

However, this does not update via the eloquent models, and that means observer events will not fire. If that is important in your application (and it is to me), then the technique that OP provided is the way to go. Another way to handle it is to hand the looping over to the collection:

$user->renewRecords->each(function ($rr) {
    $rr->foo = 'bar';

I'm adding this, because the two approaches listed in this thread above are not equivalent, but depending on your needs, either approach may work for you, or may not.

14th March, 2018

consil started a new conversation A Job Choosing Its Default Queue • 2 months ago

I would like to set some jobs to dispatch to specific queues. Rather than spread the queue names around the various places where the jobs are dispatched, I would like the jobs to control the queue they are dispatched to for themselves.

From what I can see, a dispatchable job will have a $queue property, and the queue can be hard-coded there:

class MtJob implements ShouldQueue
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    protected $queue = 'my-queue-name';

If the queue name is handled dynamically, such as in a config file, then this can be set in the constructor of the job:

public function __construct(Thing $thingToProcessInJob)

This seems to work, and I can dispatch the job without having to specify a queue. If i do specify a queue when dispatching, then that default queue will be over-ridden.

So, does this seem right? I've not found this technique documented, or anyone else asking how to set a default queue for a job, so I'm unsure whether I'm missing something.

What's more, examples like this are in the docs: ProcessPodcast::dispatch($podcast); and ProcessPodcast::dispatch($podcast)->onQueue('some-queue');. I don't understand how that works. If dispatch dispatches, then surely the onQueue() afterwards is too late, because it is already dispatched and in the queue? Unless this is some kind of "dispatch promise" that does not actually added to the queue until later in the request? I'm curious about how that works.

12th March, 2018

consil left a reply on Having Trouble To Set Up Auto-discovery For A Facade • 2 months ago

I tried this to reset the cached aliases that I changed in a package I was developing. It kept on picking up the old alias name, no matter what I did, and even when there was no trace of the old alias name in any PHP or JSON file in the application.

Turned it out it was an artisan queue:work process that was holding onto the old settings. This is on PHP 7.2, which does some fancy inter-process cacheing of data automatically. I can not see how that process could have affected the composer update otherwise. Once I stopped that queue worker, the clear+update worked a treat.

Just adding this in case anyone else is sat there scratching their head for an hour over why changes aren't being recognised.

8th March, 2018

consil left a reply on Does Anyone Have Examples Of Bootstrap Popover With Laravel Blade • 2 months ago

The answer to my previous question was that popover is built into jQuery. It wasn't working for me, and the reason was that I was using it in dynamic content, in a dataTable. To fix this, instead of binding the popover to each item on the page (items which may then be added dynamically to the pager later, and miss their chance to bind) it is bound to the body instead (or some other wrapping element if you want to contain it to a specific region of the page). The selector option then listens out for hover triggers against matching selectors:

            html: true,
            placement: 'auto left',
            trigger: 'hover',
            selector: '[data-toggle="popover"]'

The data-trigger attribute on the hover-over elements seems a little redundant, as it is also in the javascript options. So I think there is some other subtle setting that I'm missing.

consil left a reply on Does Anyone Have Examples Of Bootstrap Popover With Laravel Blade • 2 months ago

Just for context, where does this "popover" come from? Is it a jQuery plugin that needs installing? Built into jQuery perhaps?

2nd March, 2018

consil left a reply on Using Views For Columns In Datatables • 2 months ago

Just to follow up on the answer from @Voyowsky, this answer works very well and it pretty neat. It is not documented very well (like much of the Laravel DataTables package) but this will call up the view. It includes package-based views, such as ''.

The parameters passed to the view will be the columns selected in the query, so an App\User query would include {{ $id }} and {{ $name }} variables, for example.

26th February, 2018

consil left a reply on Which Laravel Admin Panel Should I Use? • 3 months ago

@royduin how did you get on with the z-song admin? I've narrowed down to and - both look very well written, well documented and well thought out. They both install as packages, [can be configured to] keep themselves in their own areas rather than blatting all over your application space.

The infyom labs version has an edge on reverse-engineering existing models and offering additional features as plugins, while the z-song admin seems overall a lot smoother to use.

Do I toss a die?

19th February, 2018

consil left a reply on Log Rotate • 3 months ago

I'm late here, but there is no reason why a symbolic link could not be used to point laravel.log to the latest named log file when it gets created. That should involve minimum effort for a handy feature.

18th February, 2018

consil left a reply on Where Is The Best Place To Put Queued Job Dispatching? • 3 months ago

Here is how I am handling this for now.

In my application I have a core package (my application is written almost entirely as a bunch of packages). The core package contains all the dependencies on other packages in the application, so it knows all the models it needs to observe are present.

That core package has an Observers directory with an observer class for each model I want to observe. The observer classes are all registered in the boot() method of my core package provider.

use Vendor\Core\Observers\ModelAObserver;
use Vendor\Core\Observers\ModelBObserver;

use Vendor\NonCoreA\ModelA;
use Vendor\NonCoreB\ModelB;

class CoreServiceProvider extends ServiceProvider
    public function boot()

These observers fire off jobs to the queues when they see changes they are interested in. The observer classes are all in one place, and NOT in the framework (they are in a package, which should make upgrades much easier later on), so easy to find and manage. I still wonder whether I need an "observer of the observers" to monitor each time they are triggered by an event, but I can work on that later.

consil started a new conversation Where Is The Best Place To Put Queued Job Dispatching? • 3 months ago

I have an application that processes data in a fairly complex way, with data coming in from a number of sources, and being updated from various triggers.

I have a bunch of jobs that should be despatched on certain triggers, such as creation of a model instance, or changing of a status in a model instance.

What I'm not sure, is the nest place to put the code to handle this dispatching. It could go into the eloquent models, and be scattered around the application that way, This would make it more difficult to see where all the despatching is.

It could go in some central place, where it monitors all events for all eloquent models, and makes decisions on what jobs need to be dispatched. This feels a little messy.

This feels to me like it is a workflow thing. Is this the kind of problem that a Laravel workflow package would handle? Are there any recommendations I could look into? I like the idea of being able to monitor all the triggers and what gets dispatched in one place, so I can see what is happening, and defining these rules through data feels like a good way to do it.

Any oher tips?

15th February, 2018

consil left a reply on How Properly Use The LockForUpdate() Method? • 3 months ago

It makes sense to wrap the lock in a transaction, since I assume you are locking a record to do several operations related to it, so they would be in the same transaction. It may work the same if the lock is done immediately before the transaction is started, but any other statements that follow it will (by default) auto-commit and your lock will be lost.

14th February, 2018

consil left a reply on Refresh And Locka A Model • 3 months ago

I think my solution will be to fetch a completely new instance $modelDummy, locking in the process. Ignore that instance from that point on. Its only purpose is to grab the lock.

Then fresh() the original $model, knowing that will then be refreshed from the database against a locked row that I know won't be changed until the transaction is released.

consil started a new conversation Refresh And Locka A Model • 3 months ago

I would like to refresh a model and lock it for updates at the same time. The reason is to make sure we have the latest model data in memory, and that nothing else can update it while we are working with it in the transaction.

The clincher is that I would like to avoid creating a new instance of the model, so that when we come out of the transaction, the model is up-to-date.

This will refresh a model and lock it by loading a new instance:

$model = $model->lockForUpdate()->find($model->id);

This will refresh a model without creating a new instance:


What I can't seem to see, is a way to mix the two together. I had hoped this would work, but it doesn't:


I'm using this in a transaction like this:

echo $model->status; // NEW

DB::transaction(function () use ($model) {
    $model = $model->lockForUpdate()->find($model->id);
    // Do some transactional stuff here.
    $model->status = 'SUCCESS';

echo $model->status; // NEW - we get the old model still

I would like at the end for $model to have the new status, but that status change was in a different instance. Any clues how I can fix that first line in the transaction?

8th February, 2018

consil left a reply on (Polymorphic) Many-to-many Relation To Multiple Models • 3 months ago

I'm looking to do much the same thing. I have notes against many models, and models with multiple notes. Given a note, I would like to fetch a collection of all model instances that a note links to, where there could be different model classes in that collection.

I think key to this is that the query for each model type must be run separately. You cannot fetch from multiple model tables in one query and hydrate multiple models from that. The one query you can run, and can sort and set a limit on (you will need to do this if you want to page the results) is the polymorphic relationship.

So for example, you may get the first 10 participant_id and participant_type rows, ordered by creation date. From this you can get a list of unique model classes (in participant_type). There may be one, there may be several.

Then you fetch an individual collection of models for each of those models. For 10 initial rows, you may fetch, say, 6 users, 3 teams and one participant.

Then those collections need to be merged together. The merge order you already have - it's in the results to the first query on the polymorphic relationship. The final merged collection will then be a mix of models related to the competition, and hopefully in a sensible order so paging can be used.

That's the logic behind what needs to be done, but I'm at a loss on how to make it work like a Laravel relationship and not just a helper function.

consil left a reply on Looking To Add Notes To Any Model • 3 months ago

Spot-on, thank you. I searched everywhere, but just didn't find the right terms to hit this one.

I started writing a package to do this last night, and it is very much along the same lines as this one, which is reassuring.

Just to expand a little on my use-case, the notes I am saving are mostly system-generated during some complex data processing tasks. I am wanting to use a many-to-many polymorphic relationship so that the context of each note can include the multiple models that are involved in the processing at each stage. The LaravelNotes package only has a one-to-many relationship, but it is easily extendable.

The many-to-many relationship is where the inverse relation comes into play. Given a single note on a model, being able to get a list of other instances of the same model that the note is also connected to, and other instances of other models that the note is connected to, will be very useful. I can't see how to do that that yet without hard-coding the relationships of the application models into the Note model. I'm sure there will be a way to declare the inverse relationships dynamically, or at least by configuration. Also, getting a collection of models connected to a Note, where different models entirely could be in the collection, is going to be interesting. But I guess polymorphic relationships will support that in Laravel without too much effort.

7th February, 2018

consil started a new conversation Looking To Add Notes To Any Model • 3 months ago

I'm wondering if anyone has any recommendations for a package that allows notes to be added to any model in an application. I'm guessing what I need is a polymorphic relationship, that can provide many child records for any other model, and probably a trait to add it to those models. It should be easy enough to write, but I am looking around to see if such a thing already exists so I can see it working practically.

Whether it just deals with the back end relationships, or has views and permissions for dealing with the front end too, I'm not too bothered about, just looking for an example.

29th January, 2018

consil left a reply on [L5] Class App\Console\Kernel Not Found • 3 months ago

Just to note, you should be able to change the application namespace to anything you like, and Laravel is very happy with you doing so (you could have multiple applications in once install, for example). However, there are many third-party packages, and just about every tutorial written ever, that make the assumption your root namespace will be App.

21st January, 2018

consil left a reply on Build Eloquent Structure Before Saving Everything At The End? • 4 months ago

Thanks all. I think in this case I needed to have a little more control over the database sessions. I'm saving error messages to the database while validating the data structure being imported, so I wouldn't want those messages to be rolled back. But I don't want any source data in the database if a single error is hit at any point.

I'm trying this out at the moment as an experiment: since I can't push unsaved child models into an unsaved parent model's relations, I'm instead pushing them into a custom property collection that I am calling "staging".

So I have the $post object, and populating its own properties as normal. Then I'm pushing a bunch of comment objects to its staging collection:


The stagingComments property is a getter that provides access to a stagingComments property intialized to a collection. So I end up with a bunch of eloquent objects all structured into a tree, but not yet saved.

It is at this stage I need to do a dozen or so complex validation checks on the structure, and the nesting and collections provide some great tools for that.

Once the validation is successful, I can whizz through the structure from the root up, saving everything and linking the relationships (that's the easy bit since all the data is already in the form of eloquent objects). I'll do that in one transaction so I can be sure the whole lot goes into the database fully or not at all.

Naturally, it's late, it's experimental, and I might have to revise this in the morning after a good night's sleep. But it is looking promising.

consil left a reply on Build Eloquent Structure Before Saving Everything At The End? • 4 months ago

I've never used Doctine, but will give it a try to see if it makes things like this easier.

So the idea with eloquent is to write everything to the database in a transaction, and then only commit it if you want to at the end. If you don't want it stored permanently, then roll it back.

consil started a new conversation Build Eloquent Structure Before Saving Everything At The End? • 4 months ago

I am loading a text file which contains data that will be structured into four tables. I am currently loading the data into nested collections. When it comes to saving it, I loop over the collections and create models to save.

Now, it occurred to me I'm creating an extra step here - putting the data into one structure, then moving it to another. It makes sense to put the data directly into nested models (all in a with of one-to-many relationships). So is that possible? Can I create that structure before saving to the database?

So to note, I don't want to save anything to the database until I have the whole data structure in memory. If Laravel provides a way to save the whole structure in one go, great, but if not, it's not a problem - I can just loop over the model instances.

If a model is set as a child of another in memory, then when I come to save that child, does eloquent automatically know to add in its referential link to its parent? Or do I need to do that myself?

Thanks. Hope that makes sense.

18th January, 2018

consil left a reply on Form Validation: Custom Error Message With Input Value • 4 months ago

Just looked through the code (I was trying to find a version of :attribute that did not "nicify" the names of the attributes) and found :input. That placeholder will put the name you want into the error message.

I didn't find what I wanted, but discovered that :attribute, :Attribute and :ATTRIBUTE placeholders do some fun things with the letter case of the attribute name.

consil left a reply on Form Validation: Custom Error Message With Input Value • 4 months ago

Would be nice to see this. I'm using the validation rules to validate CSV files as they are imported, so logging the erroneous values within the message text is very useful. It's not like a form where the message can be placed next to the field in error, so it has context.

3rd January, 2018

consil left a reply on Best Practice For Handling "active" Menu Item In L5 • 4 months ago

@johnef_sh see step 1:

Create app/Http/Helpers/BasicViewHelper.php...

2nd January, 2018

consil left a reply on Best Practice For Queues • 4 months ago

It might depend on the API you are using. If the API can retrieve details of all five songs in one call, then it may make sense to handle them all as one job. But the uploading part of your application may push you the other direction.

In general, keep one job doing one thing that can happen independently of other things.

7th September, 2017

consil left a reply on [Package] L5 Package Skeleton • 8 months ago

The digital-baker git user seems to have been deleted or made private now. I just get a 404.

consil left a reply on Where Do I Raise Issues Or Provide PRs? • 8 months ago

Ah, thank you, got it now. The repository does not show up in my list of repositories on github. I actually need to know the URL, and know I'm logged in as the right user, to get to it.

6th September, 2017

consil left a reply on Just Launched My Spark App: ZoneWatcher • 8 months ago

Looks great. However, what do teams represent here? If I'm coming to your service from fresh, and am asked to create a team as the first step, I'd be pretty stumped as to what they mean, what they are, and what I would do with one.

consil started a new conversation Where Do I Raise Issues Or Provide PRs? • 8 months ago

Can't work it out for the life of me, but I'm finding bugs and issues as I go through installation and try to use Spark, but I cannot find any channel to feed this issues or solutions back to. What am I missing? I'm just so used to there being open repositories that I can raise issues on, check for updates, check past issues other people have been having, seeing what fixes other people are doing in their own branches etc. It is kind of frustrating.

consil left a reply on Spark Installation Errors • 8 months ago

I noticed on a recent install that Spark uses some OS tools such as make and a few other less common ones. I needed to manually install them on my server before it would install. This is just one of many dependencies that the install process does not check at the start, but ploughs on through partially installing, and can be very easy to miss in masses of log entries.

Edit Your Profile

Want to change your profile photo? We pull from