FundingController.php 1.63 KB
Newer Older
beardedwarrior's avatar
beardedwarrior committed
1
2
3
4
<?php

namespace App\Http\Controllers;

5
use App\Http\Resources\ProjectResource;
beardedwarrior's avatar
beardedwarrior committed
6
7
use App\Project;
use Illuminate\Http\Request;
beardedwarrior's avatar
beardedwarrior committed
8
use SimpleSoftwareIO\QrCode\Facades\QrCode;
beardedwarrior's avatar
beardedwarrior committed
9
10
11
12

class FundingController extends Controller
{
    /**
13
     * Shows all projects
beardedwarrior's avatar
beardedwarrior committed
14
     *
15
16
     * @param Request $request
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\Resources\Json\AnonymousResourceCollection|\Illuminate\View\View
17
     */
18
    public function index(Request $request)
19
    {
20
21
22
23
24
25
        $projects = Project::paginate(15);
        // If the request has header `Accept: */json`, return JSON
        if ($request->wantsJson())
        {
            return ProjectResource::collection($projects);
        }
26
27
28
29
30
31
32
        return view('projects.index')
            ->with('projects', $projects);
    }

    /**
     * Shows the project based on the payment id
     *
33
     * @param Request $request
34
     * @param $paymentId
35
     * @return ProjectResource|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
beardedwarrior's avatar
beardedwarrior committed
36
     */
37
    public function show(Request $request, $paymentId)
beardedwarrior's avatar
beardedwarrior committed
38
    {
39
40
        $project = Project::where('payment_id', $paymentId)->firstOrFail();

41
42
43
44
        if ($request->wantsJson())
        {
            return new ProjectResource($project);
        }
45

46
        return view('projects.show')
47
            ->with('project', $project);
beardedwarrior's avatar
beardedwarrior committed
48
    }
beardedwarrior's avatar
beardedwarrior committed
49
50
51
52
53
54
55
56
57
58
59
60
61

    public function donate(Request $request, $paymentId)
    {
        $project = Project::where('payment_id', $paymentId)->firstOrFail();

        if ($request->wantsJson())
        {
            return new ProjectResource($project);
        }

        return view('projects.donate')
            ->with('project', $project);
    }
beardedwarrior's avatar
beardedwarrior committed
62
}