I'm working on a database that has only as a reference your foreign key, and I need to locate the last record based on your foreign key.
I'm working on a database that has only as a reference your foreign key, and I need to locate the last record based on your foreign key.
If you have the standard timestamp fields of laravel, you can give
SuaClasse::where('chave_estrangeira', $chave)->orderBy('created_at', 'desc')->first();
Otherwise an option would be to give the orderBy by ID in the same way, comparing the foreign key