- <?php
-
- namespace App;
-
- use Illuminate\Database\Eloquent\Model;
-
- class Flight extends Model {
-
-
-
-
-
-
- protected $table = 'my_flights';
-
- protected $primaryKey = 'filght_id';
-
- public $timestamps = false;
-
- protected $dateFormat = 'U';
-
- protected $fillable = ['first_name', 'last_name', 'email'];
-
- protected $guarded = ['id', 'password'];
-
-
-
- public function scopePopular($query) {
- return $query->where('votes', '>', 100);
- }
- public function scopeWomen($query) {
- return $query->whereGender('W');
- }
-
-
-
- }
- <?php
-
- namespace App\Http\Controllers;
-
- use App\Flight;
- use App\Http\Controllers\Controller;
-
- class FlightController extends Controller {
-
- public function all() {
- $flights = Flight::all();
-
- foreach ($flights as $flight) {
- echo $flight->name;
- }
-
- return view('flight.index', ['flights' => $flights]);
- }
-
-
-
- public function select() {
- $flights = App\Flight::where('active', 1)
- ->orderBy('name', 'desc')
- ->take(10)
- ->get();
- }
-
-
-
- public function chunkSelect() {
- Flight::chunk(200, function ($flights) {
- foreach ($flights as $flight) {
- echo $flight->name;
- }
- });
- }
-
-
- public function find() {
- $flight = App\Flight::find(1);
- $flight = App\Flight::where('active', 1)->first();
-
-
- $model = App\Flight::findOrFail(1);
- $model = App\Flight::where('legs', '>', 100)->firstOrFail();
- }
-
-
-
- public function Aggregates() {
- $count = App\Flight::where('active', 1)->count();
- $max = App\Flight::where('active', 1)->max('price');
- }
-
-
-
- public function insert(Request $request) {
- $flight = new Flight;
- $flight->name = $request->name;
-
- $flight->save();
- }
-
-
-
- public function save() {
- $flight = App\Flight::find(1);
- $flight->name = 'New Flight Name';
-
- $flight->save();
- }
-
-
-
- public function update() {
- App\Flight::where('active', 1)
- ->where('destination', 'San Diego')
- ->update(['delayed' => 1]);
- }
-
-
-
- public function firstOrCreate() {
- $flight = App\Flight::firstOrCreate(['name' => 'Flight 10']);
- }
-
-
-
- public function delete(){
- $flight = App\Flight::find(1);
- $flight->delete();
-
- App\Flight::destroy(1);
- App\Flight::destroy([1, 2, 3]);
-
- $deletedRows = App\Flight::where('active', 0)->delete();
- }
-
-
-
- public function softDelete() {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
-
-
-
- public function selectTrashed() {
- $flights = App\Flight::withTrashed()
- ->where('account_id', 1)
- ->get();
- }
-
-
- public function selectOnlyTrashed() {
- $flights = App\Flight::onlyTrashed()
- ->where('airline_id', 1)
- ->get();
- }
-
-
- public function resoreTrashed() {
-
- $flight = \App\Flight::find(1);
- $flight->restore();
-
-
- Flight::withTrashed()->where('account_id', 1)->restore();
- }
-
-
-
- public function forceDelete() {
- $flight = \App\Flight::find(1);
- $flight->forceDelete();
- }
-
-
-
- public function selectClauseTrashed() {
- User::where(function($query) {
- $query->where('name', '=', 'John')->orWhere('votes', '>', 100);
- })->get();
-
-
- User::where('name', '=', 'John')->orWhere('votes', '>', 100)->get();
-
- }
-
-
-
- }
orderBy('Id' , 'DESC') //排序