Answers for "laravel model delete"

PHP
2

laravel eloquent remove from db

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

laravel delete

DB::table('users')->where('votes', '>', 100)->delete();
Posted by: Guest on March-11-2021
6

laravel create or update

// If there's a flight from Oakland to San Diego, set the price to $99.
// If no matching model exists, create one.
$flight = App\Models\Flight::updateOrCreate(
    ['departure' => 'Oakland', 'destination' => 'San Diego'],
    ['price' => 99, 'discounted' => 1]
);
Posted by: Guest on September-27-2020
2

laravel delete relationship data

class User extends Eloquent
{
    public function photos()
    {
        return $this->has_many('Photo');
    }

    // this is a recommended way to declare event handlers
    public static function boot() {
        parent::boot();

        static::deleting(function($user) { // before delete() method call this
             $user->photos()->delete();
             // do the rest of the cleanup...
        });
    }
}
Posted by: Guest on November-08-2020
0

Laravel eloquent delete

use App\Models\Flight;

$flight = Flight::find(1);

$flight->delete();
Posted by: Guest on July-24-2021
1

larave Soft Deletes

Schema::table('flights', function (Blueprint $table) {
    $table->softDeletes();
});
Posted by: Guest on June-12-2020

Browse Popular Code Answers by Language