laravel find with code example
Example 1: laravel update from query
$affected = DB::table('users')
->where('id', 1)
->update(['votes' => 1]);
Example 2: eloquent update row response
DB::table('users')
->where('id', 1)
->update(['votes' => 1]);
Example 3: laravel find by
$flight = App\Flight::find(1);
$flight = App\Flight::where('active', 1)->first();
$flight = App\Flight::firstWhere('active', 1);
Example 4: laravel eloquent remove from db
$res=User::where('id',$id)->delete();
Example 5: laravel eloquent remove from db
public function destroy($id){
$res=User::find($id)->delete();
if ($res){
$data=[
'status'=>'1',
'msg'=>'success'
];
}else{
$data=[
'status'=>'0',
'msg'=>'fail'
];
return response()->json($data);