SHARE
TWEET

Eloquent

a guest Oct 23rd, 2019 71 in 155 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. php artisan make:model Flight -m ili --migration
  2.  
  3. use Illuminate\Database\Eloquent\Model;
  4.  
  5. Class Flight extends Model
  6. {
  7.     -On pretpostavlja da mi koristimo tabelu Flights osim ako mu mi ne kazemo dole..->
  8.     protected $table = "my_flights";
  9.     protected $id = "flight_id"; //eloquent castuje u int automatski ako hocemo drugacije moramo da mu navedemo sa protected $keyType = 'string';
  10.    
  11.     -On Automatski pravi kolone created_at i updated_at ako necemo da ih imamo stavimo
  12.     public $timestamps = false;
  13.    
  14.     -Ako hocemo menjati imena tih kolona stavimo sledece:
  15.     const CREATED_AT = "NaseIme";
  16.     const UPDATET_AT = "NaseIme";
  17.  
  18.     -$attributes se koristi da postavimo neke defaultne vrednosti nekih kolona..npr:
  19.     protected $attributes = [
  20.         'delayed' = false,
  21.         'true' = true
  22.     ];
  23.  
  24.     -postoje fresh i refresh metode za osvezavanje.
  25.     npr: $flight = App\Flight::where('number', 1)
  26.             ->first();
  27.     $freshFlight = $flight->fresh();
  28.  
  29.     -Eloquent ima mnoge metode, to pogledati vremenom u docs.
  30.    
  31.     -Illuminate\Database\Eloquent\Collection pruza mnoge klase pomocne, instanca toga pomaze.
  32.     -findOrFail(); -> metod za not found exception
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top