|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Cortex\Tenants\Http\Controllers\Adminarea; |
|
6
|
|
|
|
|
7
|
|
|
use Spatie\MediaLibrary\Models\Media; |
|
8
|
|
|
use Rinvex\Tenants\Contracts\TenantContract; |
|
9
|
|
|
use Cortex\Foundation\DataTables\MediaDataTable; |
|
10
|
|
|
use Cortex\Foundation\Http\Requests\ImageFormRequest; |
|
11
|
|
|
use Cortex\Foundation\Http\Controllers\AuthorizedController; |
|
12
|
|
|
|
|
13
|
|
|
class TenantsMediaController extends AuthorizedController |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* {@inheritdoc} |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $resource = 'tenants'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* {@inheritdoc} |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $resourceAbilityMap = [ |
|
24
|
|
|
'index' => 'list-media', |
|
25
|
|
|
'store' => 'create-media', |
|
26
|
|
|
'delete' => 'delete-media', |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Get a listing of the resource media. |
|
31
|
|
|
* |
|
32
|
|
|
* @param \Rinvex\Tenants\Contracts\TenantContract $tenant |
|
33
|
|
|
* |
|
34
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse |
|
35
|
|
|
*/ |
|
36
|
|
|
public function index(TenantContract $tenant) |
|
37
|
|
|
{ |
|
38
|
|
|
return request()->ajax() && request()->wantsJson() |
|
39
|
|
|
? app(MediaDataTable::class)->with(['resource' => $tenant])->ajax() |
|
40
|
|
|
: intend(['url' => route('adminarea.tenants.edit', ['tenant' => $tenant]).'#media-tab']); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Store a newly created resource in storage. |
|
45
|
|
|
* |
|
46
|
|
|
* @param \Cortex\Foundation\Http\Requests\ImageFormRequest $request |
|
47
|
|
|
* @param \Rinvex\Tenants\Contracts\TenantContract $tenant |
|
48
|
|
|
* |
|
49
|
|
|
* @return void |
|
50
|
|
|
*/ |
|
51
|
|
|
public function store(ImageFormRequest $request, TenantContract $tenant) |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
$tenant->addMediaFromRequest('file') |
|
|
|
|
|
|
54
|
|
|
->sanitizingFileName(function($fileName) { return md5($fileName).'.'.pathinfo($fileName, PATHINFO_EXTENSION); }) |
|
|
|
|
|
|
55
|
|
|
->toMediaCollection('default', config('cortex.tenants.media.disk')); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Delete the given resource from storage. |
|
60
|
|
|
* |
|
61
|
|
|
* @param \Rinvex\Tenants\Contracts\TenantContract $tenant |
|
62
|
|
|
* @param \Spatie\MediaLibrary\Models\Media $media |
|
63
|
|
|
* |
|
64
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse |
|
65
|
|
|
*/ |
|
66
|
|
|
public function delete(TenantContract $tenant, Media $media) |
|
67
|
|
|
{ |
|
68
|
|
|
$tenant->media()->where('id' , $media->id)->first()->delete(); |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
return intend([ |
|
71
|
|
|
'url' => route('adminarea.tenants.media.index', ['tenant' => $tenant]), |
|
72
|
|
|
'with' => ['warning' => trans('cortex/tenants::messages.tenant.media_deleted')], |
|
73
|
|
|
]); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.