Guest User

Untitled

a guest
Dec 10th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. class Post extends Eloquent {
  2.  
  3. /**
  4. * The database table used by the model.
  5. *
  6. * @var string
  7. */
  8. protected $table = 'posts';
  9. protected $softDelete = true;
  10.  
  11. ...
  12.  
  13. ...->whereNull('deleted_at')->get();
  14.  
  15. DB::table('pages')->select('id','title', 'slug')
  16. ->where('is_navigation','=','yes')
  17. ->where('parent_id','=',$parent_id)
  18. ->orderBy('page_order')
  19. ->get();
  20.  
  21. DB::table('pages')->select('id','title', 'slug')
  22. ->where('is_navigation','=','yes')
  23. ->where('parent_id','=',$parent_id)
  24. ->whereNull('deleted_at')
  25. ->orderBy('page_order')
  26. ->get();
  27.  
  28. $objCars = Car::where("color","blue");
  29.  
  30. SELECT
  31. *
  32. FROM
  33. cars
  34. WHERE
  35. deleted_at IS NULL
  36. AND
  37. "color" = 'blue'
  38.  
  39. $objCars = Car::where("color","blue")->orWhere("color","red");
  40.  
  41. SELECT
  42. *
  43. FROM
  44. cars
  45. WHERE
  46. deleted_at IS NULL
  47. AND
  48. "color" = 'blue'
  49. OR
  50. "color" = 'red'
  51.  
  52. SELECT
  53. *
  54. FROM
  55. cars
  56. WHERE
  57. (
  58. deleted_at IS NULL
  59. AND
  60. "color" = 'blue'
  61. )
  62. OR
  63. "color" = 'red'
  64.  
  65. $objCars = Car::where(
  66. function ( $query ) {
  67. $query->where("color","blue");
  68. $query->orWhere("color","red");
  69. }
  70. );
  71.  
  72. SELECT
  73. *
  74. FROM
  75. cars
  76. WHERE
  77. deleted_at IS NULL
  78. AND
  79. (
  80. "color" = 'blue'
  81. OR
  82. "color" = 'red'
  83. )
  84.  
  85. public function __construct()
  86. {
  87. parent::__construct();
  88.  
  89. //Rest of my code
  90. }
  91.  
  92. Post::all()
  93.  
  94. <?php
  95.  
  96. namespace AppModels;
  97.  
  98. use IlluminateDatabaseEloquentModel;
  99. use IlluminateDatabaseEloquentSoftDeletes;
  100.  
  101. class Banners extends Model
  102. {
  103. use SoftDeletes;
  104. //no need of this below line
  105. //protected $softDelete = true;
  106. }
Add Comment
Please, Sign In to add comment