php - Laravel: creating eloquent scope -
hey fellow developers,
i experimenting tad eloquent , ran troubles. token table looks now:
table token email (varchar 255) token (varchar 255) expires (varchar 255) // should int.. created_at timestamp in token model building scope retrieve expired tokens
public function scopeexpired($query) { homecoming $query->where('created_at', '<', date('y-m-d h:i:s', time()- ('expires'*60))); } this trick, ignoring ('expires'*60). if replace 'expires' number, lets 30, works perfectly.
my question comes downwards this: how can utilize value of corresponding row of expires column?
any assistence much appreciated!
regards, pwnball
so, solved problem! did not manage value of corresponding column, figured smart store expire moments of tokens in config.
now i'm using code define scope , works charm! removed 'expires' column token table , replaced a:
type varchar 50 seeing know type of token using @ every point in code, solves dilemma , results in easier-to-maintain code! win-win!
public function scopeexpired($query, $type) { $expires = config::get('app.tokenexpiration.'.$type, 30); homecoming $query->where('created_at', '<', date('y-m-d h:i:s', time()-($expires*60))); } php database laravel-4 eloquent
No comments:
Post a Comment