Created
April 10, 2019 12:27
-
-
Save harendra21/bb647765acee8ff3043834a29107cdcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use DB; | |
use Illuminate\Database\Eloquent\Model; | |
class crud extends Model | |
{ | |
public function add($data){ | |
$fName = $data['fName']; | |
$lName = $data['lName']; | |
$email = $data['email']; | |
$phone = $data['phone']; | |
$address = $data['address']; | |
if (isset($data['userId'])) { | |
$id = $data['userId']; | |
return DB::table('users')->where('id', $id)->update([ | |
'first_name' => $fName, | |
'last_name' => $lName, | |
'email' => $email, | |
'phone' => $phone, | |
'address' => $address | |
]); | |
}else{ | |
return DB::table('users')->insert([ | |
'first_name' => $fName, | |
'last_name' => $lName, | |
'email' => $email, | |
'phone' => $phone, | |
'address' => $address | |
]); | |
} | |
} | |
public function getAll(){ | |
$users = DB::table('users')->select('id','first_name','last_name','email','phone','address','created_at')->orderBy('id',"desc")->get(); | |
return $users; | |
} | |
public function getUser($id){ | |
$user = DB::table('users')->select('id','first_name','last_name','email','phone','address','created_at')->orderBy('id',"desc")->where('id',$id)->first(); | |
return $user; | |
} | |
public function deleteUser($userId){ | |
return DB::table('users')->where('id',$userId)->delete(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment