sam |
Is there a way to gatekeep laravel tinker |
I was wondering if it was possible to extend or replace the php artisan tinker command so it first asks for authentication as a way to gatekeep who can use it.
I tried the following:
But I get an error because I have not included the 'include' parameter used by TinkerCommand@handle
I'm not sure what the include argument is about. I tried dumping it and it's an empty array. At this point I'm wondering if there's a better way. |
php
|
php
,
|
|
Miken |
TailwindCSS: Access parent element's background in linear-gradient |
I'm trying to do something but I'm not sure if it's possible. Let's say I have a button inside a div with a background.
<div class="bg-trueGray-300 dark:bg-blueGray-700">
<button class="btn-img-1 h-24 w-48">TEXT</button>
</div>
I want this image to "fade in the background" so to speak. To that end, I've done this:
.btn-img-1 {
background-image:
linear-gradient(to right, theme('colors.blueGray.700'), transparent),
url('../../public/img/buttons/my-img.png');
}
It works... when the dark mode is toggled on. I'd like it to be dynamic. Instead of specifying theme('colors.blueGray.700'), I'd like something like inherit.
Is it possible?
My current "workaround" so to speak is just to specify the rule multiple times.
.btn-img-1 {
...
}
html.dark .btn-img-1 {
...
}
But my concern is that this is completely dependent on me using those background colors to begin with and the fact this will bloat up my stylesheet considerably if I add behavior for :hover and :focus states. |
Javascript
|
programming
,
|
|
sam |
Splitting JS libraries with laravel mix |
I'm currently trying to split JQuery from its plugins using laravel mix. Ideally, I want my views to load only what they need but I can't figure out how to do that the right way with npm.
For example, I'm using the datatables.net and jquery-mask-plugin packages. Both of them depend on JQuery to work.
Currently, what I have is the following |
php
|
laravel
,
|
|
Miken |
checking permissions after updating from laravel 5.7 to laravel 5.8 using silber/bouncer-rc5 |
I am using bouncer for my ACL needs and ever since upgrading my project from laravel 5.7 to 5.8 I've noticed a significant increase in the time it takes for my requests to process. I'm dealing with two models (let's call them Parent and Child), as well as the permissions the authenticated user has over them.
I am using bouncer for my ACL needs and ever since upgrading my project from laravel 5.7 to 5.8 I've noticed a significant increase in the time it takes for my requests to process.
I'm dealing with two models (let's call them Parent and Child), as well as the permissions the authenticated user has over them.
// Takes about 110ms. Eager loads various nested relationships and counters with specific constraints
$parents = Parent::myScope(...)->get();
// Bottleneck. Takes 5 minutes (!). Used to take about 40 seconds on laravel 5.7
$parents->each(function ($parent) {
$parent->permissions = [
'edit' => auth()->user()->can('edit', $parent),
'delete' => auth()->user()->can('delete', $parent),
'restore' => auth()->user()->can('restore', $parent)
];
$parent->children()->each(function ($child) {
$child->permissions = [
'edit' => auth()->user()->can('edit', $child),
'delete' => auth()->user()->can('delete', $child),
'restore' => auth()->user()->can('restore', $child)
];
}
}
I'm appending the permissions like this because the $parents variable will be sent as json to the front-end. I'm pretty sure this implementation is wrong, and must have a better alternative but the real issue is this inexplicable five-fold increase in loading time.
The times were obtained using Debugbar measures.
Using the monitor command in redis-cli (I'm using Redis to cache the permissions), I've noticed the GET requests come more slowly than before. In fact, even after I stop a page from loading (ESC), the GET requests to Redis don't stop immediately. I'm not sure if this is normal behavior or not.
I tried to check the issues at the bouncer repo but I haven't found anything. |
php
|
laravel
,
|
|
sam |
Trying to use config values inside test function |
I'm trying to test a middleware that uses the some config() values but it doesn't work. I'm getting
Illuminate\Contracts\Container\BindingResolutionException: Target class [config] does not exist.
This is not a new issue in the framework (https://github.com/laravel/framework/issues/9733) but I just can't get it to work and it was closed in an unsatisfactory manner.
I've tried :
Not using the config helper and instead using the Facade, but the facade root is not set in a testing environment.
Using a new instance of the config repository itself but well... it's empty.
Any ideas? |
php
|
laravel
,
|
|
Miken |
Force use of HTTP Cache with fetch |
I'm trying to use the HTTP Cache for something simple, but I can't get it to work.
I'm using the following options for fetch().
I tried to just run that same fetch over and over in the span of a minute, expecting to get the same date, unchanged but the results were always "new" so to speak.
Do I have a fundamental misunderstanding of how HTTP Cache works or am I better off just caching the value in the back-end? |
php
|
programming
,
|
|
sam |
Failing validation doesn't stop code execution |
I'm trying to show a list of models. Having a text filter posed no problem but when trying to add a year filter, problems started occurring.
If a non-numeric value is sent back from the from or to input, I expected validation to catch it and just flash some errors to the session but instead I still get SQL errors because either from or to were not numeric (for example: invalid input syntax for integer: "2020a" (SQL: select * f rom "my_models" where "year" between 2020a and 2021))
Livewire Component code |
php
|
php
,
programming
,
|
|
Miken |
Is there a way to customize JSON serialization |
I have a model with some json columns. In my seeder, I got something like this:
When I look at the records inserted in the database (PostgreSQL), I see two problems.
Their values look like arrays
All unicode characters are escaped
Basically, it's using the json_encode() function under the hood with no options and I'd like to pass some options (JSON_FORCE_OBJECT and JSON_UNESCAPED_UNICODE) by default without having to explicitly write it every time. |
php
|
laravel
,
programming
,
|
|