cavinz

Javascript : Get Credit card type from number

If we want to get credit card type from input number we have two methods https://jquerycreditcardvalidator.com/ ( from this url you can get the source and implement easily ) below is the function to fetch type <script type=”text/javascript”> function cardtype(number) { var re = new RegExp(“^4”); if (number.match(re) != null)...Read more …
cavinz

Laravel : Pass variable in orWhere condition

Please check below example: $id = “something”; DB::table(‘users’) ->where(‘name’, ‘=’, ‘John’) ->where(function ($query)  as ($id)  { // use this $id in query if you want $query->where(‘votes’, ‘>’, 100) ->orWhere(‘title’, ‘=’, ‘Admin’); }) ->get();Read more …
cavinz

Laravel : Cache Database Queries

Laravel offers a simple mechanism for caching database queries, Example : If we want to cache the user’s table for an hour we have to write this $users = User::remember(60)->get(); that’s it now from this point to next 60 minutes query will not touch the database table User.Read more …
cavinz

Laravel : Easy Relationships with models

Let me give you an example of laravel relationships If User has many tasks and want to list in page Than in the task model define relation with user table and define tasks relationship in User model like below class Task extends Eloquent { public function user() { return $this->belongsTo(‘User’);...Read more …