Wednesday, 12 February 2025

Laravel find string in table and columns

 This code will iterate to all tables and columns


$excludedColumns = array("created_at", "updated_at", "deleted_at","order","key");
$tables = DB::select('SHOW TABLES');
foreach ($tables as $table) {

$tableName = data_get($table,'Tables_in_XXXX','');
$columns = Schema::getColumnListing($tableName);
foreach ($columns as $column) {
if (!in_array($column, $excludedColumns)) {
$sqlString = "select count(*) as total from $tableName where `$column` like '%$searchString%'";

$all = DB::select(($sqlString));
$x = json_decode(json_encode($all), true);

$cnt = $x[0]['total'];
if ($cnt > 0) {
Log::info("select * from $tableName where `$column` like '%$searchString%'");
}
}
}
}
Share:

Tuesday, 11 February 2025

Laravel Cache on Redis

Deleting laravel cache when redis is applied



Assuming the Laravel cache used redis
$roles = Cache::store('redis')->rememberForever(
"roles-123456",
function () {
return Role::where('team_id', 12345)
->
get();
}
);


Cache can only be cleared by


Cache::store('redis')->forget("roles-123456");




Share:

Popular Posts

Recent Posts

Pages

Powered by Blogger.

About Me

My photo
For the past 10 years, I've been playing with codes using PHP, Java, Rails. I do this for a living and love new things to learn and the challenges that comes with it. Besides programming I love spending time with friends and family and can often be found together catching the latest movie or planning a trip to someplace I've never been before.