coolsam726 /
jetstream-inertia-generator
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | @php echo "<?php"; |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
It is not recommend to use PHP's short opening tag
<?, better use <?php, or <?= in case of outputting.
Short opening tags are disabled in PHP’s default configuration. In such a case, all content of this file is output verbatim to the browser without being parsed, or executed. As a precaution to avoid these problems better use the long opening tag Loading history...
|
|||
| 2 | @endphp |
||
| 3 | |||
| 4 | namespace {{ $controllerNamespace }}; |
||
| 5 | @if($export) |
||
| 6 | use App\Exports\{{$exportBaseName}}; |
||
| 7 | use Maatwebsite\Excel\Excel |
||
| 8 | @endif |
||
| 9 | use App\Http\Controllers\Controller; |
||
| 10 | use App\Http\Requests\{{ $modelWithNamespaceFromDefault }}\Index{{ $modelBaseName }}; |
||
| 11 | use App\Http\Requests\{{ $modelWithNamespaceFromDefault }}\Store{{ $modelBaseName }}; |
||
| 12 | use App\Http\Requests\{{ $modelWithNamespaceFromDefault }}\Update{{ $modelBaseName }}; |
||
| 13 | use App\Http\Requests\{{ $modelWithNamespaceFromDefault }}\Destroy{{ $modelBaseName }}; |
||
| 14 | use {{$modelFullName}}; |
||
| 15 | use {{$repoFullName}}; |
||
| 16 | use Illuminate\Http\Request; |
||
| 17 | use Illuminate\Support\Str; |
||
| 18 | use Inertia\Inertia; |
||
| 19 | use Yajra\DataTables\Html\Column; |
||
| 20 | |||
| 21 | class {{ $controllerBaseName }} extends Controller |
||
| 22 | { |
||
| 23 | private {{$repoBaseName}} $repo; |
||
| 24 | public function __construct({{$repoBaseName}} $repo) |
||
| 25 | { |
||
| 26 | $this->repo = $repo; |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Display a listing of the resource. |
||
| 31 | * |
||
| 32 | * @param Request $request |
||
| 33 | * @return \Inertia\Response |
||
| 34 | * @throws \Illuminate\Auth\Access\AuthorizationException |
||
| 35 | */ |
||
| 36 | public function index(Request $request): \Inertia\Response |
||
| 37 | { |
||
| 38 | $this->authorize('viewAny', {{$modelBaseName}}::class); |
||
| 39 | return Inertia::render('{{$modelPlural}}/Index',[ |
||
| 40 | "can" => [ |
||
| 41 | "viewAny" => \Auth::user()->can('viewAny', {{$modelBaseName}}::class), |
||
| 42 | "create" => \Auth::user()->can('create', {{$modelBaseName}}::class), |
||
| 43 | ], |
||
| 44 | "columns" => $this->repo::dtColumns(), |
||
| 45 | ]); |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Show the form for creating a new resource. |
||
| 50 | * |
||
| 51 | * @return \Inertia\Response |
||
| 52 | */ |
||
| 53 | public function create() |
||
| 54 | { |
||
| 55 | $this->authorize('create', {{$modelBaseName}}::class); |
||
| 56 | return Inertia::render("{{$modelPlural}}/Create",[ |
||
| 57 | "can" => [ |
||
| 58 | "viewAny" => \Auth::user()->can('viewAny', {{$modelBaseName}}::class), |
||
| 59 | "create" => \Auth::user()->can('create', {{$modelBaseName}}::class), |
||
| 60 | ] |
||
| 61 | ]); |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Store a newly created resource in storage. |
||
| 66 | * |
||
| 67 | * {{"@"}}param Store{{$modelBaseName}} $request |
||
| 68 | * {{"@"}}return \Illuminate\Http\RedirectResponse |
||
| 69 | */ |
||
| 70 | public function store(Store{{$modelBaseName}} $request) |
||
| 71 | { |
||
| 72 | try { |
||
| 73 | $data = $request->sanitizedObject(); |
||
| 74 | ${{$modelVariableName}} = $this->repo::store($data); |
||
| 75 | return back()->with(['success' => "The {{$modelTitle}} was created succesfully."]); |
||
| 76 | } catch (\Throwable $exception) { |
||
| 77 | \Log::error($exception); |
||
| 78 | return back()->with([ |
||
| 79 | 'error' => $exception->getMessage(), |
||
| 80 | ]); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Display the specified resource. |
||
| 86 | * |
||
| 87 | * {{"@"}}param Request $request |
||
| 88 | * {{"@"}}param {{$modelBaseName}} ${{$modelVariableName}} |
||
| 89 | * {{"@"}}return \Inertia\Response|\Illuminate\Http\RedirectResponse |
||
| 90 | */ |
||
| 91 | public function show(Request $request, {{$modelBaseName}} ${{$modelVariableName}}) |
||
| 92 | { |
||
| 93 | try { |
||
| 94 | $this->authorize('view', ${{$modelVariableName}}); |
||
| 95 | $model = $this->repo::init(${{$modelVariableName}})->show($request); |
||
| 96 | return Inertia::render("{{$modelPlural}}/Show", ["model" => $model]); |
||
| 97 | } catch (\Throwable $exception) { |
||
| 98 | \Log::error($exception); |
||
| 99 | return back()->with([ |
||
| 100 | 'error' => $exception->getMessage(), |
||
| 101 | ]); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Show Edit Form for the specified resource. |
||
| 107 | * |
||
| 108 | * {{"@"}}param Request $request |
||
| 109 | * {{"@"}}param {{$modelBaseName}} ${{$modelVariableName}} |
||
| 110 | * {{"@"}}return \Inertia\Response|\Illuminate\Http\RedirectResponse |
||
| 111 | */ |
||
| 112 | public function edit(Request $request, {{$modelBaseName}} ${{$modelVariableName}}) |
||
| 113 | { |
||
| 114 | try { |
||
| 115 | $this->authorize('update', ${{$modelVariableName}}); |
||
| 116 | //Fetch relationships |
||
| 117 | @if (count($relations)){{ PHP_EOL }} |
||
| 118 | @if (isset($relations['belongsTo']) && count($relations['belongsTo'])){{PHP_EOL}} |
||
| 119 | @php $parents = $relations['belongsTo']->pluck("function_name")->toArray(); @endphp |
||
| 120 | ${{$modelVariableName}}->load([ |
||
| 121 | @foreach($parents as $parent) |
||
| 122 | '{{$parent}}', |
||
| 123 | @endforeach |
||
| 124 | ]); |
||
| 125 | @endif |
||
| 126 | @endif |
||
| 127 | return Inertia::render("{{$modelPlural}}/Edit", ["model" => ${{$modelVariableName}}]); |
||
| 128 | } catch (\Throwable $exception) { |
||
| 129 | \Log::error($exception); |
||
| 130 | return back()->with([ |
||
| 131 | 'error' => $exception->getMessage(), |
||
| 132 | ]); |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Update the specified resource in storage. |
||
| 138 | * |
||
| 139 | * {{"@"}}param Update{{$modelBaseName}} $request |
||
| 140 | * {{"@"}}param {$modelBaseName} ${{$modelVariableName}} |
||
| 141 | * {{"@"}}return \Illuminate\Http\RedirectResponse |
||
| 142 | */ |
||
| 143 | public function update(Update{{$modelBaseName}} $request, {{$modelBaseName}} ${{$modelVariableName}}) |
||
| 144 | { |
||
| 145 | try { |
||
| 146 | $data = $request->sanitizedObject(); |
||
| 147 | $res = $this->repo::init(${{$modelVariableName}})->update($data); |
||
| 148 | return back()->with(['success' => "The {{$modelBaseName}} was updated succesfully."]); |
||
| 149 | } catch (\Throwable $exception) { |
||
| 150 | \Log::error($exception); |
||
| 151 | return back()->with([ |
||
| 152 | 'error' => $exception->getMessage(), |
||
| 153 | ]); |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Remove the specified resource from storage. |
||
| 159 | * |
||
| 160 | * {{"@"}}param {{$modelBaseName}} ${{$modelVariableName}} |
||
| 161 | * {{"@"}}return \Illuminate\Http\RedirectResponse |
||
| 162 | */ |
||
| 163 | public function destroy(Destroy{{$modelBaseName}} $request, {{$modelBaseName}} ${{$modelVariableName}}) |
||
| 164 | { |
||
| 165 | $res = $this->repo::init(${{$modelVariableName}})->destroy(); |
||
| 166 | if ($res) { |
||
| 167 | return back()->with(['success' => "The {{$modelBaseName}} was deleted succesfully."]); |
||
| 168 | } |
||
| 169 | else { |
||
| 170 | return back()->with(['error' => "The {{$modelBaseName}} could not be deleted."]); |
||
| 171 | } |
||
| 172 | } |
||
| 173 | } |
||
| 174 |