Tray2 liked a comment+100 XP
13h ago
You shouldn't ever need a million rows. Query what's needed and paginate server side.
Tray2 wrote a reply+100 XP
1d ago
Not really, eloquent is just sql in the end, and to order or filter by another table, you need to do a join. Writing joins in eloquent/query builder isn't always pretty, at least not if there are multiple tables involved. One option I like to use is to push the query down into the database, and use a database view, and the use eloquent on that view just as I would a single table. I wrote a blog post on that a few years back, and you can find it here.
https://tray2.se/posts/use-a-view-instead-of-a-complex-eloquent-query-in-your-laravel-application
Tray2 wrote a reply+100 XP
6d ago
@jeffreyway Can you take a look at this issue?
Tray2 wrote a reply+100 XP
1w ago
It depends a little, but as a rule of thumb, you should always leave the code a little cleaner than it was before.
Take this small JavaScript example.
Original code
function setItemHtml(item, html) {
let el = document.querySelector(item);
el.innerHTML = html;
}
Iterration 1
function getElement(selector) {
return document.querySelector(selector);
}
function setItemHtml(item, html) {
let el = getElement(item);
el.innerHTML = html;
}
Itteration 2
function getElement(selector) {
return document.querySelector(selector);
}
function setItemHtml(item, html) {
getElement(item).innerHTML = html;
}
This is the way I would do it, for two reasons, one: reuse, two: cleaner code.
You can argue that using a wrapper for document.querySelector() is unnecessary, I don't agree, getElement is much shorter and at least to me makes more sense. The inlining of the getElement and the assign of innerHTML is a good way to make the function smaller.
Tray2 wrote a reply+100 XP
1w ago
Exactly, tenant first, and then if some company says they need their own db, host the application separately for them.
Tray2 wrote a reply+100 XP
1w ago
It depends, if you have a single controller for it, then it makes sense to have a single test file, but if you use single action controllers, then it makes more sense to have separate test files.
That is of course not the only thing to take into consideration, the size of the file, and groupings of tests, for example separating the validation tests from the route tests would be an option as well.
Tray2 wrote a reply+100 XP
2w ago
Only when it's a legal requirement, and if that is the case, I would host the applications separately as well. One lemp stack for each client.
Tray2 wrote a reply+100 XP
3w ago
In the first example you are loading hundreds of records from the database, and you are checking if you are allowed to delete it for each record, while in the other you are just checking if a variable is true or false.
Tray2 wrote a reply+100 XP
3w ago
I would save the latest payload in the database to display when and if the API fails, then display a last updated message.
I do however have some suggestions.
- Don't be cheap and use a flaky service like that, find a proper one.
- Pay for a service to ensure a good uptime.
Tray2 wrote a reply+100 XP
1mo ago
I will put it like this.
A database table can without problem contain hundred of millions of records, and if indexing isn't enough, you can always partition the table, and that is possible to to per tenant, just give every table a tenant_id, and you should be good to go.
Scope all queries per tenant, then you have the isolation as well.
It's all about database structure, indexes, and proper queries.
Also make sure you normalize your database
https://en.wikipedia.org/wiki/Database_normalization
My recommendation is to use integers as primary and foreign keys, they are usually faster, and to avoid using json columns, since they aren't really indexable.
Tray2 wrote a reply+100 XP
1mo ago
I would suggest against it. Use a single db, it will make your life a lot easier.
Tray2 wrote a reply+100 XP
1mo ago
The short answer is YES.
The slightly longer answer is also yes, the integrity in the database is very important, without it you can't control your application's data in a good way.
Starting out with a column as nullable isn't in my opinion a good idea, it will cause issues when later making it not null. If you manage to do that and keep the database empty until the launch of the app, then it's better, but not good.
I would suggest spending more time on the initial database model.
I wrote these posts a few years ago, but they are still valid.
https://tray2.se/posts/database-design
https://tray2.se/posts/database-design-part-2
https://tray2.se/posts/properly-formed-foreign-keys-are-your-best-friends
Tray2 wrote a reply+100 XP
1mo ago
I usually use the dialog tag for that, it's very easy to use, and has a lot of native functionality.
https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/dialog
Tray2 wrote a reply+100 XP
2mos ago
You can't really prevent it, people can change the metadata. The easiest I think would be to remove any meta, get a checksum for the image, and compare it to what is stored in the database.
Tray2 liked a comment+100 XP
2mos ago
@reshadman My feeling is, if Taylor and the Laravel team wanted validation at the model layer, it would be already.
Tray2 wrote a reply+100 XP
2mos ago
I will put it plainly, unless the data is hashed, the data will be accessible by the person having the root access.
There is no way to encrypt the data and store know the key, the only way for that to work is to allow the tenant to use some kind of secret key, that they need to enter to decrypt the data, and even that isn't fool proof, it probably need to be either passed in every request, or stored temporarily on the session.
Tray2 wrote a reply+100 XP
2mos ago
I've used mohammedmanssour/form-request-tester for these kinds of tests.
The syntax is very clean
use App\Http\Requests\BookFormRequest;
use Carbon\Carbon;
use MohammedManssour\FormRequestTester\TestsFormRequests;
uses(TestsFormRequests::class);
it('fails if the title is missing', function () {
$this->formRequest(BookFormRequest::class)
->post(['title' => ''])
->assertValidationFailed()
->assertValidationMessages(['The title field is required.']);
});
it('fails if the title is not a string', function () {
$this->formRequest(BookFormRequest::class)
->post(['title' => ['Some title']])
->assertValidationFailed()
->assertValidationMessages(['The title must be a string.']);
});
Tray2 wrote a reply+100 XP
2mos ago
I think it might have something to do with the change of hosting for the videos. The old host worked fine with the correct file names, and the new one gave then a generic name like download.mp4 or something like that. So that combined with other stuff, it makes sense to remove it.
Tray2 wrote a reply+100 XP
3mos ago
@lukask If I'm not mistaken, they are only for subscribers.
Tray2 wrote a reply+100 XP
4mos ago
You do know that this thread is 11 years old right?
Tray2 wrote a reply+100 XP
4mos ago
While AI is a good tool to use in many tasks, writing code that you don't understand or know exactly what is does, is not only a risk for bugs, it might also be a security risk.
You can probably get away with not understanding all of the code it writes for a while, but sooner or later it will bite you in the ass.
The smarter the AI tool becomes, the better of a programmer you need to be to spot the mistakes.
A few years back it was quite easy to spot an AI generated image, it could have six fingers or something similarly visible, but now it is really hard to spot one, the same goes for code, it used to be easy to spot the mistakes made by AI, now it isn't as easy.
Tray2 wrote a reply+100 XP
4mos ago
Not sure exactly what it is you want to track here, but a table trigger might be an alternative if you want to track changes made byt the user.
https://tray2.se/posts/using-table-triggers-to-log-changes-in-your-database-tables
Tray2 wrote a reply+100 XP
4mos ago
In that case I would use a sequence from the database.
https://mariadb.com/docs/server/reference/sql-structure/sequences/create-sequence
Tray2 wrote a reply+100 XP
4mos ago
I would even go so far as to why UUID at all if you don't need to make it impossible to guess.
Tray2 wrote a reply+100 XP
4mos ago
Tray2 wrote a reply+100 XP
4mos ago
I would say that it's generally reliable, the thing is most likely that things sometimes takes a little longer to run/render that you would suspect. It could be a db query, or and API hit that causes the delay, and if something is missing when you try to access it, it might look like random errors.
I've been using Cypress and Playwright to run browser tests, and I had to add extra delays in multiple places to get the tests to green every time.
Tray2 liked a comment+100 XP
5mos ago
@Tray2 thank you sir you saved me after 4 hours i dont know what was happening getting crazy !!!
Tray2 wrote a comment+100 XP
5mos ago
@terdoo-mzer Simple you can consider the routes a list of addresses, and it select the first matching one.
Tray2 wrote a reply+100 XP
5mos ago
Yes, you can develop a blog with laravel, you can basically create any kind of web application with it.
Start here https://laracasts.com/series/laravel-from-scratch-2026
Tray2 wrote a reply+100 XP
5mos ago
Easiest is to use github, other than that you can use a mounted share, or a regular usb stick.
Tray2 wrote a reply+100 XP
5mos ago
Looks like that senior used to be a Cobol programmer.
I guess there are no tests written for it either, but if there are, I would ctrl-a delete, and start from scratch.
If not, the I would start by extraction each segment of the if statements to it's own method.
For example
if ($data['user']['send_email']) {
$skipResetPassword = array_key_exists('skip_reset_password', $data['user']);
$withDelay = (array_key_exists('invite_email_with_delay', $data['user']) ? $data['user']['invite_email_with_delay'] : true);
$this->sendInviteEmail($modelResource, $setInviteFlag, $skipResetPassword, $withDelay);
}
would become something like this
function sendInviteEmailIfNeeded($modelResource, $setInviteFlag, $data)
{
if (! $data['user']['send_email']) return;
$skipResetPassword = array_key_exists('skip_reset_password', $data['user']);
$withDelay = (array_key_exists('invite_email_with_delay', $data['user']) ? $data['user']['invite_email_with_delay'] : true);
$this->sendInviteEmail($modelResource, $setInviteFlag, $skipResetPassword, $withDelay);
}
