FundingController.php 1.44 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 33
        return view('projects.index')
            ->with('projects', $projects);
    }

    /**
     * Shows the project based on the payment id
     *
     * @param $paymentId
beardedwarrior's avatar
beardedwarrior committed
34
     *
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
    {
        $project = Project::where('payment_id', $paymentId)->first();
40 41 42
        if (!$project) {
            abort(404);
        }
43 44 45 46
        if ($request->wantsJson())
        {
            return new ProjectResource($project);
        }
beardedwarrior's avatar
beardedwarrior committed
47
        $qrcode = QrCode::format('png')->size(100)->generate($project->uri);
48
        return view('projects.show')
49
            ->with('project', $project)
50
            ->with('qrcode', $qrcode);
beardedwarrior's avatar
beardedwarrior committed
51 52
    }
}