laravel remove code example
Example 1: laravel update from query
$affected = DB::table('users')
->where('id', 1)
->update(['votes' => 1]);
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 create or update
$flight = App\Models\Flight::updateOrCreate(
['departure' => 'Oakland', 'destination' => 'San Diego'],
['price' => 99, 'discounted' => 1]
);
Example 4: laravel delete
DB::table('users')->where('votes', '>', 100)->delete();
Example 5: Laravel Delete
Flight::destroy(1);
Flight::destroy(1, 2, 3);
Flight::destroy([1, 2, 3]);
Flight::destroy(collect([1, 2, 3]));
Example 6: laravel update
$flight = App\Models\Flight::find(1);
$flight->name = 'New Flight Name';
$flight->save();