Asset.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\Validator;
  6. class Asset extends Model
  7. {
  8. use HasFactory;
  9. /**
  10. * The database table used by the model.
  11. *
  12. * @var string
  13. */
  14. protected $table = 'assets';
  15. /**
  16. * The database primary key value.
  17. *
  18. * @var string
  19. */
  20. protected $primaryKey = 'id';
  21. /**
  22. * Attributes that should be mass-assignable.
  23. *
  24. * @var array
  25. */
  26. protected $fillable = [
  27. 'vendor_id',
  28. 'category_id',
  29. 'name',
  30. 'model_name',
  31. 'model_number',
  32. 'registered_number',
  33. 'brand',
  34. 'duration',
  35. 'asset_type',
  36. 'cost',
  37. 'description',
  38. 'image',
  39. 'weight',
  40. 'size',
  41. 'return_policy',
  42. 'status',
  43. 'meta_keyword',
  44. 'meta_description',
  45. 'created_by',
  46. ];
  47. public function validate($request){
  48. $validate = Validator::make($request->all(), [
  49. 'name' => 'required',
  50. 'cost' => 'required',
  51. ]);
  52. if($validate->fails()){
  53. return response()->json([
  54. 'status' => false,
  55. 'message' => 'Validation errors in your request',
  56. 'errors' => $validate->errors()
  57. ], 400);
  58. }
  59. return response()->json([
  60. 'status' => true,
  61. 'message' => 'sucess',
  62. 'errors' => ''
  63. ], 200);
  64. }
  65. }