laravel delete data code example

Example 1: laravel delete where

DB::table('users')->where('id', $id)->delete();

Example 2: laravel soft delete

/** in migrations this changes need to
    add for table we want to add soft delete (LARAVEL)*/

	/** The migrations. START */
	public function up()
	{
		Schema::table('users', function(Blueprint $table)
		{
			$table->softDeletes();
		});
	}
	/** The migrations. END */

	/** after adding softdelete you need to
    point that column in table related model (LARAVEL)*/

	/** The Model. START */
  	use Illuminate\Database\Eloquent\SoftDeletes;
  	class User extends Model {
	  use SoftDeletes;
	  protected $dates = ['deleted_at'];
	}
	/** The Model. END */

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 delete

DB::table('users')->where('votes', '>', 100)->delete();

Example 5: create new record via model in laravel

$userData = array('username' => 'Me', 'email' => '[email protected]');
User::create($userData);