Answers for "delete data from database laravel 8"

PHP
2

laravel eloquent remove from db

$res=User::where('id',$id)->delete();
Posted by: Guest on November-05-2020
2

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);
Posted by: Guest on November-05-2020
0

delete rows by migration laravel

Comment::where('post_id',$id)->delete();

// in down migration

    public function down()
    {
        Schema::table('package_types', function (Blueprint $table) {
            \App\Models\PackageType::query()->where('id','gt',1)->delete();
        });
    }
Posted by: Guest on August-14-2021

Code answers related to "delete data from database laravel 8"

Browse Popular Code Answers by Language