590 experience to go until the next level!
In case you were wondering, you earn Laracasts experience when you:
Earned once you have completed your first Laracasts lesson.
Earned once you have earned your first 1000 experience points.
Earned when you have been with Laracasts for 1 year.
Earned when you have been with Laracasts for 2 years.
Earned when you have been with Laracasts for 3 years.
Earned when you have been with Laracasts for 4 years.
Earned when you have been with Laracasts for 5 years.
Earned when at least one Laracasts series has been fully completed.
Earned after your first post on the Laracasts forum.
Earned once 100 Laracasts lessons have been completed.
Earned once you receive your first "Best Reply" award on the Laracasts forum.
Earned if you are a paying Laracasts subscriber.
Earned if you have a lifetime subscription to Laracasts.
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.
Earned once you have achieved 500 forum replies.
Earned once your experience points passes 100,000.
Earned once your experience points hits 10,000.
Earned once 1000 Laracasts lessons have been completed.
Earned once your "Best Reply" award count is 100 or more.
Earned once your experience points passes 1 million.
Earned once your experience points ranks in the top 50 of all Laracasts users.
Earned once your experience points ranks in the top 10 of all Laracasts users.
Replied to CI/CD Pipelines For Laravel Packages
Oh, migrations needed to be ran. Thanks, working now!
Replied to CI/CD Pipelines For Laravel Packages
Well I did exactly that, however running that returns:
Response status code [500] is not a successful status code. Failed asserting that false is true.
But I'm wondering how would the request even work here? Does Orchestral T. provide some sort of workaround behind the fact that server is not up and running? How can it get to the route?
Replied to CI/CD Pipelines For Laravel Packages
I'm not quite sure how to do that. Testbench documentation is outdated (at least the one I could find here).
Do you have any resources where I could look at to get me started?
Replied to CI/CD Pipelines For Laravel Packages
Wouldn't this be just a workaround? Some things are simple CRUD stuff, but other have minor logic which didn't make sense for me to pull out of controllers. Yes, package is public https://github.com/asseco-voice/laravel-custom-fields
Started a new Conversation CI/CD Pipelines For Laravel Packages
How would I proceed in building a CI/CD pipeline for a package? Specifically what is confusing is how am I supposed to enrich it with Laravel specific things.
I can set up the pipeline to run the tests which will work out of the box, however my package has API routes as well and I would like to test them out as well. The issue I have is that I can't start a package by itself with something like artisan serve
or bringing it up as a stand-alone solution.
It came to mind to set up a pipeline to create a new Laravel project which would require the package, bring up the server and test the routes, but is that really the way to go?
Started a new Conversation Laravel Logging Permissions
How are log permissions supposed to work? https://laravel.com/docs/8.x/logging#configuring-the-single-and-daily-channels
'daily' => [
'driver' => 'daily',
'tap' => [CustomizeFormatter::class],
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'days' => 14,
'permission' => 664,
],
I tried with numeric value as well as doing a string like '0664'
, and logs get created with --w--wx--T
permissions? What am I missing here?
Also, how do I control the owner of the log file? Usually it is daemon:daemon
, but last day it got created as a root:root
and it broke everything.
Awarded Best Reply on Mailable Storage Attachment
Found it, Laravel has attachFromStorage()
method which does the job.
Replied to Mailable Storage Attachment
Found it, Laravel has attachFromStorage()
method which does the job.
Started a new Conversation Mailable Storage Attachment
How are you supposed to attach something from storage to email?
I am storing it as $request->file('attachment')->store('attachments');
and then within the mailable:
foreach ($attachments as $attachment) {
$this->attach($attachment->path, [
'as' => $attachment->name,
'mime' => $attachment->mime_type
]);
}
It is telling me that Unable to open file for reading. And if I instead of path include a Storage::get($attachment->path)
it fails complaining about UTF-8. What is the right way to do it?
Replied to Overriding Core Classes
It feels a bit hacky to me. I ended up using the macros for the job because a lot of classes down the road just aren't containerized and I didn't want to meddle up more than needed. Thinking about future upgrades also here. Thanks anyway!
Replied to Overriding Core Classes
@martinbean is it possible to provide a natural follow-definition for a defined macro without digging into how IDE itself resolves it? Only thing why I'm reluctant to use macro is because from migration perspective it looks as non-existing method
Replied to Overriding Core Classes
Also usually yes :) In this case I have microservices interconnected, and IAM is a single service holding all users. In this setup, created_by
references user ID extracted from incoming token
Replied to Overriding Core Classes
@tippin usually yes, but as I said to @martinbean Builder
class isn't being pulled from container, but rather instantiated in a standard PHP way. So if I bind it to the container it will do nothing since Laravel codebase isn't calling a bound class.
@martinbean one minor detail passed by you, I am not converting the original timestamps, but adding a created_BY
and updated_BY
to have indication about the user who performed creation/editing. Macro is always an option as @tippin also suggested.
Maybe all things aside, it would be better to have those explicit rather than implicit, so macros may be a good way to go...
Replied to Overriding Core Classes
I really don't want to replace originally injected Blueprint
in all migrations. Especially given the fact that this spans across ~10 services, and later onboarding new team members, it will wreak havoc with new migrations etc.
Replied to Overriding Core Classes
@martinbean I tried implementing this in a service provider boot()
method, however it doesn't work (tried register()
also). Unless I've done something wrong, I presume it doesn't work because Blueprint
isn't actually bound in the container. Schema
is though. So I've tried
$this->app->extend(Schema::class, function ($service, $app) {
return new SchemaDecorator($service);
});
And then within the decorator doing:
use ForwardsCalls;
protected $schema;
public function __construct(Schema $schema)
{
$this->schema = $schema;
}
public function __call($method, $parameters)
{
return $this->forwardCallTo($this->schema, $method, $parameters);
}
protected function createBlueprint($table, Closure $callback = null)
{
$prefix = $this->schema->connection->getConfig('prefix_indexes')
? $this->schema->connection->getConfig('prefix')
: '';
if (isset($this->schema->resolver)) {
return call_user_func($this->schema->resolver, $table, $callback, $prefix);
}
return new BlueprintExtension($table, $callback, $prefix);
}
Having the extension look like:
class BlueprintExtension extends Blueprint
{
public function timestamps($precision = 0)
{
parent::timestamps($precision);
$this->string('created_by')->nullable();
$this->string('updated_by')->nullable();
}
}
But this didn't work also. I tried throwing some dd()
's around the new classes and they never get triggered.
@tippin macros work for non-existing methods, using it like this doesn't override or change the original functionality at all.
Started a new Conversation Overriding Core Classes
I'm failing to understand as to how would one extend Laravel core classes. There is this: https://laravel.com/docs/8.x/container#extending-bindings but how would the decorated service look like, and why does it accept original service? What should the decorated service return? How would I override a method from original service?
For example I would like to override Blueprint
class timestamps()
method. So I'd have:
$this->app->extend(Blueprint::class, function ($service, $app) {
return new BlueprintExtended($service);
});
And I'm stuck from there. I have no idea how should the class look like.
I tried with:
private Blueprint $blueprint;
public function __construct(Blueprint $blueprint)
{
$this->blueprint = $blueprint;
}
public function timestamps($precision = 0)
{
$this->blueprint->timestamps($precision);
$this->blueprint->string('created_by')->nullable();
$this->blueprint->string('updated_by')->nullable();
}
But this does nothing...
Replied to Running In Console Micro Optimizations
Well yeah, exactly...but I've noticed by using Clockwork profiler that a portion of a response is framework booting. Since PHP is the way it is, booting happens on every request over again, so I assume it would cut some time off if I used micro-optimizations :)
Started a new Conversation Running In Console Micro Optimizations
I was wondering if I can use app()->runningInConsole()
for my Service Provider micro optimizations?
For example:
public function boot()
{
$this->publishes([__DIR__ . '/Config/containers.php' => config_path('containers.php'),]);
$this->registerCreator();
$this->registerMigrateMakeCommand();
$this->commands([
'my.command.migrate.make',
]);
}
The whole purpose of the things within the boot()
method is to publish the configuration, and provide additional methods when using the migrations.
I can't see a scenario where a request would trigger this part of the code.
Would it be wise then to do:
public function boot()
{
if(app()->runningInConsole()) {
$this->publishes([__DIR__ . '/Config/containers.php' => config_path('containers.php'),]);
$this->registerCreator();
$this->registerMigrateMakeCommand();
$this->commands([
'my.command.migrate.make',
]);
}
}
So that if a standard request is made to prevent running these things unnecessarily?