Skip to content

Commit 8101f4e

Browse files
committed
add view and download file actions
1 parent 4483bbc commit 8101f4e

File tree

1 file changed

+37
-14
lines changed

1 file changed

+37
-14
lines changed

README.md

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,13 @@ Each MagicLink is associated with an action, which is what will be performed
5959
once the link is visited.
6060

6161
* [Login Action](#login-action)
62+
* [Download file Action](#download-file-action)
63+
* [View Action](#view-action)
6264
* [Http Reponse Action](#http-response-action)
6365

6466
### Login Action
6567

66-
Through the `LoginAction` action, you can log in to the application using the generated link
67-
by `MagicLink`.
68+
Through the `LoginAction` action, you can log in to the application using the generated link by `MagicLink`.
6869

6970
Your constructor supports the user who will login. Optionally we can specify
7071
the [HTTP response](https://laravel.com/docs/master/responses) using the
@@ -99,6 +100,40 @@ $urlShowView = MagicLink::create(
99100
)->url;
100101
```
101102

103+
### Download file Action
104+
105+
This action, `DownloadFileAction`, permit create a link to download a private file.
106+
107+
The constructor require the file path.
108+
109+
Example:
110+
111+
```php
112+
use MagicLink\Actions\DownloadFileAction;
113+
use MagicLink\MagicLink;
114+
115+
// Url to download the file storage_app('private_document.pdf')
116+
$url = MagicLink::create(new DownloadFileAction('private_document.pdf'))->url;
117+
```
118+
119+
### View Action
120+
121+
With the action `ViewAction`, you can provide access to the view. You can use
122+
in his constructor the same arguments than method `view` of Laravel.
123+
124+
Example:
125+
126+
```php
127+
use MagicLink\Actions\ViewAction;
128+
use MagicLink\MagicLink;
129+
130+
// Url to view a internal.blade.php
131+
$url = MagicLink::create(new ViewAction('internal', [
132+
'data' => 'Your private custom content',
133+
]))->url;
134+
```
135+
136+
102137
### Http Response Action
103138

104139
Through the `ResponseAction` action we can access private content without need
@@ -112,18 +147,6 @@ Examples:
112147
use MagicLink\Actions\ResponseAction;
113148
use MagicLink\MagicLink;
114149

115-
$urlToViewContenct = MagicLink::create(
116-
new ResponseAction(
117-
view('promotion.code', ['code' => 'YOUR_CODE'])
118-
)
119-
)->url;
120-
121-
$urlToDownLoadFile = MagicLink::create(
122-
new ResponseAction(function () {
123-
return Storage::download('private/docs.pdf');
124-
})
125-
)->url;
126-
127150
$urlToCustomFunction = MagicLink::create(
128151
new ResponseAction(function () {
129152
Auth::login(User::first());

0 commit comments

Comments
 (0)