1<?php
2
3namespace App\Models;
4
5use Illuminate\Database\Eloquent\Model;
6use Illuminate\Database\Eloquent\SoftDeletes;
7
8class Flight extends Model
9{
10 use SoftDeletes;
11}
12
13#to restore
14$flight->restore();
15
16#to query trashed models
17Flight::withTrashed()
18 ->where('airline_id', 1)
19 ->restore();
20$flights = Flight::onlyTrashed()
21 ->where('airline_id', 1)
22 ->get();
23
1// Retrieve flight by name, or create it if it doesn't exist...
2$flight = App\Flight::firstOrCreate(['name' => 'Flight 10']);
3
4// Retrieve flight by name, or create it with the name, delayed, and arrival_time attributes...
5$flight = App\Flight::firstOrCreate(
6 ['name' => 'Flight 10'],
7 ['delayed' => 1, 'arrival_time' => '11:30']
8);
9
10// Retrieve by name, or instantiate...
11$flight = App\Flight::firstOrNew(['name' => 'Flight 10']);
12
13// Retrieve by name, or instantiate with the name, delayed, and arrival_time attributes...
14$flight = App\Flight::firstOrNew(
15 ['name' => 'Flight 10'],
16 ['delayed' => 1, 'arrival_time' => '11:30']
17);
1/** in migrations this changes need to
2 add for table we want to add soft delete (LARAVEL)*/
3
4 /** The migrations. START */
5 public function up()
6 {
7 Schema::table('users', function(Blueprint $table)
8 {
9 $table->softDeletes();
10 });
11 }
12 /** The migrations. END */
13
14 /** after adding softdelete you need to
15 point that column in table related model (LARAVEL)*/
16
17 /** The Model. START */
18 use Illuminate\Database\Eloquent\SoftDeletes;
19 class User extends Model {
20 use SoftDeletes;
21 protected $dates = ['deleted_at'];
22 }
23 /** The Model. END */
1<?php
2
3namespace App\Models;
4
5use Illuminate\Database\Eloquent\Model;
6use Illuminate\Database\Eloquent\SoftDeletes;
7
8class Flight extends Model
9{
10 use SoftDeletes;
11}
1$flights = Flight::where('active', 1)
2 ->orderBy('name')
3 ->take(10)
4 ->get();