Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Resources;
- use Illuminate\Http\Resources\Json\ResourceCollection;
- use Config;
- use Carbon\Carbon;
- class ExpensesRes extends ResourceCollection
- {
- public function toArray($request)
- {
- // dd($request->all());
- return [
- 'data' => $this->collection->transform(function($expences) {
- //protected
- $protected = false;
- $dateProtected = new Carbon('-'. Config::get('app.protected') .' day');
- if($expences->created_at <= $dateProtected) {
- $protected = true;
- }
- //category
- $category_name = '';
- if($expences->categories) {
- $category_name = $expences->categories->name;
- }
- //expenses_name
- $expenses_name = '';
- if($expences->expancenames) {
- $expenses_name = $expences->expancenames->name;
- }
- //photos
- if(isset($expences->photos)) {
- // dd($expences->photos[0]->url);
- $exp_photo = $expences->photos->transform(function($photo) {
- return [
- 'id' => $photo->id,
- 'name' => $photo->file_name,
- 'url' => $photo->url,
- 'image' => $photo->image,
- ];
- });
- // $car_photo = $expences->photos[0]->url;
- } else { $exp_photo = ''; }
- return [
- 'id' => $expences->id,
- 'category' => $expences->category,
- 'category_name' => $category_name,
- 'expenses_name' => $expenses_name,
- 'date' => $expences->date,
- 'cost' => $expences->cost,
- 'seller_id' => $expences->seller_id,
- 'description' => $expences->description,
- 'mileage' => $expences->mileage,
- 'created_at' => $expences->created_at,
- 'extras' => $expences->extras,
- 'exp_photo' => $exp_photo,
- 'protected' => $protected,
- ];
- }),
- ];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement