laravel create or delete code example
Example 1: laravel delete where
DB::table('users')->where('id', $id)->delete();
Example 2: laravel soft delete
public function up()
{
Schema::table('users', function(Blueprint $table)
{
$table->softDeletes();
});
}
use Illuminate\Database\Eloquent\SoftDeletes;
class User extends Model {
use SoftDeletes;
protected $dates = ['deleted_at'];
}
Example 3: Laravel Delete
Flight::destroy(1);
Flight::destroy(1, 2, 3);
Flight::destroy([1, 2, 3]);
Flight::destroy(collect([1, 2, 3]));
Example 4: laravel update
<!-mass update-->
App\Models\Flight::where('active', 1)
->where('destination', 'San Diego')
->update(['delayed' => 1]);